three.js 787 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '72dev' };
  6. // browserify support
  7. if ( typeof module === 'object' ) {
  8. module.exports = THREE;
  9. }
  10. // polyfills
  11. ( function () {
  12. var lastTime = 0;
  13. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  14. for ( var x = 0; x < vendors.length && !self.requestAnimationFrame; ++ x ) {
  15. self.requestAnimationFrame = self[ vendors[ x ] + 'RequestAnimationFrame' ];
  16. self.cancelAnimationFrame = self[ vendors[ x ] + 'CancelAnimationFrame' ] || self[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  17. }
  18. if ( self.requestAnimationFrame === undefined && self.setTimeout !== undefined ) {
  19. self.requestAnimationFrame = function ( callback ) {
  20. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  21. var id = self.setTimeout( function () { callback( currTime + timeToCall ) }, timeToCall );
  22. lastTime = currTime + timeToCall;
  23. return id;
  24. };
  25. }
  26. if ( self.cancelAnimationFrame === undefined && self.clearTimeout !== undefined ) {
  27. self.cancelAnimationFrame = function ( id ) { self.clearTimeout( id ) };
  28. }
  29. }() );
  30. if ( Math.sign === undefined ) {
  31. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  32. Math.sign = function ( x ) {
  33. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : +x;
  34. };
  35. }
  36. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  37. // Missing in IE9-11.
  38. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  39. Object.defineProperty( Function.prototype, 'name', {
  40. get: function () {
  41. return this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1];
  42. }
  43. } );
  44. }
  45. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  46. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  47. // GL STATE CONSTANTS
  48. THREE.CullFaceNone = 0;
  49. THREE.CullFaceBack = 1;
  50. THREE.CullFaceFront = 2;
  51. THREE.CullFaceFrontBack = 3;
  52. THREE.FrontFaceDirectionCW = 0;
  53. THREE.FrontFaceDirectionCCW = 1;
  54. // SHADOWING TYPES
  55. THREE.BasicShadowMap = 0;
  56. THREE.PCFShadowMap = 1;
  57. THREE.PCFSoftShadowMap = 2;
  58. // MATERIAL CONSTANTS
  59. // side
  60. THREE.FrontSide = 0;
  61. THREE.BackSide = 1;
  62. THREE.DoubleSide = 2;
  63. // shading
  64. THREE.NoShading = 0;
  65. THREE.FlatShading = 1;
  66. THREE.SmoothShading = 2;
  67. // colors
  68. THREE.NoColors = 0;
  69. THREE.FaceColors = 1;
  70. THREE.VertexColors = 2;
  71. // blending modes
  72. THREE.NoBlending = 0;
  73. THREE.NormalBlending = 1;
  74. THREE.AdditiveBlending = 2;
  75. THREE.SubtractiveBlending = 3;
  76. THREE.MultiplyBlending = 4;
  77. THREE.CustomBlending = 5;
  78. // custom blending equations
  79. // (numbers start from 100 not to clash with other
  80. // mappings to OpenGL constants defined in Texture.js)
  81. THREE.AddEquation = 100;
  82. THREE.SubtractEquation = 101;
  83. THREE.ReverseSubtractEquation = 102;
  84. THREE.MinEquation = 103;
  85. THREE.MaxEquation = 104;
  86. // custom blending destination factors
  87. THREE.ZeroFactor = 200;
  88. THREE.OneFactor = 201;
  89. THREE.SrcColorFactor = 202;
  90. THREE.OneMinusSrcColorFactor = 203;
  91. THREE.SrcAlphaFactor = 204;
  92. THREE.OneMinusSrcAlphaFactor = 205;
  93. THREE.DstAlphaFactor = 206;
  94. THREE.OneMinusDstAlphaFactor = 207;
  95. // custom blending source factors
  96. //THREE.ZeroFactor = 200;
  97. //THREE.OneFactor = 201;
  98. //THREE.SrcAlphaFactor = 204;
  99. //THREE.OneMinusSrcAlphaFactor = 205;
  100. //THREE.DstAlphaFactor = 206;
  101. //THREE.OneMinusDstAlphaFactor = 207;
  102. THREE.DstColorFactor = 208;
  103. THREE.OneMinusDstColorFactor = 209;
  104. THREE.SrcAlphaSaturateFactor = 210;
  105. // depth modes
  106. THREE.NeverDepth = 0;
  107. THREE.AlwaysDepth = 1;
  108. THREE.LessDepth = 2;
  109. THREE.LessEqualDepth = 3;
  110. THREE.EqualDepth = 4;
  111. THREE.GreaterEqualDepth = 5;
  112. THREE.GreaterDepth = 6;
  113. THREE.NotEqualDepth = 7;
  114. // TEXTURE CONSTANTS
  115. THREE.MultiplyOperation = 0;
  116. THREE.MixOperation = 1;
  117. THREE.AddOperation = 2;
  118. // Mapping modes
  119. THREE.UVMapping = 300;
  120. THREE.CubeReflectionMapping = 301;
  121. THREE.CubeRefractionMapping = 302;
  122. THREE.EquirectangularReflectionMapping = 303;
  123. THREE.EquirectangularRefractionMapping = 304;
  124. THREE.SphericalReflectionMapping = 305;
  125. // Wrapping modes
  126. THREE.RepeatWrapping = 1000;
  127. THREE.ClampToEdgeWrapping = 1001;
  128. THREE.MirroredRepeatWrapping = 1002;
  129. // Filters
  130. THREE.NearestFilter = 1003;
  131. THREE.NearestMipMapNearestFilter = 1004;
  132. THREE.NearestMipMapLinearFilter = 1005;
  133. THREE.LinearFilter = 1006;
  134. THREE.LinearMipMapNearestFilter = 1007;
  135. THREE.LinearMipMapLinearFilter = 1008;
  136. // Data types
  137. THREE.UnsignedByteType = 1009;
  138. THREE.ByteType = 1010;
  139. THREE.ShortType = 1011;
  140. THREE.UnsignedShortType = 1012;
  141. THREE.IntType = 1013;
  142. THREE.UnsignedIntType = 1014;
  143. THREE.FloatType = 1015;
  144. THREE.HalfFloatType = 1025;
  145. // Pixel types
  146. //THREE.UnsignedByteType = 1009;
  147. THREE.UnsignedShort4444Type = 1016;
  148. THREE.UnsignedShort5551Type = 1017;
  149. THREE.UnsignedShort565Type = 1018;
  150. // Pixel formats
  151. THREE.AlphaFormat = 1019;
  152. THREE.RGBFormat = 1020;
  153. THREE.RGBAFormat = 1021;
  154. THREE.LuminanceFormat = 1022;
  155. THREE.LuminanceAlphaFormat = 1023;
  156. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  157. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  158. // DDS / ST3C Compressed texture formats
  159. THREE.RGB_S3TC_DXT1_Format = 2001;
  160. THREE.RGBA_S3TC_DXT1_Format = 2002;
  161. THREE.RGBA_S3TC_DXT3_Format = 2003;
  162. THREE.RGBA_S3TC_DXT5_Format = 2004;
  163. // PVRTC compressed texture formats
  164. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  165. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  166. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  167. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  168. // DEPRECATED
  169. THREE.Projector = function () {
  170. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  171. this.projectVector = function ( vector, camera ) {
  172. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  173. vector.project( camera );
  174. };
  175. this.unprojectVector = function ( vector, camera ) {
  176. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  177. vector.unproject( camera );
  178. };
  179. this.pickingRay = function ( vector, camera ) {
  180. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  181. };
  182. };
  183. THREE.CanvasRenderer = function () {
  184. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  185. this.domElement = document.createElement( 'canvas' );
  186. this.clear = function () {};
  187. this.render = function () {};
  188. this.setClearColor = function () {};
  189. this.setSize = function () {};
  190. };
  191. // File:src/math/Color.js
  192. /**
  193. * @author mrdoob / http://mrdoob.com/
  194. */
  195. THREE.Color = function ( color ) {
  196. if ( arguments.length === 3 ) {
  197. return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
  198. }
  199. return this.set( color );
  200. };
  201. THREE.Color.prototype = {
  202. constructor: THREE.Color,
  203. r: 1, g: 1, b: 1,
  204. set: function ( value ) {
  205. if ( value instanceof THREE.Color ) {
  206. this.copy( value );
  207. } else if ( typeof value === 'number' ) {
  208. this.setHex( value );
  209. } else if ( typeof value === 'string' ) {
  210. this.setStyle( value );
  211. }
  212. return this;
  213. },
  214. setHex: function ( hex ) {
  215. hex = Math.floor( hex );
  216. this.r = ( hex >> 16 & 255 ) / 255;
  217. this.g = ( hex >> 8 & 255 ) / 255;
  218. this.b = ( hex & 255 ) / 255;
  219. return this;
  220. },
  221. setRGB: function ( r, g, b ) {
  222. this.r = r;
  223. this.g = g;
  224. this.b = b;
  225. return this;
  226. },
  227. setHSL: function () {
  228. function hue2rgb ( p, q, t ) {
  229. if ( t < 0 ) t += 1;
  230. if ( t > 1 ) t -= 1;
  231. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  232. if ( t < 1 / 2 ) return q;
  233. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  234. return p;
  235. }
  236. return function ( h, s, l ) {
  237. // h,s,l ranges are in 0.0 - 1.0
  238. h = THREE.Math.euclideanModulo( h, 1 );
  239. s = THREE.Math.clamp( s, 0, 1 );
  240. l = THREE.Math.clamp( l, 0, 1 );
  241. if ( s === 0 ) {
  242. this.r = this.g = this.b = l;
  243. } else {
  244. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  245. var q = ( 2 * l ) - p;
  246. this.r = hue2rgb( q, p, h + 1 / 3 );
  247. this.g = hue2rgb( q, p, h );
  248. this.b = hue2rgb( q, p, h - 1 / 3 );
  249. }
  250. return this;
  251. };
  252. }(),
  253. setStyle: function ( style ) {
  254. // rgb(255,0,0)
  255. if ( /^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.test( style ) ) {
  256. var color = /^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.exec( style );
  257. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  258. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  259. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  260. return this;
  261. }
  262. // rgb(100%,0%,0%)
  263. if ( /^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.test( style ) ) {
  264. var color = /^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.exec( style );
  265. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  266. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  267. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  268. return this;
  269. }
  270. // #ff0000
  271. if ( /^\#([0-9a-f]{6})$/i.test( style ) ) {
  272. var color = /^\#([0-9a-f]{6})$/i.exec( style );
  273. this.setHex( parseInt( color[ 1 ], 16 ) );
  274. return this;
  275. }
  276. // #f00
  277. if ( /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.test( style ) ) {
  278. var color = /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec( style );
  279. this.setHex( parseInt( color[ 1 ] + color[ 1 ] + color[ 2 ] + color[ 2 ] + color[ 3 ] + color[ 3 ], 16 ) );
  280. return this;
  281. }
  282. // red
  283. if ( /^(\w+)$/i.test( style ) ) {
  284. this.setHex( THREE.ColorKeywords[ style ] );
  285. return this;
  286. }
  287. },
  288. copy: function ( color ) {
  289. this.r = color.r;
  290. this.g = color.g;
  291. this.b = color.b;
  292. return this;
  293. },
  294. copyGammaToLinear: function ( color, gammaFactor ) {
  295. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  296. this.r = Math.pow( color.r, gammaFactor );
  297. this.g = Math.pow( color.g, gammaFactor );
  298. this.b = Math.pow( color.b, gammaFactor );
  299. return this;
  300. },
  301. copyLinearToGamma: function ( color, gammaFactor ) {
  302. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  303. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  304. this.r = Math.pow( color.r, safeInverse );
  305. this.g = Math.pow( color.g, safeInverse );
  306. this.b = Math.pow( color.b, safeInverse );
  307. return this;
  308. },
  309. convertGammaToLinear: function () {
  310. var r = this.r, g = this.g, b = this.b;
  311. this.r = r * r;
  312. this.g = g * g;
  313. this.b = b * b;
  314. return this;
  315. },
  316. convertLinearToGamma: function () {
  317. this.r = Math.sqrt( this.r );
  318. this.g = Math.sqrt( this.g );
  319. this.b = Math.sqrt( this.b );
  320. return this;
  321. },
  322. getHex: function () {
  323. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  324. },
  325. getHexString: function () {
  326. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  327. },
  328. getHSL: function ( optionalTarget ) {
  329. // h,s,l ranges are in 0.0 - 1.0
  330. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  331. var r = this.r, g = this.g, b = this.b;
  332. var max = Math.max( r, g, b );
  333. var min = Math.min( r, g, b );
  334. var hue, saturation;
  335. var lightness = ( min + max ) / 2.0;
  336. if ( min === max ) {
  337. hue = 0;
  338. saturation = 0;
  339. } else {
  340. var delta = max - min;
  341. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  342. switch ( max ) {
  343. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  344. case g: hue = ( b - r ) / delta + 2; break;
  345. case b: hue = ( r - g ) / delta + 4; break;
  346. }
  347. hue /= 6;
  348. }
  349. hsl.h = hue;
  350. hsl.s = saturation;
  351. hsl.l = lightness;
  352. return hsl;
  353. },
  354. getStyle: function () {
  355. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  356. },
  357. offsetHSL: function ( h, s, l ) {
  358. var hsl = this.getHSL();
  359. hsl.h += h; hsl.s += s; hsl.l += l;
  360. this.setHSL( hsl.h, hsl.s, hsl.l );
  361. return this;
  362. },
  363. add: function ( color ) {
  364. this.r += color.r;
  365. this.g += color.g;
  366. this.b += color.b;
  367. return this;
  368. },
  369. addColors: function ( color1, color2 ) {
  370. this.r = color1.r + color2.r;
  371. this.g = color1.g + color2.g;
  372. this.b = color1.b + color2.b;
  373. return this;
  374. },
  375. addScalar: function ( s ) {
  376. this.r += s;
  377. this.g += s;
  378. this.b += s;
  379. return this;
  380. },
  381. multiply: function ( color ) {
  382. this.r *= color.r;
  383. this.g *= color.g;
  384. this.b *= color.b;
  385. return this;
  386. },
  387. multiplyScalar: function ( s ) {
  388. this.r *= s;
  389. this.g *= s;
  390. this.b *= s;
  391. return this;
  392. },
  393. lerp: function ( color, alpha ) {
  394. this.r += ( color.r - this.r ) * alpha;
  395. this.g += ( color.g - this.g ) * alpha;
  396. this.b += ( color.b - this.b ) * alpha;
  397. return this;
  398. },
  399. equals: function ( c ) {
  400. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  401. },
  402. fromArray: function ( array ) {
  403. this.r = array[ 0 ];
  404. this.g = array[ 1 ];
  405. this.b = array[ 2 ];
  406. return this;
  407. },
  408. toArray: function ( array, offset ) {
  409. if ( array === undefined ) array = [];
  410. if ( offset === undefined ) offset = 0;
  411. array[ offset ] = this.r;
  412. array[ offset + 1 ] = this.g;
  413. array[ offset + 2 ] = this.b;
  414. return array;
  415. },
  416. clone: function () {
  417. return new THREE.Color().setRGB( this.r, this.g, this.b );
  418. }
  419. };
  420. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  421. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  422. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  423. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  424. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  425. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  426. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  427. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  428. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  429. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  430. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  431. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  432. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  433. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  434. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  435. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  436. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  437. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  438. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  439. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  440. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  441. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  442. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  443. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  444. // File:src/math/Quaternion.js
  445. /**
  446. * @author mikael emtinger / http://gomo.se/
  447. * @author alteredq / http://alteredqualia.com/
  448. * @author WestLangley / http://github.com/WestLangley
  449. * @author bhouston / http://exocortex.com
  450. */
  451. THREE.Quaternion = function ( x, y, z, w ) {
  452. this._x = x || 0;
  453. this._y = y || 0;
  454. this._z = z || 0;
  455. this._w = ( w !== undefined ) ? w : 1;
  456. };
  457. THREE.Quaternion.prototype = {
  458. constructor: THREE.Quaternion,
  459. _x: 0,_y: 0, _z: 0, _w: 0,
  460. get x () {
  461. return this._x;
  462. },
  463. set x ( value ) {
  464. this._x = value;
  465. this.onChangeCallback();
  466. },
  467. get y () {
  468. return this._y;
  469. },
  470. set y ( value ) {
  471. this._y = value;
  472. this.onChangeCallback();
  473. },
  474. get z () {
  475. return this._z;
  476. },
  477. set z ( value ) {
  478. this._z = value;
  479. this.onChangeCallback();
  480. },
  481. get w () {
  482. return this._w;
  483. },
  484. set w ( value ) {
  485. this._w = value;
  486. this.onChangeCallback();
  487. },
  488. set: function ( x, y, z, w ) {
  489. this._x = x;
  490. this._y = y;
  491. this._z = z;
  492. this._w = w;
  493. this.onChangeCallback();
  494. return this;
  495. },
  496. copy: function ( quaternion ) {
  497. this._x = quaternion.x;
  498. this._y = quaternion.y;
  499. this._z = quaternion.z;
  500. this._w = quaternion.w;
  501. this.onChangeCallback();
  502. return this;
  503. },
  504. setFromEuler: function ( euler, update ) {
  505. if ( euler instanceof THREE.Euler === false ) {
  506. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  507. }
  508. // http://www.mathworks.com/matlabcentral/fileexchange/
  509. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  510. // content/SpinCalc.m
  511. var c1 = Math.cos( euler._x / 2 );
  512. var c2 = Math.cos( euler._y / 2 );
  513. var c3 = Math.cos( euler._z / 2 );
  514. var s1 = Math.sin( euler._x / 2 );
  515. var s2 = Math.sin( euler._y / 2 );
  516. var s3 = Math.sin( euler._z / 2 );
  517. if ( euler.order === 'XYZ' ) {
  518. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  519. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  520. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  521. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  522. } else if ( euler.order === 'YXZ' ) {
  523. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  524. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  525. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  526. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  527. } else if ( euler.order === 'ZXY' ) {
  528. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  529. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  530. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  531. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  532. } else if ( euler.order === 'ZYX' ) {
  533. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  534. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  535. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  536. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  537. } else if ( euler.order === 'YZX' ) {
  538. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  539. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  540. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  541. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  542. } else if ( euler.order === 'XZY' ) {
  543. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  544. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  545. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  546. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  547. }
  548. if ( update !== false ) this.onChangeCallback();
  549. return this;
  550. },
  551. setFromAxisAngle: function ( axis, angle ) {
  552. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  553. // assumes axis is normalized
  554. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  555. this._x = axis.x * s;
  556. this._y = axis.y * s;
  557. this._z = axis.z * s;
  558. this._w = Math.cos( halfAngle );
  559. this.onChangeCallback();
  560. return this;
  561. },
  562. setFromRotationMatrix: function ( m ) {
  563. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  564. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  565. var te = m.elements,
  566. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  567. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  568. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  569. trace = m11 + m22 + m33,
  570. s;
  571. if ( trace > 0 ) {
  572. s = 0.5 / Math.sqrt( trace + 1.0 );
  573. this._w = 0.25 / s;
  574. this._x = ( m32 - m23 ) * s;
  575. this._y = ( m13 - m31 ) * s;
  576. this._z = ( m21 - m12 ) * s;
  577. } else if ( m11 > m22 && m11 > m33 ) {
  578. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  579. this._w = ( m32 - m23 ) / s;
  580. this._x = 0.25 * s;
  581. this._y = ( m12 + m21 ) / s;
  582. this._z = ( m13 + m31 ) / s;
  583. } else if ( m22 > m33 ) {
  584. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  585. this._w = ( m13 - m31 ) / s;
  586. this._x = ( m12 + m21 ) / s;
  587. this._y = 0.25 * s;
  588. this._z = ( m23 + m32 ) / s;
  589. } else {
  590. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  591. this._w = ( m21 - m12 ) / s;
  592. this._x = ( m13 + m31 ) / s;
  593. this._y = ( m23 + m32 ) / s;
  594. this._z = 0.25 * s;
  595. }
  596. this.onChangeCallback();
  597. return this;
  598. },
  599. setFromUnitVectors: function () {
  600. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  601. // assumes direction vectors vFrom and vTo are normalized
  602. var v1, r;
  603. var EPS = 0.000001;
  604. return function ( vFrom, vTo ) {
  605. if ( v1 === undefined ) v1 = new THREE.Vector3();
  606. r = vFrom.dot( vTo ) + 1;
  607. if ( r < EPS ) {
  608. r = 0;
  609. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  610. v1.set( - vFrom.y, vFrom.x, 0 );
  611. } else {
  612. v1.set( 0, - vFrom.z, vFrom.y );
  613. }
  614. } else {
  615. v1.crossVectors( vFrom, vTo );
  616. }
  617. this._x = v1.x;
  618. this._y = v1.y;
  619. this._z = v1.z;
  620. this._w = r;
  621. this.normalize();
  622. return this;
  623. }
  624. }(),
  625. inverse: function () {
  626. this.conjugate().normalize();
  627. return this;
  628. },
  629. conjugate: function () {
  630. this._x *= - 1;
  631. this._y *= - 1;
  632. this._z *= - 1;
  633. this.onChangeCallback();
  634. return this;
  635. },
  636. dot: function ( v ) {
  637. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  638. },
  639. lengthSq: function () {
  640. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  641. },
  642. length: function () {
  643. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  644. },
  645. normalize: function () {
  646. var l = this.length();
  647. if ( l === 0 ) {
  648. this._x = 0;
  649. this._y = 0;
  650. this._z = 0;
  651. this._w = 1;
  652. } else {
  653. l = 1 / l;
  654. this._x = this._x * l;
  655. this._y = this._y * l;
  656. this._z = this._z * l;
  657. this._w = this._w * l;
  658. }
  659. this.onChangeCallback();
  660. return this;
  661. },
  662. multiply: function ( q, p ) {
  663. if ( p !== undefined ) {
  664. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  665. return this.multiplyQuaternions( q, p );
  666. }
  667. return this.multiplyQuaternions( this, q );
  668. },
  669. multiplyQuaternions: function ( a, b ) {
  670. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  671. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  672. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  673. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  674. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  675. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  676. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  677. this.onChangeCallback();
  678. return this;
  679. },
  680. multiplyVector3: function ( vector ) {
  681. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  682. return vector.applyQuaternion( this );
  683. },
  684. slerp: function ( qb, t ) {
  685. if ( t === 0 ) return this;
  686. if ( t === 1 ) return this.copy( qb );
  687. var x = this._x, y = this._y, z = this._z, w = this._w;
  688. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  689. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  690. if ( cosHalfTheta < 0 ) {
  691. this._w = - qb._w;
  692. this._x = - qb._x;
  693. this._y = - qb._y;
  694. this._z = - qb._z;
  695. cosHalfTheta = - cosHalfTheta;
  696. } else {
  697. this.copy( qb );
  698. }
  699. if ( cosHalfTheta >= 1.0 ) {
  700. this._w = w;
  701. this._x = x;
  702. this._y = y;
  703. this._z = z;
  704. return this;
  705. }
  706. var halfTheta = Math.acos( cosHalfTheta );
  707. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  708. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  709. this._w = 0.5 * ( w + this._w );
  710. this._x = 0.5 * ( x + this._x );
  711. this._y = 0.5 * ( y + this._y );
  712. this._z = 0.5 * ( z + this._z );
  713. return this;
  714. }
  715. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  716. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  717. this._w = ( w * ratioA + this._w * ratioB );
  718. this._x = ( x * ratioA + this._x * ratioB );
  719. this._y = ( y * ratioA + this._y * ratioB );
  720. this._z = ( z * ratioA + this._z * ratioB );
  721. this.onChangeCallback();
  722. return this;
  723. },
  724. equals: function ( quaternion ) {
  725. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  726. },
  727. fromArray: function ( array, offset ) {
  728. if ( offset === undefined ) offset = 0;
  729. this._x = array[ offset ];
  730. this._y = array[ offset + 1 ];
  731. this._z = array[ offset + 2 ];
  732. this._w = array[ offset + 3 ];
  733. this.onChangeCallback();
  734. return this;
  735. },
  736. toArray: function ( array, offset ) {
  737. if ( array === undefined ) array = [];
  738. if ( offset === undefined ) offset = 0;
  739. array[ offset ] = this._x;
  740. array[ offset + 1 ] = this._y;
  741. array[ offset + 2 ] = this._z;
  742. array[ offset + 3 ] = this._w;
  743. return array;
  744. },
  745. onChange: function ( callback ) {
  746. this.onChangeCallback = callback;
  747. return this;
  748. },
  749. onChangeCallback: function () {},
  750. clone: function () {
  751. return new THREE.Quaternion( this._x, this._y, this._z, this._w );
  752. }
  753. };
  754. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  755. return qm.copy( qa ).slerp( qb, t );
  756. };
  757. // File:src/math/Vector2.js
  758. /**
  759. * @author mrdoob / http://mrdoob.com/
  760. * @author philogb / http://blog.thejit.org/
  761. * @author egraether / http://egraether.com/
  762. * @author zz85 / http://www.lab4games.net/zz85/blog
  763. */
  764. THREE.Vector2 = function ( x, y ) {
  765. this.x = x || 0;
  766. this.y = y || 0;
  767. };
  768. THREE.Vector2.prototype = {
  769. constructor: THREE.Vector2,
  770. set: function ( x, y ) {
  771. this.x = x;
  772. this.y = y;
  773. return this;
  774. },
  775. setX: function ( x ) {
  776. this.x = x;
  777. return this;
  778. },
  779. setY: function ( y ) {
  780. this.y = y;
  781. return this;
  782. },
  783. setComponent: function ( index, value ) {
  784. switch ( index ) {
  785. case 0: this.x = value; break;
  786. case 1: this.y = value; break;
  787. default: throw new Error( 'index is out of range: ' + index );
  788. }
  789. },
  790. getComponent: function ( index ) {
  791. switch ( index ) {
  792. case 0: return this.x;
  793. case 1: return this.y;
  794. default: throw new Error( 'index is out of range: ' + index );
  795. }
  796. },
  797. copy: function ( v ) {
  798. this.x = v.x;
  799. this.y = v.y;
  800. return this;
  801. },
  802. add: function ( v, w ) {
  803. if ( w !== undefined ) {
  804. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  805. return this.addVectors( v, w );
  806. }
  807. this.x += v.x;
  808. this.y += v.y;
  809. return this;
  810. },
  811. addScalar: function ( s ) {
  812. this.x += s;
  813. this.y += s;
  814. return this;
  815. },
  816. addVectors: function ( a, b ) {
  817. this.x = a.x + b.x;
  818. this.y = a.y + b.y;
  819. return this;
  820. },
  821. addScaledVector: function ( v, s ) {
  822. this.x += v.x * s;
  823. this.y += v.y * s;
  824. return this;
  825. },
  826. sub: function ( v, w ) {
  827. if ( w !== undefined ) {
  828. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  829. return this.subVectors( v, w );
  830. }
  831. this.x -= v.x;
  832. this.y -= v.y;
  833. return this;
  834. },
  835. subScalar: function ( s ) {
  836. this.x -= s;
  837. this.y -= s;
  838. return this;
  839. },
  840. subVectors: function ( a, b ) {
  841. this.x = a.x - b.x;
  842. this.y = a.y - b.y;
  843. return this;
  844. },
  845. multiply: function ( v ) {
  846. this.x *= v.x;
  847. this.y *= v.y;
  848. return this;
  849. },
  850. multiplyScalar: function ( s ) {
  851. this.x *= s;
  852. this.y *= s;
  853. return this;
  854. },
  855. divide: function ( v ) {
  856. this.x /= v.x;
  857. this.y /= v.y;
  858. return this;
  859. },
  860. divideScalar: function ( scalar ) {
  861. if ( scalar !== 0 ) {
  862. var invScalar = 1 / scalar;
  863. this.x *= invScalar;
  864. this.y *= invScalar;
  865. } else {
  866. this.x = 0;
  867. this.y = 0;
  868. }
  869. return this;
  870. },
  871. min: function ( v ) {
  872. if ( this.x > v.x ) {
  873. this.x = v.x;
  874. }
  875. if ( this.y > v.y ) {
  876. this.y = v.y;
  877. }
  878. return this;
  879. },
  880. max: function ( v ) {
  881. if ( this.x < v.x ) {
  882. this.x = v.x;
  883. }
  884. if ( this.y < v.y ) {
  885. this.y = v.y;
  886. }
  887. return this;
  888. },
  889. clamp: function ( min, max ) {
  890. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  891. if ( this.x < min.x ) {
  892. this.x = min.x;
  893. } else if ( this.x > max.x ) {
  894. this.x = max.x;
  895. }
  896. if ( this.y < min.y ) {
  897. this.y = min.y;
  898. } else if ( this.y > max.y ) {
  899. this.y = max.y;
  900. }
  901. return this;
  902. },
  903. clampScalar: ( function () {
  904. var min, max;
  905. return function ( minVal, maxVal ) {
  906. if ( min === undefined ) {
  907. min = new THREE.Vector2();
  908. max = new THREE.Vector2();
  909. }
  910. min.set( minVal, minVal );
  911. max.set( maxVal, maxVal );
  912. return this.clamp( min, max );
  913. };
  914. } )(),
  915. floor: function () {
  916. this.x = Math.floor( this.x );
  917. this.y = Math.floor( this.y );
  918. return this;
  919. },
  920. ceil: function () {
  921. this.x = Math.ceil( this.x );
  922. this.y = Math.ceil( this.y );
  923. return this;
  924. },
  925. round: function () {
  926. this.x = Math.round( this.x );
  927. this.y = Math.round( this.y );
  928. return this;
  929. },
  930. roundToZero: function () {
  931. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  932. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  933. return this;
  934. },
  935. negate: function () {
  936. this.x = - this.x;
  937. this.y = - this.y;
  938. return this;
  939. },
  940. dot: function ( v ) {
  941. return this.x * v.x + this.y * v.y;
  942. },
  943. lengthSq: function () {
  944. return this.x * this.x + this.y * this.y;
  945. },
  946. length: function () {
  947. return Math.sqrt( this.x * this.x + this.y * this.y );
  948. },
  949. lengthManhattan: function() {
  950. return Math.abs( this.x ) + Math.abs( this.y );
  951. },
  952. normalize: function () {
  953. return this.divideScalar( this.length() );
  954. },
  955. distanceTo: function ( v ) {
  956. return Math.sqrt( this.distanceToSquared( v ) );
  957. },
  958. distanceToSquared: function ( v ) {
  959. var dx = this.x - v.x, dy = this.y - v.y;
  960. return dx * dx + dy * dy;
  961. },
  962. setLength: function ( l ) {
  963. var oldLength = this.length();
  964. if ( oldLength !== 0 && l !== oldLength ) {
  965. this.multiplyScalar( l / oldLength );
  966. }
  967. return this;
  968. },
  969. lerp: function ( v, alpha ) {
  970. this.x += ( v.x - this.x ) * alpha;
  971. this.y += ( v.y - this.y ) * alpha;
  972. return this;
  973. },
  974. lerpVectors: function ( v1, v2, alpha ) {
  975. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  976. return this;
  977. },
  978. equals: function ( v ) {
  979. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  980. },
  981. fromArray: function ( array, offset ) {
  982. if ( offset === undefined ) offset = 0;
  983. this.x = array[ offset ];
  984. this.y = array[ offset + 1 ];
  985. return this;
  986. },
  987. toArray: function ( array, offset ) {
  988. if ( array === undefined ) array = [];
  989. if ( offset === undefined ) offset = 0;
  990. array[ offset ] = this.x;
  991. array[ offset + 1 ] = this.y;
  992. return array;
  993. },
  994. fromAttribute: function ( attribute, index, offset ) {
  995. if ( offset === undefined ) offset = 0;
  996. index = index * attribute.itemSize + offset;
  997. this.x = attribute.array[ index ];
  998. this.y = attribute.array[ index + 1 ];
  999. return this;
  1000. },
  1001. clone: function () {
  1002. return new THREE.Vector2( this.x, this.y );
  1003. }
  1004. };
  1005. // File:src/math/Vector3.js
  1006. /**
  1007. * @author mrdoob / http://mrdoob.com/
  1008. * @author *kile / http://kile.stravaganza.org/
  1009. * @author philogb / http://blog.thejit.org/
  1010. * @author mikael emtinger / http://gomo.se/
  1011. * @author egraether / http://egraether.com/
  1012. * @author WestLangley / http://github.com/WestLangley
  1013. */
  1014. THREE.Vector3 = function ( x, y, z ) {
  1015. this.x = x || 0;
  1016. this.y = y || 0;
  1017. this.z = z || 0;
  1018. };
  1019. THREE.Vector3.prototype = {
  1020. constructor: THREE.Vector3,
  1021. set: function ( x, y, z ) {
  1022. this.x = x;
  1023. this.y = y;
  1024. this.z = z;
  1025. return this;
  1026. },
  1027. setX: function ( x ) {
  1028. this.x = x;
  1029. return this;
  1030. },
  1031. setY: function ( y ) {
  1032. this.y = y;
  1033. return this;
  1034. },
  1035. setZ: function ( z ) {
  1036. this.z = z;
  1037. return this;
  1038. },
  1039. setComponent: function ( index, value ) {
  1040. switch ( index ) {
  1041. case 0: this.x = value; break;
  1042. case 1: this.y = value; break;
  1043. case 2: this.z = value; break;
  1044. default: throw new Error( 'index is out of range: ' + index );
  1045. }
  1046. },
  1047. getComponent: function ( index ) {
  1048. switch ( index ) {
  1049. case 0: return this.x;
  1050. case 1: return this.y;
  1051. case 2: return this.z;
  1052. default: throw new Error( 'index is out of range: ' + index );
  1053. }
  1054. },
  1055. copy: function ( v ) {
  1056. this.x = v.x;
  1057. this.y = v.y;
  1058. this.z = v.z;
  1059. return this;
  1060. },
  1061. add: function ( v, w ) {
  1062. if ( w !== undefined ) {
  1063. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1064. return this.addVectors( v, w );
  1065. }
  1066. this.x += v.x;
  1067. this.y += v.y;
  1068. this.z += v.z;
  1069. return this;
  1070. },
  1071. addScalar: function ( s ) {
  1072. this.x += s;
  1073. this.y += s;
  1074. this.z += s;
  1075. return this;
  1076. },
  1077. addVectors: function ( a, b ) {
  1078. this.x = a.x + b.x;
  1079. this.y = a.y + b.y;
  1080. this.z = a.z + b.z;
  1081. return this;
  1082. },
  1083. addScaledVector: function ( v, s ) {
  1084. this.x += v.x * s;
  1085. this.y += v.y * s;
  1086. this.z += v.z * s;
  1087. return this;
  1088. },
  1089. sub: function ( v, w ) {
  1090. if ( w !== undefined ) {
  1091. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1092. return this.subVectors( v, w );
  1093. }
  1094. this.x -= v.x;
  1095. this.y -= v.y;
  1096. this.z -= v.z;
  1097. return this;
  1098. },
  1099. subScalar: function ( s ) {
  1100. this.x -= s;
  1101. this.y -= s;
  1102. this.z -= s;
  1103. return this;
  1104. },
  1105. subVectors: function ( a, b ) {
  1106. this.x = a.x - b.x;
  1107. this.y = a.y - b.y;
  1108. this.z = a.z - b.z;
  1109. return this;
  1110. },
  1111. multiply: function ( v, w ) {
  1112. if ( w !== undefined ) {
  1113. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1114. return this.multiplyVectors( v, w );
  1115. }
  1116. this.x *= v.x;
  1117. this.y *= v.y;
  1118. this.z *= v.z;
  1119. return this;
  1120. },
  1121. multiplyScalar: function ( scalar ) {
  1122. this.x *= scalar;
  1123. this.y *= scalar;
  1124. this.z *= scalar;
  1125. return this;
  1126. },
  1127. multiplyVectors: function ( a, b ) {
  1128. this.x = a.x * b.x;
  1129. this.y = a.y * b.y;
  1130. this.z = a.z * b.z;
  1131. return this;
  1132. },
  1133. applyEuler: function () {
  1134. var quaternion;
  1135. return function ( euler ) {
  1136. if ( euler instanceof THREE.Euler === false ) {
  1137. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1138. }
  1139. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1140. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1141. return this;
  1142. };
  1143. }(),
  1144. applyAxisAngle: function () {
  1145. var quaternion;
  1146. return function ( axis, angle ) {
  1147. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1148. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1149. return this;
  1150. };
  1151. }(),
  1152. applyMatrix3: function ( m ) {
  1153. var x = this.x;
  1154. var y = this.y;
  1155. var z = this.z;
  1156. var e = m.elements;
  1157. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1158. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1159. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1160. return this;
  1161. },
  1162. applyMatrix4: function ( m ) {
  1163. // input: THREE.Matrix4 affine matrix
  1164. var x = this.x, y = this.y, z = this.z;
  1165. var e = m.elements;
  1166. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1167. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1168. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1169. return this;
  1170. },
  1171. applyProjection: function ( m ) {
  1172. // input: THREE.Matrix4 projection matrix
  1173. var x = this.x, y = this.y, z = this.z;
  1174. var e = m.elements;
  1175. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1176. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1177. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1178. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1179. return this;
  1180. },
  1181. applyQuaternion: function ( q ) {
  1182. var x = this.x;
  1183. var y = this.y;
  1184. var z = this.z;
  1185. var qx = q.x;
  1186. var qy = q.y;
  1187. var qz = q.z;
  1188. var qw = q.w;
  1189. // calculate quat * vector
  1190. var ix = qw * x + qy * z - qz * y;
  1191. var iy = qw * y + qz * x - qx * z;
  1192. var iz = qw * z + qx * y - qy * x;
  1193. var iw = - qx * x - qy * y - qz * z;
  1194. // calculate result * inverse quat
  1195. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1196. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1197. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1198. return this;
  1199. },
  1200. project: function () {
  1201. var matrix;
  1202. return function ( camera ) {
  1203. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1204. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1205. return this.applyProjection( matrix );
  1206. };
  1207. }(),
  1208. unproject: function () {
  1209. var matrix;
  1210. return function ( camera ) {
  1211. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1212. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1213. return this.applyProjection( matrix );
  1214. };
  1215. }(),
  1216. transformDirection: function ( m ) {
  1217. // input: THREE.Matrix4 affine matrix
  1218. // vector interpreted as a direction
  1219. var x = this.x, y = this.y, z = this.z;
  1220. var e = m.elements;
  1221. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1222. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1223. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1224. this.normalize();
  1225. return this;
  1226. },
  1227. divide: function ( v ) {
  1228. this.x /= v.x;
  1229. this.y /= v.y;
  1230. this.z /= v.z;
  1231. return this;
  1232. },
  1233. divideScalar: function ( scalar ) {
  1234. if ( scalar !== 0 ) {
  1235. var invScalar = 1 / scalar;
  1236. this.x *= invScalar;
  1237. this.y *= invScalar;
  1238. this.z *= invScalar;
  1239. } else {
  1240. this.x = 0;
  1241. this.y = 0;
  1242. this.z = 0;
  1243. }
  1244. return this;
  1245. },
  1246. min: function ( v ) {
  1247. if ( this.x > v.x ) {
  1248. this.x = v.x;
  1249. }
  1250. if ( this.y > v.y ) {
  1251. this.y = v.y;
  1252. }
  1253. if ( this.z > v.z ) {
  1254. this.z = v.z;
  1255. }
  1256. return this;
  1257. },
  1258. max: function ( v ) {
  1259. if ( this.x < v.x ) {
  1260. this.x = v.x;
  1261. }
  1262. if ( this.y < v.y ) {
  1263. this.y = v.y;
  1264. }
  1265. if ( this.z < v.z ) {
  1266. this.z = v.z;
  1267. }
  1268. return this;
  1269. },
  1270. clamp: function ( min, max ) {
  1271. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1272. if ( this.x < min.x ) {
  1273. this.x = min.x;
  1274. } else if ( this.x > max.x ) {
  1275. this.x = max.x;
  1276. }
  1277. if ( this.y < min.y ) {
  1278. this.y = min.y;
  1279. } else if ( this.y > max.y ) {
  1280. this.y = max.y;
  1281. }
  1282. if ( this.z < min.z ) {
  1283. this.z = min.z;
  1284. } else if ( this.z > max.z ) {
  1285. this.z = max.z;
  1286. }
  1287. return this;
  1288. },
  1289. clampScalar: ( function () {
  1290. var min, max;
  1291. return function ( minVal, maxVal ) {
  1292. if ( min === undefined ) {
  1293. min = new THREE.Vector3();
  1294. max = new THREE.Vector3();
  1295. }
  1296. min.set( minVal, minVal, minVal );
  1297. max.set( maxVal, maxVal, maxVal );
  1298. return this.clamp( min, max );
  1299. };
  1300. } )(),
  1301. floor: function () {
  1302. this.x = Math.floor( this.x );
  1303. this.y = Math.floor( this.y );
  1304. this.z = Math.floor( this.z );
  1305. return this;
  1306. },
  1307. ceil: function () {
  1308. this.x = Math.ceil( this.x );
  1309. this.y = Math.ceil( this.y );
  1310. this.z = Math.ceil( this.z );
  1311. return this;
  1312. },
  1313. round: function () {
  1314. this.x = Math.round( this.x );
  1315. this.y = Math.round( this.y );
  1316. this.z = Math.round( this.z );
  1317. return this;
  1318. },
  1319. roundToZero: function () {
  1320. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1321. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1322. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1323. return this;
  1324. },
  1325. negate: function () {
  1326. this.x = - this.x;
  1327. this.y = - this.y;
  1328. this.z = - this.z;
  1329. return this;
  1330. },
  1331. dot: function ( v ) {
  1332. return this.x * v.x + this.y * v.y + this.z * v.z;
  1333. },
  1334. lengthSq: function () {
  1335. return this.x * this.x + this.y * this.y + this.z * this.z;
  1336. },
  1337. length: function () {
  1338. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1339. },
  1340. lengthManhattan: function () {
  1341. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1342. },
  1343. normalize: function () {
  1344. return this.divideScalar( this.length() );
  1345. },
  1346. setLength: function ( l ) {
  1347. var oldLength = this.length();
  1348. if ( oldLength !== 0 && l !== oldLength ) {
  1349. this.multiplyScalar( l / oldLength );
  1350. }
  1351. return this;
  1352. },
  1353. lerp: function ( v, alpha ) {
  1354. this.x += ( v.x - this.x ) * alpha;
  1355. this.y += ( v.y - this.y ) * alpha;
  1356. this.z += ( v.z - this.z ) * alpha;
  1357. return this;
  1358. },
  1359. lerpVectors: function ( v1, v2, alpha ) {
  1360. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1361. return this;
  1362. },
  1363. cross: function ( v, w ) {
  1364. if ( w !== undefined ) {
  1365. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1366. return this.crossVectors( v, w );
  1367. }
  1368. var x = this.x, y = this.y, z = this.z;
  1369. this.x = y * v.z - z * v.y;
  1370. this.y = z * v.x - x * v.z;
  1371. this.z = x * v.y - y * v.x;
  1372. return this;
  1373. },
  1374. crossVectors: function ( a, b ) {
  1375. var ax = a.x, ay = a.y, az = a.z;
  1376. var bx = b.x, by = b.y, bz = b.z;
  1377. this.x = ay * bz - az * by;
  1378. this.y = az * bx - ax * bz;
  1379. this.z = ax * by - ay * bx;
  1380. return this;
  1381. },
  1382. projectOnVector: function () {
  1383. var v1, dot;
  1384. return function ( vector ) {
  1385. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1386. v1.copy( vector ).normalize();
  1387. dot = this.dot( v1 );
  1388. return this.copy( v1 ).multiplyScalar( dot );
  1389. };
  1390. }(),
  1391. projectOnPlane: function () {
  1392. var v1;
  1393. return function ( planeNormal ) {
  1394. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1395. v1.copy( this ).projectOnVector( planeNormal );
  1396. return this.sub( v1 );
  1397. }
  1398. }(),
  1399. reflect: function () {
  1400. // reflect incident vector off plane orthogonal to normal
  1401. // normal is assumed to have unit length
  1402. var v1;
  1403. return function ( normal ) {
  1404. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1405. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1406. }
  1407. }(),
  1408. angleTo: function ( v ) {
  1409. var theta = this.dot( v ) / ( this.length() * v.length() );
  1410. // clamp, to handle numerical problems
  1411. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1412. },
  1413. distanceTo: function ( v ) {
  1414. return Math.sqrt( this.distanceToSquared( v ) );
  1415. },
  1416. distanceToSquared: function ( v ) {
  1417. var dx = this.x - v.x;
  1418. var dy = this.y - v.y;
  1419. var dz = this.z - v.z;
  1420. return dx * dx + dy * dy + dz * dz;
  1421. },
  1422. setEulerFromRotationMatrix: function ( m, order ) {
  1423. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1424. },
  1425. setEulerFromQuaternion: function ( q, order ) {
  1426. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1427. },
  1428. getPositionFromMatrix: function ( m ) {
  1429. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1430. return this.setFromMatrixPosition( m );
  1431. },
  1432. getScaleFromMatrix: function ( m ) {
  1433. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1434. return this.setFromMatrixScale( m );
  1435. },
  1436. getColumnFromMatrix: function ( index, matrix ) {
  1437. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1438. return this.setFromMatrixColumn( index, matrix );
  1439. },
  1440. setFromMatrixPosition: function ( m ) {
  1441. this.x = m.elements[ 12 ];
  1442. this.y = m.elements[ 13 ];
  1443. this.z = m.elements[ 14 ];
  1444. return this;
  1445. },
  1446. setFromMatrixScale: function ( m ) {
  1447. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1448. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1449. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1450. this.x = sx;
  1451. this.y = sy;
  1452. this.z = sz;
  1453. return this;
  1454. },
  1455. setFromMatrixColumn: function ( index, matrix ) {
  1456. var offset = index * 4;
  1457. var me = matrix.elements;
  1458. this.x = me[ offset ];
  1459. this.y = me[ offset + 1 ];
  1460. this.z = me[ offset + 2 ];
  1461. return this;
  1462. },
  1463. equals: function ( v ) {
  1464. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1465. },
  1466. fromArray: function ( array, offset ) {
  1467. if ( offset === undefined ) offset = 0;
  1468. this.x = array[ offset ];
  1469. this.y = array[ offset + 1 ];
  1470. this.z = array[ offset + 2 ];
  1471. return this;
  1472. },
  1473. toArray: function ( array, offset ) {
  1474. if ( array === undefined ) array = [];
  1475. if ( offset === undefined ) offset = 0;
  1476. array[ offset ] = this.x;
  1477. array[ offset + 1 ] = this.y;
  1478. array[ offset + 2 ] = this.z;
  1479. return array;
  1480. },
  1481. fromAttribute: function ( attribute, index, offset ) {
  1482. if ( offset === undefined ) offset = 0;
  1483. index = index * attribute.itemSize + offset;
  1484. this.x = attribute.array[ index ];
  1485. this.y = attribute.array[ index + 1 ];
  1486. this.z = attribute.array[ index + 2 ];
  1487. return this;
  1488. },
  1489. clone: function () {
  1490. return new THREE.Vector3( this.x, this.y, this.z );
  1491. }
  1492. };
  1493. // File:src/math/Vector4.js
  1494. /**
  1495. * @author supereggbert / http://www.paulbrunt.co.uk/
  1496. * @author philogb / http://blog.thejit.org/
  1497. * @author mikael emtinger / http://gomo.se/
  1498. * @author egraether / http://egraether.com/
  1499. * @author WestLangley / http://github.com/WestLangley
  1500. */
  1501. THREE.Vector4 = function ( x, y, z, w ) {
  1502. this.x = x || 0;
  1503. this.y = y || 0;
  1504. this.z = z || 0;
  1505. this.w = ( w !== undefined ) ? w : 1;
  1506. };
  1507. THREE.Vector4.prototype = {
  1508. constructor: THREE.Vector4,
  1509. set: function ( x, y, z, w ) {
  1510. this.x = x;
  1511. this.y = y;
  1512. this.z = z;
  1513. this.w = w;
  1514. return this;
  1515. },
  1516. setX: function ( x ) {
  1517. this.x = x;
  1518. return this;
  1519. },
  1520. setY: function ( y ) {
  1521. this.y = y;
  1522. return this;
  1523. },
  1524. setZ: function ( z ) {
  1525. this.z = z;
  1526. return this;
  1527. },
  1528. setW: function ( w ) {
  1529. this.w = w;
  1530. return this;
  1531. },
  1532. setComponent: function ( index, value ) {
  1533. switch ( index ) {
  1534. case 0: this.x = value; break;
  1535. case 1: this.y = value; break;
  1536. case 2: this.z = value; break;
  1537. case 3: this.w = value; break;
  1538. default: throw new Error( 'index is out of range: ' + index );
  1539. }
  1540. },
  1541. getComponent: function ( index ) {
  1542. switch ( index ) {
  1543. case 0: return this.x;
  1544. case 1: return this.y;
  1545. case 2: return this.z;
  1546. case 3: return this.w;
  1547. default: throw new Error( 'index is out of range: ' + index );
  1548. }
  1549. },
  1550. copy: function ( v ) {
  1551. this.x = v.x;
  1552. this.y = v.y;
  1553. this.z = v.z;
  1554. this.w = ( v.w !== undefined ) ? v.w : 1;
  1555. return this;
  1556. },
  1557. add: function ( v, w ) {
  1558. if ( w !== undefined ) {
  1559. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1560. return this.addVectors( v, w );
  1561. }
  1562. this.x += v.x;
  1563. this.y += v.y;
  1564. this.z += v.z;
  1565. this.w += v.w;
  1566. return this;
  1567. },
  1568. addScalar: function ( s ) {
  1569. this.x += s;
  1570. this.y += s;
  1571. this.z += s;
  1572. this.w += s;
  1573. return this;
  1574. },
  1575. addVectors: function ( a, b ) {
  1576. this.x = a.x + b.x;
  1577. this.y = a.y + b.y;
  1578. this.z = a.z + b.z;
  1579. this.w = a.w + b.w;
  1580. return this;
  1581. },
  1582. addScaledVector: function ( v, s ) {
  1583. this.x += v.x * s;
  1584. this.y += v.y * s;
  1585. this.z += v.z * s;
  1586. this.w += v.w * s;
  1587. return this;
  1588. },
  1589. sub: function ( v, w ) {
  1590. if ( w !== undefined ) {
  1591. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1592. return this.subVectors( v, w );
  1593. }
  1594. this.x -= v.x;
  1595. this.y -= v.y;
  1596. this.z -= v.z;
  1597. this.w -= v.w;
  1598. return this;
  1599. },
  1600. subScalar: function ( s ) {
  1601. this.x -= s;
  1602. this.y -= s;
  1603. this.z -= s;
  1604. this.w -= s;
  1605. return this;
  1606. },
  1607. subVectors: function ( a, b ) {
  1608. this.x = a.x - b.x;
  1609. this.y = a.y - b.y;
  1610. this.z = a.z - b.z;
  1611. this.w = a.w - b.w;
  1612. return this;
  1613. },
  1614. multiplyScalar: function ( scalar ) {
  1615. this.x *= scalar;
  1616. this.y *= scalar;
  1617. this.z *= scalar;
  1618. this.w *= scalar;
  1619. return this;
  1620. },
  1621. applyMatrix4: function ( m ) {
  1622. var x = this.x;
  1623. var y = this.y;
  1624. var z = this.z;
  1625. var w = this.w;
  1626. var e = m.elements;
  1627. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1628. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1629. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1630. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1631. return this;
  1632. },
  1633. divideScalar: function ( scalar ) {
  1634. if ( scalar !== 0 ) {
  1635. var invScalar = 1 / scalar;
  1636. this.x *= invScalar;
  1637. this.y *= invScalar;
  1638. this.z *= invScalar;
  1639. this.w *= invScalar;
  1640. } else {
  1641. this.x = 0;
  1642. this.y = 0;
  1643. this.z = 0;
  1644. this.w = 1;
  1645. }
  1646. return this;
  1647. },
  1648. setAxisAngleFromQuaternion: function ( q ) {
  1649. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1650. // q is assumed to be normalized
  1651. this.w = 2 * Math.acos( q.w );
  1652. var s = Math.sqrt( 1 - q.w * q.w );
  1653. if ( s < 0.0001 ) {
  1654. this.x = 1;
  1655. this.y = 0;
  1656. this.z = 0;
  1657. } else {
  1658. this.x = q.x / s;
  1659. this.y = q.y / s;
  1660. this.z = q.z / s;
  1661. }
  1662. return this;
  1663. },
  1664. setAxisAngleFromRotationMatrix: function ( m ) {
  1665. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1666. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1667. var angle, x, y, z, // variables for result
  1668. epsilon = 0.01, // margin to allow for rounding errors
  1669. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1670. te = m.elements,
  1671. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1672. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1673. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1674. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1675. && ( Math.abs( m13 - m31 ) < epsilon )
  1676. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1677. // singularity found
  1678. // first check for identity matrix which must have +1 for all terms
  1679. // in leading diagonal and zero in other terms
  1680. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1681. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1682. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1683. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1684. // this singularity is identity matrix so angle = 0
  1685. this.set( 1, 0, 0, 0 );
  1686. return this; // zero angle, arbitrary axis
  1687. }
  1688. // otherwise this singularity is angle = 180
  1689. angle = Math.PI;
  1690. var xx = ( m11 + 1 ) / 2;
  1691. var yy = ( m22 + 1 ) / 2;
  1692. var zz = ( m33 + 1 ) / 2;
  1693. var xy = ( m12 + m21 ) / 4;
  1694. var xz = ( m13 + m31 ) / 4;
  1695. var yz = ( m23 + m32 ) / 4;
  1696. if ( ( xx > yy ) && ( xx > zz ) ) { // m11 is the largest diagonal term
  1697. if ( xx < epsilon ) {
  1698. x = 0;
  1699. y = 0.707106781;
  1700. z = 0.707106781;
  1701. } else {
  1702. x = Math.sqrt( xx );
  1703. y = xy / x;
  1704. z = xz / x;
  1705. }
  1706. } else if ( yy > zz ) { // m22 is the largest diagonal term
  1707. if ( yy < epsilon ) {
  1708. x = 0.707106781;
  1709. y = 0;
  1710. z = 0.707106781;
  1711. } else {
  1712. y = Math.sqrt( yy );
  1713. x = xy / y;
  1714. z = yz / y;
  1715. }
  1716. } else { // m33 is the largest diagonal term so base result on this
  1717. if ( zz < epsilon ) {
  1718. x = 0.707106781;
  1719. y = 0.707106781;
  1720. z = 0;
  1721. } else {
  1722. z = Math.sqrt( zz );
  1723. x = xz / z;
  1724. y = yz / z;
  1725. }
  1726. }
  1727. this.set( x, y, z, angle );
  1728. return this; // return 180 deg rotation
  1729. }
  1730. // as we have reached here there are no singularities so we can handle normally
  1731. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1732. + ( m13 - m31 ) * ( m13 - m31 )
  1733. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1734. if ( Math.abs( s ) < 0.001 ) s = 1;
  1735. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1736. // caught by singularity test above, but I've left it in just in case
  1737. this.x = ( m32 - m23 ) / s;
  1738. this.y = ( m13 - m31 ) / s;
  1739. this.z = ( m21 - m12 ) / s;
  1740. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1741. return this;
  1742. },
  1743. min: function ( v ) {
  1744. if ( this.x > v.x ) {
  1745. this.x = v.x;
  1746. }
  1747. if ( this.y > v.y ) {
  1748. this.y = v.y;
  1749. }
  1750. if ( this.z > v.z ) {
  1751. this.z = v.z;
  1752. }
  1753. if ( this.w > v.w ) {
  1754. this.w = v.w;
  1755. }
  1756. return this;
  1757. },
  1758. max: function ( v ) {
  1759. if ( this.x < v.x ) {
  1760. this.x = v.x;
  1761. }
  1762. if ( this.y < v.y ) {
  1763. this.y = v.y;
  1764. }
  1765. if ( this.z < v.z ) {
  1766. this.z = v.z;
  1767. }
  1768. if ( this.w < v.w ) {
  1769. this.w = v.w;
  1770. }
  1771. return this;
  1772. },
  1773. clamp: function ( min, max ) {
  1774. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1775. if ( this.x < min.x ) {
  1776. this.x = min.x;
  1777. } else if ( this.x > max.x ) {
  1778. this.x = max.x;
  1779. }
  1780. if ( this.y < min.y ) {
  1781. this.y = min.y;
  1782. } else if ( this.y > max.y ) {
  1783. this.y = max.y;
  1784. }
  1785. if ( this.z < min.z ) {
  1786. this.z = min.z;
  1787. } else if ( this.z > max.z ) {
  1788. this.z = max.z;
  1789. }
  1790. if ( this.w < min.w ) {
  1791. this.w = min.w;
  1792. } else if ( this.w > max.w ) {
  1793. this.w = max.w;
  1794. }
  1795. return this;
  1796. },
  1797. clampScalar: ( function () {
  1798. var min, max;
  1799. return function ( minVal, maxVal ) {
  1800. if ( min === undefined ) {
  1801. min = new THREE.Vector4();
  1802. max = new THREE.Vector4();
  1803. }
  1804. min.set( minVal, minVal, minVal, minVal );
  1805. max.set( maxVal, maxVal, maxVal, maxVal );
  1806. return this.clamp( min, max );
  1807. };
  1808. } )(),
  1809. floor: function () {
  1810. this.x = Math.floor( this.x );
  1811. this.y = Math.floor( this.y );
  1812. this.z = Math.floor( this.z );
  1813. this.w = Math.floor( this.w );
  1814. return this;
  1815. },
  1816. ceil: function () {
  1817. this.x = Math.ceil( this.x );
  1818. this.y = Math.ceil( this.y );
  1819. this.z = Math.ceil( this.z );
  1820. this.w = Math.ceil( this.w );
  1821. return this;
  1822. },
  1823. round: function () {
  1824. this.x = Math.round( this.x );
  1825. this.y = Math.round( this.y );
  1826. this.z = Math.round( this.z );
  1827. this.w = Math.round( this.w );
  1828. return this;
  1829. },
  1830. roundToZero: function () {
  1831. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1832. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1833. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1834. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1835. return this;
  1836. },
  1837. negate: function () {
  1838. this.x = - this.x;
  1839. this.y = - this.y;
  1840. this.z = - this.z;
  1841. this.w = - this.w;
  1842. return this;
  1843. },
  1844. dot: function ( v ) {
  1845. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1846. },
  1847. lengthSq: function () {
  1848. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1849. },
  1850. length: function () {
  1851. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1852. },
  1853. lengthManhattan: function () {
  1854. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1855. },
  1856. normalize: function () {
  1857. return this.divideScalar( this.length() );
  1858. },
  1859. setLength: function ( l ) {
  1860. var oldLength = this.length();
  1861. if ( oldLength !== 0 && l !== oldLength ) {
  1862. this.multiplyScalar( l / oldLength );
  1863. }
  1864. return this;
  1865. },
  1866. lerp: function ( v, alpha ) {
  1867. this.x += ( v.x - this.x ) * alpha;
  1868. this.y += ( v.y - this.y ) * alpha;
  1869. this.z += ( v.z - this.z ) * alpha;
  1870. this.w += ( v.w - this.w ) * alpha;
  1871. return this;
  1872. },
  1873. lerpVectors: function ( v1, v2, alpha ) {
  1874. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1875. return this;
  1876. },
  1877. equals: function ( v ) {
  1878. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1879. },
  1880. fromArray: function ( array, offset ) {
  1881. if ( offset === undefined ) offset = 0;
  1882. this.x = array[ offset ];
  1883. this.y = array[ offset + 1 ];
  1884. this.z = array[ offset + 2 ];
  1885. this.w = array[ offset + 3 ];
  1886. return this;
  1887. },
  1888. toArray: function ( array, offset ) {
  1889. if ( array === undefined ) array = [];
  1890. if ( offset === undefined ) offset = 0;
  1891. array[ offset ] = this.x;
  1892. array[ offset + 1 ] = this.y;
  1893. array[ offset + 2 ] = this.z;
  1894. array[ offset + 3 ] = this.w;
  1895. return array;
  1896. },
  1897. fromAttribute: function ( attribute, index, offset ) {
  1898. if ( offset === undefined ) offset = 0;
  1899. index = index * attribute.itemSize + offset;
  1900. this.x = attribute.array[ index ];
  1901. this.y = attribute.array[ index + 1 ];
  1902. this.z = attribute.array[ index + 2 ];
  1903. this.w = attribute.array[ index + 3 ];
  1904. return this;
  1905. },
  1906. clone: function () {
  1907. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  1908. }
  1909. };
  1910. // File:src/math/Euler.js
  1911. /**
  1912. * @author mrdoob / http://mrdoob.com/
  1913. * @author WestLangley / http://github.com/WestLangley
  1914. * @author bhouston / http://exocortex.com
  1915. */
  1916. THREE.Euler = function ( x, y, z, order ) {
  1917. this._x = x || 0;
  1918. this._y = y || 0;
  1919. this._z = z || 0;
  1920. this._order = order || THREE.Euler.DefaultOrder;
  1921. };
  1922. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1923. THREE.Euler.DefaultOrder = 'XYZ';
  1924. THREE.Euler.prototype = {
  1925. constructor: THREE.Euler,
  1926. _x: 0, _y: 0, _z: 0, _order: THREE.Euler.DefaultOrder,
  1927. get x () {
  1928. return this._x;
  1929. },
  1930. set x ( value ) {
  1931. this._x = value;
  1932. this.onChangeCallback();
  1933. },
  1934. get y () {
  1935. return this._y;
  1936. },
  1937. set y ( value ) {
  1938. this._y = value;
  1939. this.onChangeCallback();
  1940. },
  1941. get z () {
  1942. return this._z;
  1943. },
  1944. set z ( value ) {
  1945. this._z = value;
  1946. this.onChangeCallback();
  1947. },
  1948. get order () {
  1949. return this._order;
  1950. },
  1951. set order ( value ) {
  1952. this._order = value;
  1953. this.onChangeCallback();
  1954. },
  1955. set: function ( x, y, z, order ) {
  1956. this._x = x;
  1957. this._y = y;
  1958. this._z = z;
  1959. this._order = order || this._order;
  1960. this.onChangeCallback();
  1961. return this;
  1962. },
  1963. copy: function ( euler ) {
  1964. this._x = euler._x;
  1965. this._y = euler._y;
  1966. this._z = euler._z;
  1967. this._order = euler._order;
  1968. this.onChangeCallback();
  1969. return this;
  1970. },
  1971. setFromRotationMatrix: function ( m, order, update ) {
  1972. var clamp = THREE.Math.clamp;
  1973. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1974. var te = m.elements;
  1975. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  1976. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  1977. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1978. order = order || this._order;
  1979. if ( order === 'XYZ' ) {
  1980. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  1981. if ( Math.abs( m13 ) < 0.99999 ) {
  1982. this._x = Math.atan2( - m23, m33 );
  1983. this._z = Math.atan2( - m12, m11 );
  1984. } else {
  1985. this._x = Math.atan2( m32, m22 );
  1986. this._z = 0;
  1987. }
  1988. } else if ( order === 'YXZ' ) {
  1989. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  1990. if ( Math.abs( m23 ) < 0.99999 ) {
  1991. this._y = Math.atan2( m13, m33 );
  1992. this._z = Math.atan2( m21, m22 );
  1993. } else {
  1994. this._y = Math.atan2( - m31, m11 );
  1995. this._z = 0;
  1996. }
  1997. } else if ( order === 'ZXY' ) {
  1998. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  1999. if ( Math.abs( m32 ) < 0.99999 ) {
  2000. this._y = Math.atan2( - m31, m33 );
  2001. this._z = Math.atan2( - m12, m22 );
  2002. } else {
  2003. this._y = 0;
  2004. this._z = Math.atan2( m21, m11 );
  2005. }
  2006. } else if ( order === 'ZYX' ) {
  2007. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2008. if ( Math.abs( m31 ) < 0.99999 ) {
  2009. this._x = Math.atan2( m32, m33 );
  2010. this._z = Math.atan2( m21, m11 );
  2011. } else {
  2012. this._x = 0;
  2013. this._z = Math.atan2( - m12, m22 );
  2014. }
  2015. } else if ( order === 'YZX' ) {
  2016. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2017. if ( Math.abs( m21 ) < 0.99999 ) {
  2018. this._x = Math.atan2( - m23, m22 );
  2019. this._y = Math.atan2( - m31, m11 );
  2020. } else {
  2021. this._x = 0;
  2022. this._y = Math.atan2( m13, m33 );
  2023. }
  2024. } else if ( order === 'XZY' ) {
  2025. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2026. if ( Math.abs( m12 ) < 0.99999 ) {
  2027. this._x = Math.atan2( m32, m22 );
  2028. this._y = Math.atan2( m13, m11 );
  2029. } else {
  2030. this._x = Math.atan2( - m23, m33 );
  2031. this._y = 0;
  2032. }
  2033. } else {
  2034. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2035. }
  2036. this._order = order;
  2037. if ( update !== false ) this.onChangeCallback();
  2038. return this;
  2039. },
  2040. setFromQuaternion: function () {
  2041. var matrix;
  2042. return function ( q, order, update ) {
  2043. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2044. matrix.makeRotationFromQuaternion( q );
  2045. this.setFromRotationMatrix( matrix, order, update );
  2046. return this;
  2047. };
  2048. }(),
  2049. setFromVector3: function ( v, order ) {
  2050. return this.set( v.x, v.y, v.z, order || this._order );
  2051. },
  2052. reorder: function () {
  2053. // WARNING: this discards revolution information -bhouston
  2054. var q = new THREE.Quaternion();
  2055. return function ( newOrder ) {
  2056. q.setFromEuler( this );
  2057. this.setFromQuaternion( q, newOrder );
  2058. };
  2059. }(),
  2060. equals: function ( euler ) {
  2061. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2062. },
  2063. fromArray: function ( array ) {
  2064. this._x = array[ 0 ];
  2065. this._y = array[ 1 ];
  2066. this._z = array[ 2 ];
  2067. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2068. this.onChangeCallback();
  2069. return this;
  2070. },
  2071. toArray: function ( array, offset ) {
  2072. if ( array === undefined ) array = [];
  2073. if ( offset === undefined ) offset = 0;
  2074. array[ offset ] = this._x;
  2075. array[ offset + 1 ] = this._y;
  2076. array[ offset + 2 ] = this._z;
  2077. array[ offset + 3 ] = this._order;
  2078. return array;
  2079. },
  2080. toVector3: function ( optionalResult ) {
  2081. if ( optionalResult ) {
  2082. return optionalResult.set( this._x, this._y, this._z );
  2083. } else {
  2084. return new THREE.Vector3( this._x, this._y, this._z );
  2085. }
  2086. },
  2087. onChange: function ( callback ) {
  2088. this.onChangeCallback = callback;
  2089. return this;
  2090. },
  2091. onChangeCallback: function () {},
  2092. clone: function () {
  2093. return new THREE.Euler( this._x, this._y, this._z, this._order );
  2094. }
  2095. };
  2096. // File:src/math/Line3.js
  2097. /**
  2098. * @author bhouston / http://exocortex.com
  2099. */
  2100. THREE.Line3 = function ( start, end ) {
  2101. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2102. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2103. };
  2104. THREE.Line3.prototype = {
  2105. constructor: THREE.Line3,
  2106. set: function ( start, end ) {
  2107. this.start.copy( start );
  2108. this.end.copy( end );
  2109. return this;
  2110. },
  2111. copy: function ( line ) {
  2112. this.start.copy( line.start );
  2113. this.end.copy( line.end );
  2114. return this;
  2115. },
  2116. center: function ( optionalTarget ) {
  2117. var result = optionalTarget || new THREE.Vector3();
  2118. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2119. },
  2120. delta: function ( optionalTarget ) {
  2121. var result = optionalTarget || new THREE.Vector3();
  2122. return result.subVectors( this.end, this.start );
  2123. },
  2124. distanceSq: function () {
  2125. return this.start.distanceToSquared( this.end );
  2126. },
  2127. distance: function () {
  2128. return this.start.distanceTo( this.end );
  2129. },
  2130. at: function ( t, optionalTarget ) {
  2131. var result = optionalTarget || new THREE.Vector3();
  2132. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2133. },
  2134. closestPointToPointParameter: function () {
  2135. var startP = new THREE.Vector3();
  2136. var startEnd = new THREE.Vector3();
  2137. return function ( point, clampToLine ) {
  2138. startP.subVectors( point, this.start );
  2139. startEnd.subVectors( this.end, this.start );
  2140. var startEnd2 = startEnd.dot( startEnd );
  2141. var startEnd_startP = startEnd.dot( startP );
  2142. var t = startEnd_startP / startEnd2;
  2143. if ( clampToLine ) {
  2144. t = THREE.Math.clamp( t, 0, 1 );
  2145. }
  2146. return t;
  2147. };
  2148. }(),
  2149. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2150. var t = this.closestPointToPointParameter( point, clampToLine );
  2151. var result = optionalTarget || new THREE.Vector3();
  2152. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2153. },
  2154. applyMatrix4: function ( matrix ) {
  2155. this.start.applyMatrix4( matrix );
  2156. this.end.applyMatrix4( matrix );
  2157. return this;
  2158. },
  2159. equals: function ( line ) {
  2160. return line.start.equals( this.start ) && line.end.equals( this.end );
  2161. },
  2162. clone: function () {
  2163. return new THREE.Line3().copy( this );
  2164. }
  2165. };
  2166. // File:src/math/Box2.js
  2167. /**
  2168. * @author bhouston / http://exocortex.com
  2169. */
  2170. THREE.Box2 = function ( min, max ) {
  2171. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2172. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2173. };
  2174. THREE.Box2.prototype = {
  2175. constructor: THREE.Box2,
  2176. set: function ( min, max ) {
  2177. this.min.copy( min );
  2178. this.max.copy( max );
  2179. return this;
  2180. },
  2181. setFromPoints: function ( points ) {
  2182. this.makeEmpty();
  2183. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2184. this.expandByPoint( points[ i ] )
  2185. }
  2186. return this;
  2187. },
  2188. setFromCenterAndSize: function () {
  2189. var v1 = new THREE.Vector2();
  2190. return function ( center, size ) {
  2191. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2192. this.min.copy( center ).sub( halfSize );
  2193. this.max.copy( center ).add( halfSize );
  2194. return this;
  2195. };
  2196. }(),
  2197. copy: function ( box ) {
  2198. this.min.copy( box.min );
  2199. this.max.copy( box.max );
  2200. return this;
  2201. },
  2202. makeEmpty: function () {
  2203. this.min.x = this.min.y = Infinity;
  2204. this.max.x = this.max.y = - Infinity;
  2205. return this;
  2206. },
  2207. empty: function () {
  2208. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2209. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2210. },
  2211. center: function ( optionalTarget ) {
  2212. var result = optionalTarget || new THREE.Vector2();
  2213. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2214. },
  2215. size: function ( optionalTarget ) {
  2216. var result = optionalTarget || new THREE.Vector2();
  2217. return result.subVectors( this.max, this.min );
  2218. },
  2219. expandByPoint: function ( point ) {
  2220. this.min.min( point );
  2221. this.max.max( point );
  2222. return this;
  2223. },
  2224. expandByVector: function ( vector ) {
  2225. this.min.sub( vector );
  2226. this.max.add( vector );
  2227. return this;
  2228. },
  2229. expandByScalar: function ( scalar ) {
  2230. this.min.addScalar( - scalar );
  2231. this.max.addScalar( scalar );
  2232. return this;
  2233. },
  2234. containsPoint: function ( point ) {
  2235. if ( point.x < this.min.x || point.x > this.max.x ||
  2236. point.y < this.min.y || point.y > this.max.y ) {
  2237. return false;
  2238. }
  2239. return true;
  2240. },
  2241. containsBox: function ( box ) {
  2242. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2243. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2244. return true;
  2245. }
  2246. return false;
  2247. },
  2248. getParameter: function ( point, optionalTarget ) {
  2249. // This can potentially have a divide by zero if the box
  2250. // has a size dimension of 0.
  2251. var result = optionalTarget || new THREE.Vector2();
  2252. return result.set(
  2253. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2254. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2255. );
  2256. },
  2257. isIntersectionBox: function ( box ) {
  2258. // using 6 splitting planes to rule out intersections.
  2259. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2260. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2261. return false;
  2262. }
  2263. return true;
  2264. },
  2265. clampPoint: function ( point, optionalTarget ) {
  2266. var result = optionalTarget || new THREE.Vector2();
  2267. return result.copy( point ).clamp( this.min, this.max );
  2268. },
  2269. distanceToPoint: function () {
  2270. var v1 = new THREE.Vector2();
  2271. return function ( point ) {
  2272. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2273. return clampedPoint.sub( point ).length();
  2274. };
  2275. }(),
  2276. intersect: function ( box ) {
  2277. this.min.max( box.min );
  2278. this.max.min( box.max );
  2279. return this;
  2280. },
  2281. union: function ( box ) {
  2282. this.min.min( box.min );
  2283. this.max.max( box.max );
  2284. return this;
  2285. },
  2286. translate: function ( offset ) {
  2287. this.min.add( offset );
  2288. this.max.add( offset );
  2289. return this;
  2290. },
  2291. equals: function ( box ) {
  2292. return box.min.equals( this.min ) && box.max.equals( this.max );
  2293. },
  2294. clone: function () {
  2295. return new THREE.Box2().copy( this );
  2296. }
  2297. };
  2298. // File:src/math/Box3.js
  2299. /**
  2300. * @author bhouston / http://exocortex.com
  2301. * @author WestLangley / http://github.com/WestLangley
  2302. */
  2303. THREE.Box3 = function ( min, max ) {
  2304. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2305. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2306. };
  2307. THREE.Box3.prototype = {
  2308. constructor: THREE.Box3,
  2309. set: function ( min, max ) {
  2310. this.min.copy( min );
  2311. this.max.copy( max );
  2312. return this;
  2313. },
  2314. setFromPoints: function ( points ) {
  2315. this.makeEmpty();
  2316. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2317. this.expandByPoint( points[ i ] );
  2318. }
  2319. return this;
  2320. },
  2321. setFromCenterAndSize: function () {
  2322. var v1 = new THREE.Vector3();
  2323. return function ( center, size ) {
  2324. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2325. this.min.copy( center ).sub( halfSize );
  2326. this.max.copy( center ).add( halfSize );
  2327. return this;
  2328. };
  2329. }(),
  2330. setFromObject: function () {
  2331. // Computes the world-axis-aligned bounding box of an object (including its children),
  2332. // accounting for both the object's, and children's, world transforms
  2333. var v1 = new THREE.Vector3();
  2334. return function ( object ) {
  2335. var scope = this;
  2336. object.updateMatrixWorld( true );
  2337. this.makeEmpty();
  2338. object.traverse( function ( node ) {
  2339. var geometry = node.geometry;
  2340. if ( geometry !== undefined ) {
  2341. if ( geometry instanceof THREE.Geometry ) {
  2342. var vertices = geometry.vertices;
  2343. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2344. v1.copy( vertices[ i ] );
  2345. v1.applyMatrix4( node.matrixWorld );
  2346. scope.expandByPoint( v1 );
  2347. }
  2348. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2349. var positions = geometry.attributes[ 'position' ].array;
  2350. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2351. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2352. v1.applyMatrix4( node.matrixWorld );
  2353. scope.expandByPoint( v1 );
  2354. }
  2355. }
  2356. }
  2357. } );
  2358. return this;
  2359. };
  2360. }(),
  2361. copy: function ( box ) {
  2362. this.min.copy( box.min );
  2363. this.max.copy( box.max );
  2364. return this;
  2365. },
  2366. makeEmpty: function () {
  2367. this.min.x = this.min.y = this.min.z = Infinity;
  2368. this.max.x = this.max.y = this.max.z = - Infinity;
  2369. return this;
  2370. },
  2371. empty: function () {
  2372. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2373. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2374. },
  2375. center: function ( optionalTarget ) {
  2376. var result = optionalTarget || new THREE.Vector3();
  2377. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2378. },
  2379. size: function ( optionalTarget ) {
  2380. var result = optionalTarget || new THREE.Vector3();
  2381. return result.subVectors( this.max, this.min );
  2382. },
  2383. expandByPoint: function ( point ) {
  2384. this.min.min( point );
  2385. this.max.max( point );
  2386. return this;
  2387. },
  2388. expandByVector: function ( vector ) {
  2389. this.min.sub( vector );
  2390. this.max.add( vector );
  2391. return this;
  2392. },
  2393. expandByScalar: function ( scalar ) {
  2394. this.min.addScalar( - scalar );
  2395. this.max.addScalar( scalar );
  2396. return this;
  2397. },
  2398. containsPoint: function ( point ) {
  2399. if ( point.x < this.min.x || point.x > this.max.x ||
  2400. point.y < this.min.y || point.y > this.max.y ||
  2401. point.z < this.min.z || point.z > this.max.z ) {
  2402. return false;
  2403. }
  2404. return true;
  2405. },
  2406. containsBox: function ( box ) {
  2407. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2408. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2409. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2410. return true;
  2411. }
  2412. return false;
  2413. },
  2414. getParameter: function ( point, optionalTarget ) {
  2415. // This can potentially have a divide by zero if the box
  2416. // has a size dimension of 0.
  2417. var result = optionalTarget || new THREE.Vector3();
  2418. return result.set(
  2419. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2420. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2421. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2422. );
  2423. },
  2424. isIntersectionBox: function ( box ) {
  2425. // using 6 splitting planes to rule out intersections.
  2426. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2427. box.max.y < this.min.y || box.min.y > this.max.y ||
  2428. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2429. return false;
  2430. }
  2431. return true;
  2432. },
  2433. clampPoint: function ( point, optionalTarget ) {
  2434. var result = optionalTarget || new THREE.Vector3();
  2435. return result.copy( point ).clamp( this.min, this.max );
  2436. },
  2437. distanceToPoint: function () {
  2438. var v1 = new THREE.Vector3();
  2439. return function ( point ) {
  2440. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2441. return clampedPoint.sub( point ).length();
  2442. };
  2443. }(),
  2444. getBoundingSphere: function () {
  2445. var v1 = new THREE.Vector3();
  2446. return function ( optionalTarget ) {
  2447. var result = optionalTarget || new THREE.Sphere();
  2448. result.center = this.center();
  2449. result.radius = this.size( v1 ).length() * 0.5;
  2450. return result;
  2451. };
  2452. }(),
  2453. intersect: function ( box ) {
  2454. this.min.max( box.min );
  2455. this.max.min( box.max );
  2456. return this;
  2457. },
  2458. union: function ( box ) {
  2459. this.min.min( box.min );
  2460. this.max.max( box.max );
  2461. return this;
  2462. },
  2463. applyMatrix4: function () {
  2464. var points = [
  2465. new THREE.Vector3(),
  2466. new THREE.Vector3(),
  2467. new THREE.Vector3(),
  2468. new THREE.Vector3(),
  2469. new THREE.Vector3(),
  2470. new THREE.Vector3(),
  2471. new THREE.Vector3(),
  2472. new THREE.Vector3()
  2473. ];
  2474. return function ( matrix ) {
  2475. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2476. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2477. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2478. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2479. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2480. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2481. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2482. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2483. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2484. this.makeEmpty();
  2485. this.setFromPoints( points );
  2486. return this;
  2487. };
  2488. }(),
  2489. translate: function ( offset ) {
  2490. this.min.add( offset );
  2491. this.max.add( offset );
  2492. return this;
  2493. },
  2494. equals: function ( box ) {
  2495. return box.min.equals( this.min ) && box.max.equals( this.max );
  2496. },
  2497. clone: function () {
  2498. return new THREE.Box3().copy( this );
  2499. }
  2500. };
  2501. // File:src/math/Matrix3.js
  2502. /**
  2503. * @author alteredq / http://alteredqualia.com/
  2504. * @author WestLangley / http://github.com/WestLangley
  2505. * @author bhouston / http://exocortex.com
  2506. */
  2507. THREE.Matrix3 = function () {
  2508. this.elements = new Float32Array( [
  2509. 1, 0, 0,
  2510. 0, 1, 0,
  2511. 0, 0, 1
  2512. ] );
  2513. if ( arguments.length > 0 ) {
  2514. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2515. }
  2516. };
  2517. THREE.Matrix3.prototype = {
  2518. constructor: THREE.Matrix3,
  2519. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2520. var te = this.elements;
  2521. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2522. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2523. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2524. return this;
  2525. },
  2526. identity: function () {
  2527. this.set(
  2528. 1, 0, 0,
  2529. 0, 1, 0,
  2530. 0, 0, 1
  2531. );
  2532. return this;
  2533. },
  2534. copy: function ( m ) {
  2535. var me = m.elements;
  2536. this.set(
  2537. me[ 0 ], me[ 3 ], me[ 6 ],
  2538. me[ 1 ], me[ 4 ], me[ 7 ],
  2539. me[ 2 ], me[ 5 ], me[ 8 ]
  2540. );
  2541. return this;
  2542. },
  2543. multiplyVector3: function ( vector ) {
  2544. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2545. return vector.applyMatrix3( this );
  2546. },
  2547. multiplyVector3Array: function ( a ) {
  2548. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2549. return this.applyToVector3Array( a );
  2550. },
  2551. applyToVector3Array: function () {
  2552. var v1;
  2553. return function ( array, offset, length ) {
  2554. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2555. if ( offset === undefined ) offset = 0;
  2556. if ( length === undefined ) length = array.length;
  2557. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2558. v1.fromArray( array, j );
  2559. v1.applyMatrix3( this );
  2560. v1.toArray( array, j );
  2561. }
  2562. return array;
  2563. };
  2564. }(),
  2565. applyToBuffer: function () {
  2566. var v1;
  2567. return function applyToBuffer( buffer, offset, length ) {
  2568. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2569. if ( offset === undefined ) offset = 0;
  2570. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2571. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2572. v1.x = buffer.getX( j );
  2573. v1.y = buffer.getY( j );
  2574. v1.z = buffer.getZ( j );
  2575. v1.applyMatrix3( this );
  2576. buffer.setXYZ( v1.x, v1.y, v1.z );
  2577. }
  2578. return buffer;
  2579. };
  2580. }(),
  2581. multiplyScalar: function ( s ) {
  2582. var te = this.elements;
  2583. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2584. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2585. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2586. return this;
  2587. },
  2588. determinant: function () {
  2589. var te = this.elements;
  2590. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2591. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2592. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2593. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2594. },
  2595. getInverse: function ( matrix, throwOnInvertible ) {
  2596. // input: THREE.Matrix4
  2597. // ( based on http://code.google.com/p/webgl-mjs/ )
  2598. var me = matrix.elements;
  2599. var te = this.elements;
  2600. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2601. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2602. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2603. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2604. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2605. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2606. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2607. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2608. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2609. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2610. // no inverse
  2611. if ( det === 0 ) {
  2612. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2613. if ( throwOnInvertible || false ) {
  2614. throw new Error( msg );
  2615. } else {
  2616. console.warn( msg );
  2617. }
  2618. this.identity();
  2619. return this;
  2620. }
  2621. this.multiplyScalar( 1.0 / det );
  2622. return this;
  2623. },
  2624. transpose: function () {
  2625. var tmp, m = this.elements;
  2626. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2627. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2628. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2629. return this;
  2630. },
  2631. flattenToArrayOffset: function ( array, offset ) {
  2632. var te = this.elements;
  2633. array[ offset ] = te[ 0 ];
  2634. array[ offset + 1 ] = te[ 1 ];
  2635. array[ offset + 2 ] = te[ 2 ];
  2636. array[ offset + 3 ] = te[ 3 ];
  2637. array[ offset + 4 ] = te[ 4 ];
  2638. array[ offset + 5 ] = te[ 5 ];
  2639. array[ offset + 6 ] = te[ 6 ];
  2640. array[ offset + 7 ] = te[ 7 ];
  2641. array[ offset + 8 ] = te[ 8 ];
  2642. return array;
  2643. },
  2644. getNormalMatrix: function ( m ) {
  2645. // input: THREE.Matrix4
  2646. this.getInverse( m ).transpose();
  2647. return this;
  2648. },
  2649. transposeIntoArray: function ( r ) {
  2650. var m = this.elements;
  2651. r[ 0 ] = m[ 0 ];
  2652. r[ 1 ] = m[ 3 ];
  2653. r[ 2 ] = m[ 6 ];
  2654. r[ 3 ] = m[ 1 ];
  2655. r[ 4 ] = m[ 4 ];
  2656. r[ 5 ] = m[ 7 ];
  2657. r[ 6 ] = m[ 2 ];
  2658. r[ 7 ] = m[ 5 ];
  2659. r[ 8 ] = m[ 8 ];
  2660. return this;
  2661. },
  2662. fromArray: function ( array ) {
  2663. this.elements.set( array );
  2664. return this;
  2665. },
  2666. toArray: function () {
  2667. var te = this.elements;
  2668. return [
  2669. te[ 0 ], te[ 1 ], te[ 2 ],
  2670. te[ 3 ], te[ 4 ], te[ 5 ],
  2671. te[ 6 ], te[ 7 ], te[ 8 ]
  2672. ];
  2673. },
  2674. clone: function () {
  2675. return new THREE.Matrix3().fromArray( this.elements );
  2676. }
  2677. };
  2678. // File:src/math/Matrix4.js
  2679. /**
  2680. * @author mrdoob / http://mrdoob.com/
  2681. * @author supereggbert / http://www.paulbrunt.co.uk/
  2682. * @author philogb / http://blog.thejit.org/
  2683. * @author jordi_ros / http://plattsoft.com
  2684. * @author D1plo1d / http://github.com/D1plo1d
  2685. * @author alteredq / http://alteredqualia.com/
  2686. * @author mikael emtinger / http://gomo.se/
  2687. * @author timknip / http://www.floorplanner.com/
  2688. * @author bhouston / http://exocortex.com
  2689. * @author WestLangley / http://github.com/WestLangley
  2690. */
  2691. THREE.Matrix4 = function () {
  2692. this.elements = new Float32Array( [
  2693. 1, 0, 0, 0,
  2694. 0, 1, 0, 0,
  2695. 0, 0, 1, 0,
  2696. 0, 0, 0, 1
  2697. ] );
  2698. if ( arguments.length > 0 ) {
  2699. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2700. }
  2701. };
  2702. THREE.Matrix4.prototype = {
  2703. constructor: THREE.Matrix4,
  2704. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2705. var te = this.elements;
  2706. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2707. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2708. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2709. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2710. return this;
  2711. },
  2712. identity: function () {
  2713. this.set(
  2714. 1, 0, 0, 0,
  2715. 0, 1, 0, 0,
  2716. 0, 0, 1, 0,
  2717. 0, 0, 0, 1
  2718. );
  2719. return this;
  2720. },
  2721. copy: function ( m ) {
  2722. this.elements.set( m.elements );
  2723. return this;
  2724. },
  2725. extractPosition: function ( m ) {
  2726. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2727. return this.copyPosition( m );
  2728. },
  2729. copyPosition: function ( m ) {
  2730. var te = this.elements;
  2731. var me = m.elements;
  2732. te[ 12 ] = me[ 12 ];
  2733. te[ 13 ] = me[ 13 ];
  2734. te[ 14 ] = me[ 14 ];
  2735. return this;
  2736. },
  2737. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2738. var te = this.elements;
  2739. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2740. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2741. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2742. return this;
  2743. },
  2744. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2745. this.set(
  2746. xAxis.x, yAxis.x, zAxis.x, 0,
  2747. xAxis.y, yAxis.y, zAxis.y, 0,
  2748. xAxis.z, yAxis.z, zAxis.z, 0,
  2749. 0, 0, 0, 1
  2750. );
  2751. return this;
  2752. },
  2753. extractRotation: function () {
  2754. var v1;
  2755. return function ( m ) {
  2756. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2757. var te = this.elements;
  2758. var me = m.elements;
  2759. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2760. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2761. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2762. te[ 0 ] = me[ 0 ] * scaleX;
  2763. te[ 1 ] = me[ 1 ] * scaleX;
  2764. te[ 2 ] = me[ 2 ] * scaleX;
  2765. te[ 4 ] = me[ 4 ] * scaleY;
  2766. te[ 5 ] = me[ 5 ] * scaleY;
  2767. te[ 6 ] = me[ 6 ] * scaleY;
  2768. te[ 8 ] = me[ 8 ] * scaleZ;
  2769. te[ 9 ] = me[ 9 ] * scaleZ;
  2770. te[ 10 ] = me[ 10 ] * scaleZ;
  2771. return this;
  2772. };
  2773. }(),
  2774. makeRotationFromEuler: function ( euler ) {
  2775. if ( euler instanceof THREE.Euler === false ) {
  2776. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2777. }
  2778. var te = this.elements;
  2779. var x = euler.x, y = euler.y, z = euler.z;
  2780. var a = Math.cos( x ), b = Math.sin( x );
  2781. var c = Math.cos( y ), d = Math.sin( y );
  2782. var e = Math.cos( z ), f = Math.sin( z );
  2783. if ( euler.order === 'XYZ' ) {
  2784. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2785. te[ 0 ] = c * e;
  2786. te[ 4 ] = - c * f;
  2787. te[ 8 ] = d;
  2788. te[ 1 ] = af + be * d;
  2789. te[ 5 ] = ae - bf * d;
  2790. te[ 9 ] = - b * c;
  2791. te[ 2 ] = bf - ae * d;
  2792. te[ 6 ] = be + af * d;
  2793. te[ 10 ] = a * c;
  2794. } else if ( euler.order === 'YXZ' ) {
  2795. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2796. te[ 0 ] = ce + df * b;
  2797. te[ 4 ] = de * b - cf;
  2798. te[ 8 ] = a * d;
  2799. te[ 1 ] = a * f;
  2800. te[ 5 ] = a * e;
  2801. te[ 9 ] = - b;
  2802. te[ 2 ] = cf * b - de;
  2803. te[ 6 ] = df + ce * b;
  2804. te[ 10 ] = a * c;
  2805. } else if ( euler.order === 'ZXY' ) {
  2806. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2807. te[ 0 ] = ce - df * b;
  2808. te[ 4 ] = - a * f;
  2809. te[ 8 ] = de + cf * b;
  2810. te[ 1 ] = cf + de * b;
  2811. te[ 5 ] = a * e;
  2812. te[ 9 ] = df - ce * b;
  2813. te[ 2 ] = - a * d;
  2814. te[ 6 ] = b;
  2815. te[ 10 ] = a * c;
  2816. } else if ( euler.order === 'ZYX' ) {
  2817. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2818. te[ 0 ] = c * e;
  2819. te[ 4 ] = be * d - af;
  2820. te[ 8 ] = ae * d + bf;
  2821. te[ 1 ] = c * f;
  2822. te[ 5 ] = bf * d + ae;
  2823. te[ 9 ] = af * d - be;
  2824. te[ 2 ] = - d;
  2825. te[ 6 ] = b * c;
  2826. te[ 10 ] = a * c;
  2827. } else if ( euler.order === 'YZX' ) {
  2828. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2829. te[ 0 ] = c * e;
  2830. te[ 4 ] = bd - ac * f;
  2831. te[ 8 ] = bc * f + ad;
  2832. te[ 1 ] = f;
  2833. te[ 5 ] = a * e;
  2834. te[ 9 ] = - b * e;
  2835. te[ 2 ] = - d * e;
  2836. te[ 6 ] = ad * f + bc;
  2837. te[ 10 ] = ac - bd * f;
  2838. } else if ( euler.order === 'XZY' ) {
  2839. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2840. te[ 0 ] = c * e;
  2841. te[ 4 ] = - f;
  2842. te[ 8 ] = d * e;
  2843. te[ 1 ] = ac * f + bd;
  2844. te[ 5 ] = a * e;
  2845. te[ 9 ] = ad * f - bc;
  2846. te[ 2 ] = bc * f - ad;
  2847. te[ 6 ] = b * e;
  2848. te[ 10 ] = bd * f + ac;
  2849. }
  2850. // last column
  2851. te[ 3 ] = 0;
  2852. te[ 7 ] = 0;
  2853. te[ 11 ] = 0;
  2854. // bottom row
  2855. te[ 12 ] = 0;
  2856. te[ 13 ] = 0;
  2857. te[ 14 ] = 0;
  2858. te[ 15 ] = 1;
  2859. return this;
  2860. },
  2861. setRotationFromQuaternion: function ( q ) {
  2862. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2863. return this.makeRotationFromQuaternion( q );
  2864. },
  2865. makeRotationFromQuaternion: function ( q ) {
  2866. var te = this.elements;
  2867. var x = q.x, y = q.y, z = q.z, w = q.w;
  2868. var x2 = x + x, y2 = y + y, z2 = z + z;
  2869. var xx = x * x2, xy = x * y2, xz = x * z2;
  2870. var yy = y * y2, yz = y * z2, zz = z * z2;
  2871. var wx = w * x2, wy = w * y2, wz = w * z2;
  2872. te[ 0 ] = 1 - ( yy + zz );
  2873. te[ 4 ] = xy - wz;
  2874. te[ 8 ] = xz + wy;
  2875. te[ 1 ] = xy + wz;
  2876. te[ 5 ] = 1 - ( xx + zz );
  2877. te[ 9 ] = yz - wx;
  2878. te[ 2 ] = xz - wy;
  2879. te[ 6 ] = yz + wx;
  2880. te[ 10 ] = 1 - ( xx + yy );
  2881. // last column
  2882. te[ 3 ] = 0;
  2883. te[ 7 ] = 0;
  2884. te[ 11 ] = 0;
  2885. // bottom row
  2886. te[ 12 ] = 0;
  2887. te[ 13 ] = 0;
  2888. te[ 14 ] = 0;
  2889. te[ 15 ] = 1;
  2890. return this;
  2891. },
  2892. lookAt: function () {
  2893. var x, y, z;
  2894. return function ( eye, target, up ) {
  2895. if ( x === undefined ) x = new THREE.Vector3();
  2896. if ( y === undefined ) y = new THREE.Vector3();
  2897. if ( z === undefined ) z = new THREE.Vector3();
  2898. var te = this.elements;
  2899. z.subVectors( eye, target ).normalize();
  2900. if ( z.length() === 0 ) {
  2901. z.z = 1;
  2902. }
  2903. x.crossVectors( up, z ).normalize();
  2904. if ( x.length() === 0 ) {
  2905. z.x += 0.0001;
  2906. x.crossVectors( up, z ).normalize();
  2907. }
  2908. y.crossVectors( z, x );
  2909. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2910. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2911. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2912. return this;
  2913. };
  2914. }(),
  2915. multiply: function ( m, n ) {
  2916. if ( n !== undefined ) {
  2917. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2918. return this.multiplyMatrices( m, n );
  2919. }
  2920. return this.multiplyMatrices( this, m );
  2921. },
  2922. multiplyMatrices: function ( a, b ) {
  2923. var ae = a.elements;
  2924. var be = b.elements;
  2925. var te = this.elements;
  2926. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2927. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2928. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2929. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2930. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2931. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2932. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2933. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2934. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2935. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2936. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2937. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2938. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2939. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2940. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2941. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2942. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2943. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2944. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2945. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2946. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2947. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2948. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2949. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2950. return this;
  2951. },
  2952. multiplyToArray: function ( a, b, r ) {
  2953. var te = this.elements;
  2954. this.multiplyMatrices( a, b );
  2955. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  2956. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  2957. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  2958. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  2959. return this;
  2960. },
  2961. multiplyScalar: function ( s ) {
  2962. var te = this.elements;
  2963. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2964. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2965. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2966. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2967. return this;
  2968. },
  2969. multiplyVector3: function ( vector ) {
  2970. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  2971. return vector.applyProjection( this );
  2972. },
  2973. multiplyVector4: function ( vector ) {
  2974. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  2975. return vector.applyMatrix4( this );
  2976. },
  2977. multiplyVector3Array: function ( a ) {
  2978. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2979. return this.applyToVector3Array( a );
  2980. },
  2981. applyToVector3Array: function () {
  2982. var v1;
  2983. return function ( array, offset, length ) {
  2984. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2985. if ( offset === undefined ) offset = 0;
  2986. if ( length === undefined ) length = array.length;
  2987. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2988. v1.fromArray( array, j );
  2989. v1.applyMatrix4( this );
  2990. v1.toArray( array, j );
  2991. }
  2992. return array;
  2993. };
  2994. }(),
  2995. applyToBuffer: function () {
  2996. var v1;
  2997. return function applyToBuffer( buffer, offset, length ) {
  2998. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2999. if ( offset === undefined ) offset = 0;
  3000. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3001. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3002. v1.x = buffer.getX( j );
  3003. v1.y = buffer.getY( j );
  3004. v1.z = buffer.getZ( j );
  3005. v1.applyMatrix4( this );
  3006. buffer.setXYZ( v1.x, v1.y, v1.z );
  3007. }
  3008. return buffer;
  3009. };
  3010. }(),
  3011. rotateAxis: function ( v ) {
  3012. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  3013. v.transformDirection( this );
  3014. },
  3015. crossVector: function ( vector ) {
  3016. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3017. return vector.applyMatrix4( this );
  3018. },
  3019. determinant: function () {
  3020. var te = this.elements;
  3021. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3022. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3023. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3024. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3025. //TODO: make this more efficient
  3026. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3027. return (
  3028. n41 * (
  3029. + n14 * n23 * n32
  3030. - n13 * n24 * n32
  3031. - n14 * n22 * n33
  3032. + n12 * n24 * n33
  3033. + n13 * n22 * n34
  3034. - n12 * n23 * n34
  3035. ) +
  3036. n42 * (
  3037. + n11 * n23 * n34
  3038. - n11 * n24 * n33
  3039. + n14 * n21 * n33
  3040. - n13 * n21 * n34
  3041. + n13 * n24 * n31
  3042. - n14 * n23 * n31
  3043. ) +
  3044. n43 * (
  3045. + n11 * n24 * n32
  3046. - n11 * n22 * n34
  3047. - n14 * n21 * n32
  3048. + n12 * n21 * n34
  3049. + n14 * n22 * n31
  3050. - n12 * n24 * n31
  3051. ) +
  3052. n44 * (
  3053. - n13 * n22 * n31
  3054. - n11 * n23 * n32
  3055. + n11 * n22 * n33
  3056. + n13 * n21 * n32
  3057. - n12 * n21 * n33
  3058. + n12 * n23 * n31
  3059. )
  3060. );
  3061. },
  3062. transpose: function () {
  3063. var te = this.elements;
  3064. var tmp;
  3065. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3066. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3067. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3068. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3069. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3070. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3071. return this;
  3072. },
  3073. flattenToArrayOffset: function ( array, offset ) {
  3074. var te = this.elements;
  3075. array[ offset ] = te[ 0 ];
  3076. array[ offset + 1 ] = te[ 1 ];
  3077. array[ offset + 2 ] = te[ 2 ];
  3078. array[ offset + 3 ] = te[ 3 ];
  3079. array[ offset + 4 ] = te[ 4 ];
  3080. array[ offset + 5 ] = te[ 5 ];
  3081. array[ offset + 6 ] = te[ 6 ];
  3082. array[ offset + 7 ] = te[ 7 ];
  3083. array[ offset + 8 ] = te[ 8 ];
  3084. array[ offset + 9 ] = te[ 9 ];
  3085. array[ offset + 10 ] = te[ 10 ];
  3086. array[ offset + 11 ] = te[ 11 ];
  3087. array[ offset + 12 ] = te[ 12 ];
  3088. array[ offset + 13 ] = te[ 13 ];
  3089. array[ offset + 14 ] = te[ 14 ];
  3090. array[ offset + 15 ] = te[ 15 ];
  3091. return array;
  3092. },
  3093. getPosition: function () {
  3094. var v1;
  3095. return function () {
  3096. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3097. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3098. var te = this.elements;
  3099. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3100. };
  3101. }(),
  3102. setPosition: function ( v ) {
  3103. var te = this.elements;
  3104. te[ 12 ] = v.x;
  3105. te[ 13 ] = v.y;
  3106. te[ 14 ] = v.z;
  3107. return this;
  3108. },
  3109. getInverse: function ( m, throwOnInvertible ) {
  3110. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3111. var te = this.elements;
  3112. var me = m.elements;
  3113. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3114. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3115. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3116. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3117. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3118. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3119. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3120. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3121. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3122. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3123. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3124. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3125. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3126. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3127. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3128. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3129. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3130. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3131. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3132. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3133. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3134. if ( det === 0 ) {
  3135. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3136. if ( throwOnInvertible || false ) {
  3137. throw new Error( msg );
  3138. } else {
  3139. console.warn( msg );
  3140. }
  3141. this.identity();
  3142. return this;
  3143. }
  3144. this.multiplyScalar( 1 / det );
  3145. return this;
  3146. },
  3147. translate: function ( v ) {
  3148. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3149. },
  3150. rotateX: function ( angle ) {
  3151. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3152. },
  3153. rotateY: function ( angle ) {
  3154. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3155. },
  3156. rotateZ: function ( angle ) {
  3157. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3158. },
  3159. rotateByAxis: function ( axis, angle ) {
  3160. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3161. },
  3162. scale: function ( v ) {
  3163. var te = this.elements;
  3164. var x = v.x, y = v.y, z = v.z;
  3165. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3166. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3167. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3168. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3169. return this;
  3170. },
  3171. getMaxScaleOnAxis: function () {
  3172. var te = this.elements;
  3173. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3174. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3175. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3176. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  3177. },
  3178. makeTranslation: function ( x, y, z ) {
  3179. this.set(
  3180. 1, 0, 0, x,
  3181. 0, 1, 0, y,
  3182. 0, 0, 1, z,
  3183. 0, 0, 0, 1
  3184. );
  3185. return this;
  3186. },
  3187. makeRotationX: function ( theta ) {
  3188. var c = Math.cos( theta ), s = Math.sin( theta );
  3189. this.set(
  3190. 1, 0, 0, 0,
  3191. 0, c, - s, 0,
  3192. 0, s, c, 0,
  3193. 0, 0, 0, 1
  3194. );
  3195. return this;
  3196. },
  3197. makeRotationY: function ( theta ) {
  3198. var c = Math.cos( theta ), s = Math.sin( theta );
  3199. this.set(
  3200. c, 0, s, 0,
  3201. 0, 1, 0, 0,
  3202. - s, 0, c, 0,
  3203. 0, 0, 0, 1
  3204. );
  3205. return this;
  3206. },
  3207. makeRotationZ: function ( theta ) {
  3208. var c = Math.cos( theta ), s = Math.sin( theta );
  3209. this.set(
  3210. c, - s, 0, 0,
  3211. s, c, 0, 0,
  3212. 0, 0, 1, 0,
  3213. 0, 0, 0, 1
  3214. );
  3215. return this;
  3216. },
  3217. makeRotationAxis: function ( axis, angle ) {
  3218. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3219. var c = Math.cos( angle );
  3220. var s = Math.sin( angle );
  3221. var t = 1 - c;
  3222. var x = axis.x, y = axis.y, z = axis.z;
  3223. var tx = t * x, ty = t * y;
  3224. this.set(
  3225. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3226. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3227. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3228. 0, 0, 0, 1
  3229. );
  3230. return this;
  3231. },
  3232. makeScale: function ( x, y, z ) {
  3233. this.set(
  3234. x, 0, 0, 0,
  3235. 0, y, 0, 0,
  3236. 0, 0, z, 0,
  3237. 0, 0, 0, 1
  3238. );
  3239. return this;
  3240. },
  3241. compose: function ( position, quaternion, scale ) {
  3242. this.makeRotationFromQuaternion( quaternion );
  3243. this.scale( scale );
  3244. this.setPosition( position );
  3245. return this;
  3246. },
  3247. decompose: function () {
  3248. var vector, matrix;
  3249. return function ( position, quaternion, scale ) {
  3250. if ( vector === undefined ) vector = new THREE.Vector3();
  3251. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3252. var te = this.elements;
  3253. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3254. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3255. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3256. // if determine is negative, we need to invert one scale
  3257. var det = this.determinant();
  3258. if ( det < 0 ) {
  3259. sx = - sx;
  3260. }
  3261. position.x = te[ 12 ];
  3262. position.y = te[ 13 ];
  3263. position.z = te[ 14 ];
  3264. // scale the rotation part
  3265. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3266. var invSX = 1 / sx;
  3267. var invSY = 1 / sy;
  3268. var invSZ = 1 / sz;
  3269. matrix.elements[ 0 ] *= invSX;
  3270. matrix.elements[ 1 ] *= invSX;
  3271. matrix.elements[ 2 ] *= invSX;
  3272. matrix.elements[ 4 ] *= invSY;
  3273. matrix.elements[ 5 ] *= invSY;
  3274. matrix.elements[ 6 ] *= invSY;
  3275. matrix.elements[ 8 ] *= invSZ;
  3276. matrix.elements[ 9 ] *= invSZ;
  3277. matrix.elements[ 10 ] *= invSZ;
  3278. quaternion.setFromRotationMatrix( matrix );
  3279. scale.x = sx;
  3280. scale.y = sy;
  3281. scale.z = sz;
  3282. return this;
  3283. };
  3284. }(),
  3285. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3286. var te = this.elements;
  3287. var x = 2 * near / ( right - left );
  3288. var y = 2 * near / ( top - bottom );
  3289. var a = ( right + left ) / ( right - left );
  3290. var b = ( top + bottom ) / ( top - bottom );
  3291. var c = - ( far + near ) / ( far - near );
  3292. var d = - 2 * far * near / ( far - near );
  3293. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3294. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3295. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3296. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3297. return this;
  3298. },
  3299. makePerspective: function ( fov, aspect, near, far ) {
  3300. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3301. var ymin = - ymax;
  3302. var xmin = ymin * aspect;
  3303. var xmax = ymax * aspect;
  3304. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3305. },
  3306. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3307. var te = this.elements;
  3308. var w = right - left;
  3309. var h = top - bottom;
  3310. var p = far - near;
  3311. var x = ( right + left ) / w;
  3312. var y = ( top + bottom ) / h;
  3313. var z = ( far + near ) / p;
  3314. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3315. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3316. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3317. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3318. return this;
  3319. },
  3320. fromArray: function ( array ) {
  3321. this.elements.set( array );
  3322. return this;
  3323. },
  3324. toArray: function () {
  3325. var te = this.elements;
  3326. return [
  3327. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3328. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3329. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3330. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3331. ];
  3332. },
  3333. clone: function () {
  3334. return new THREE.Matrix4().fromArray( this.elements );
  3335. }
  3336. };
  3337. // File:src/math/Ray.js
  3338. /**
  3339. * @author bhouston / http://exocortex.com
  3340. */
  3341. THREE.Ray = function ( origin, direction ) {
  3342. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3343. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3344. };
  3345. THREE.Ray.prototype = {
  3346. constructor: THREE.Ray,
  3347. set: function ( origin, direction ) {
  3348. this.origin.copy( origin );
  3349. this.direction.copy( direction );
  3350. return this;
  3351. },
  3352. copy: function ( ray ) {
  3353. this.origin.copy( ray.origin );
  3354. this.direction.copy( ray.direction );
  3355. return this;
  3356. },
  3357. at: function ( t, optionalTarget ) {
  3358. var result = optionalTarget || new THREE.Vector3();
  3359. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3360. },
  3361. recast: function () {
  3362. var v1 = new THREE.Vector3();
  3363. return function ( t ) {
  3364. this.origin.copy( this.at( t, v1 ) );
  3365. return this;
  3366. };
  3367. }(),
  3368. closestPointToPoint: function ( point, optionalTarget ) {
  3369. var result = optionalTarget || new THREE.Vector3();
  3370. result.subVectors( point, this.origin );
  3371. var directionDistance = result.dot( this.direction );
  3372. if ( directionDistance < 0 ) {
  3373. return result.copy( this.origin );
  3374. }
  3375. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3376. },
  3377. distanceToPoint: function ( point ) {
  3378. return Math.sqrt( this.distanceSqToPoint( point ) );
  3379. },
  3380. distanceSqToPoint: function () {
  3381. var v1 = new THREE.Vector3();
  3382. return function ( point ) {
  3383. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3384. // point behind the ray
  3385. if ( directionDistance < 0 ) {
  3386. return this.origin.distanceToSquared( point );
  3387. }
  3388. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3389. return v1.distanceToSquared( point );
  3390. };
  3391. }(),
  3392. distanceSqToSegment: function () {
  3393. var segCenter = new THREE.Vector3();
  3394. var segDir = new THREE.Vector3();
  3395. var diff = new THREE.Vector3();
  3396. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3397. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3398. // It returns the min distance between the ray and the segment
  3399. // defined by v0 and v1
  3400. // It can also set two optional targets :
  3401. // - The closest point on the ray
  3402. // - The closest point on the segment
  3403. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3404. segDir.copy( v1 ).sub( v0 ).normalize();
  3405. diff.copy( this.origin ).sub( segCenter );
  3406. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3407. var a01 = - this.direction.dot( segDir );
  3408. var b0 = diff.dot( this.direction );
  3409. var b1 = - diff.dot( segDir );
  3410. var c = diff.lengthSq();
  3411. var det = Math.abs( 1 - a01 * a01 );
  3412. var s0, s1, sqrDist, extDet;
  3413. if ( det > 0 ) {
  3414. // The ray and segment are not parallel.
  3415. s0 = a01 * b1 - b0;
  3416. s1 = a01 * b0 - b1;
  3417. extDet = segExtent * det;
  3418. if ( s0 >= 0 ) {
  3419. if ( s1 >= - extDet ) {
  3420. if ( s1 <= extDet ) {
  3421. // region 0
  3422. // Minimum at interior points of ray and segment.
  3423. var invDet = 1 / det;
  3424. s0 *= invDet;
  3425. s1 *= invDet;
  3426. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3427. } else {
  3428. // region 1
  3429. s1 = segExtent;
  3430. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3431. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3432. }
  3433. } else {
  3434. // region 5
  3435. s1 = - segExtent;
  3436. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3437. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3438. }
  3439. } else {
  3440. if ( s1 <= - extDet ) {
  3441. // region 4
  3442. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3443. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3444. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3445. } else if ( s1 <= extDet ) {
  3446. // region 3
  3447. s0 = 0;
  3448. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3449. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3450. } else {
  3451. // region 2
  3452. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3453. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3454. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3455. }
  3456. }
  3457. } else {
  3458. // Ray and segment are parallel.
  3459. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3460. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3461. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3462. }
  3463. if ( optionalPointOnRay ) {
  3464. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3465. }
  3466. if ( optionalPointOnSegment ) {
  3467. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3468. }
  3469. return sqrDist;
  3470. };
  3471. }(),
  3472. isIntersectionSphere: function ( sphere ) {
  3473. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3474. },
  3475. intersectSphere: function () {
  3476. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3477. var v1 = new THREE.Vector3();
  3478. return function ( sphere, optionalTarget ) {
  3479. v1.subVectors( sphere.center, this.origin );
  3480. var tca = v1.dot( this.direction );
  3481. var d2 = v1.dot( v1 ) - tca * tca;
  3482. var radius2 = sphere.radius * sphere.radius;
  3483. if ( d2 > radius2 ) return null;
  3484. var thc = Math.sqrt( radius2 - d2 );
  3485. // t0 = first intersect point - entrance on front of sphere
  3486. var t0 = tca - thc;
  3487. // t1 = second intersect point - exit point on back of sphere
  3488. var t1 = tca + thc;
  3489. // test to see if both t0 and t1 are behind the ray - if so, return null
  3490. if ( t0 < 0 && t1 < 0 ) return null;
  3491. // test to see if t0 is behind the ray:
  3492. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3493. // in order to always return an intersect point that is in front of the ray.
  3494. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3495. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3496. return this.at( t0, optionalTarget );
  3497. }
  3498. }(),
  3499. isIntersectionPlane: function ( plane ) {
  3500. // check if the ray lies on the plane first
  3501. var distToPoint = plane.distanceToPoint( this.origin );
  3502. if ( distToPoint === 0 ) {
  3503. return true;
  3504. }
  3505. var denominator = plane.normal.dot( this.direction );
  3506. if ( denominator * distToPoint < 0 ) {
  3507. return true;
  3508. }
  3509. // ray origin is behind the plane (and is pointing behind it)
  3510. return false;
  3511. },
  3512. distanceToPlane: function ( plane ) {
  3513. var denominator = plane.normal.dot( this.direction );
  3514. if ( denominator === 0 ) {
  3515. // line is coplanar, return origin
  3516. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3517. return 0;
  3518. }
  3519. // Null is preferable to undefined since undefined means.... it is undefined
  3520. return null;
  3521. }
  3522. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3523. // Return if the ray never intersects the plane
  3524. return t >= 0 ? t : null;
  3525. },
  3526. intersectPlane: function ( plane, optionalTarget ) {
  3527. var t = this.distanceToPlane( plane );
  3528. if ( t === null ) {
  3529. return null;
  3530. }
  3531. return this.at( t, optionalTarget );
  3532. },
  3533. isIntersectionBox: function () {
  3534. var v = new THREE.Vector3();
  3535. return function ( box ) {
  3536. return this.intersectBox( box, v ) !== null;
  3537. };
  3538. }(),
  3539. intersectBox: function ( box, optionalTarget ) {
  3540. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3541. var tmin,tmax,tymin,tymax,tzmin,tzmax;
  3542. var invdirx = 1 / this.direction.x,
  3543. invdiry = 1 / this.direction.y,
  3544. invdirz = 1 / this.direction.z;
  3545. var origin = this.origin;
  3546. if ( invdirx >= 0 ) {
  3547. tmin = ( box.min.x - origin.x ) * invdirx;
  3548. tmax = ( box.max.x - origin.x ) * invdirx;
  3549. } else {
  3550. tmin = ( box.max.x - origin.x ) * invdirx;
  3551. tmax = ( box.min.x - origin.x ) * invdirx;
  3552. }
  3553. if ( invdiry >= 0 ) {
  3554. tymin = ( box.min.y - origin.y ) * invdiry;
  3555. tymax = ( box.max.y - origin.y ) * invdiry;
  3556. } else {
  3557. tymin = ( box.max.y - origin.y ) * invdiry;
  3558. tymax = ( box.min.y - origin.y ) * invdiry;
  3559. }
  3560. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3561. // These lines also handle the case where tmin or tmax is NaN
  3562. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3563. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3564. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3565. if ( invdirz >= 0 ) {
  3566. tzmin = ( box.min.z - origin.z ) * invdirz;
  3567. tzmax = ( box.max.z - origin.z ) * invdirz;
  3568. } else {
  3569. tzmin = ( box.max.z - origin.z ) * invdirz;
  3570. tzmax = ( box.min.z - origin.z ) * invdirz;
  3571. }
  3572. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3573. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3574. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3575. //return point closest to the ray (positive side)
  3576. if ( tmax < 0 ) return null;
  3577. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3578. },
  3579. intersectTriangle: function () {
  3580. // Compute the offset origin, edges, and normal.
  3581. var diff = new THREE.Vector3();
  3582. var edge1 = new THREE.Vector3();
  3583. var edge2 = new THREE.Vector3();
  3584. var normal = new THREE.Vector3();
  3585. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3586. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3587. edge1.subVectors( b, a );
  3588. edge2.subVectors( c, a );
  3589. normal.crossVectors( edge1, edge2 );
  3590. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3591. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3592. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3593. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3594. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3595. var DdN = this.direction.dot( normal );
  3596. var sign;
  3597. if ( DdN > 0 ) {
  3598. if ( backfaceCulling ) return null;
  3599. sign = 1;
  3600. } else if ( DdN < 0 ) {
  3601. sign = - 1;
  3602. DdN = - DdN;
  3603. } else {
  3604. return null;
  3605. }
  3606. diff.subVectors( this.origin, a );
  3607. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3608. // b1 < 0, no intersection
  3609. if ( DdQxE2 < 0 ) {
  3610. return null;
  3611. }
  3612. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3613. // b2 < 0, no intersection
  3614. if ( DdE1xQ < 0 ) {
  3615. return null;
  3616. }
  3617. // b1+b2 > 1, no intersection
  3618. if ( DdQxE2 + DdE1xQ > DdN ) {
  3619. return null;
  3620. }
  3621. // Line intersects triangle, check if ray does.
  3622. var QdN = - sign * diff.dot( normal );
  3623. // t < 0, no intersection
  3624. if ( QdN < 0 ) {
  3625. return null;
  3626. }
  3627. // Ray intersects triangle.
  3628. return this.at( QdN / DdN, optionalTarget );
  3629. };
  3630. }(),
  3631. applyMatrix4: function ( matrix4 ) {
  3632. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3633. this.origin.applyMatrix4( matrix4 );
  3634. this.direction.sub( this.origin );
  3635. this.direction.normalize();
  3636. return this;
  3637. },
  3638. equals: function ( ray ) {
  3639. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3640. },
  3641. clone: function () {
  3642. return new THREE.Ray().copy( this );
  3643. }
  3644. };
  3645. // File:src/math/Sphere.js
  3646. /**
  3647. * @author bhouston / http://exocortex.com
  3648. * @author mrdoob / http://mrdoob.com/
  3649. */
  3650. THREE.Sphere = function ( center, radius ) {
  3651. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3652. this.radius = ( radius !== undefined ) ? radius : 0;
  3653. };
  3654. THREE.Sphere.prototype = {
  3655. constructor: THREE.Sphere,
  3656. set: function ( center, radius ) {
  3657. this.center.copy( center );
  3658. this.radius = radius;
  3659. return this;
  3660. },
  3661. setFromPoints: function () {
  3662. var box = new THREE.Box3();
  3663. return function ( points, optionalCenter ) {
  3664. var center = this.center;
  3665. if ( optionalCenter !== undefined ) {
  3666. center.copy( optionalCenter );
  3667. } else {
  3668. box.setFromPoints( points ).center( center );
  3669. }
  3670. var maxRadiusSq = 0;
  3671. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3672. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3673. }
  3674. this.radius = Math.sqrt( maxRadiusSq );
  3675. return this;
  3676. };
  3677. }(),
  3678. copy: function ( sphere ) {
  3679. this.center.copy( sphere.center );
  3680. this.radius = sphere.radius;
  3681. return this;
  3682. },
  3683. empty: function () {
  3684. return ( this.radius <= 0 );
  3685. },
  3686. containsPoint: function ( point ) {
  3687. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3688. },
  3689. distanceToPoint: function ( point ) {
  3690. return ( point.distanceTo( this.center ) - this.radius );
  3691. },
  3692. intersectsSphere: function ( sphere ) {
  3693. var radiusSum = this.radius + sphere.radius;
  3694. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3695. },
  3696. clampPoint: function ( point, optionalTarget ) {
  3697. var deltaLengthSq = this.center.distanceToSquared( point );
  3698. var result = optionalTarget || new THREE.Vector3();
  3699. result.copy( point );
  3700. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3701. result.sub( this.center ).normalize();
  3702. result.multiplyScalar( this.radius ).add( this.center );
  3703. }
  3704. return result;
  3705. },
  3706. getBoundingBox: function ( optionalTarget ) {
  3707. var box = optionalTarget || new THREE.Box3();
  3708. box.set( this.center, this.center );
  3709. box.expandByScalar( this.radius );
  3710. return box;
  3711. },
  3712. applyMatrix4: function ( matrix ) {
  3713. this.center.applyMatrix4( matrix );
  3714. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3715. return this;
  3716. },
  3717. translate: function ( offset ) {
  3718. this.center.add( offset );
  3719. return this;
  3720. },
  3721. equals: function ( sphere ) {
  3722. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3723. },
  3724. clone: function () {
  3725. return new THREE.Sphere().copy( this );
  3726. }
  3727. };
  3728. // File:src/math/Frustum.js
  3729. /**
  3730. * @author mrdoob / http://mrdoob.com/
  3731. * @author alteredq / http://alteredqualia.com/
  3732. * @author bhouston / http://exocortex.com
  3733. */
  3734. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3735. this.planes = [
  3736. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3737. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3738. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3739. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3740. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3741. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3742. ];
  3743. };
  3744. THREE.Frustum.prototype = {
  3745. constructor: THREE.Frustum,
  3746. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3747. var planes = this.planes;
  3748. planes[ 0 ].copy( p0 );
  3749. planes[ 1 ].copy( p1 );
  3750. planes[ 2 ].copy( p2 );
  3751. planes[ 3 ].copy( p3 );
  3752. planes[ 4 ].copy( p4 );
  3753. planes[ 5 ].copy( p5 );
  3754. return this;
  3755. },
  3756. copy: function ( frustum ) {
  3757. var planes = this.planes;
  3758. for ( var i = 0; i < 6; i ++ ) {
  3759. planes[ i ].copy( frustum.planes[ i ] );
  3760. }
  3761. return this;
  3762. },
  3763. setFromMatrix: function ( m ) {
  3764. var planes = this.planes;
  3765. var me = m.elements;
  3766. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3767. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3768. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3769. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3770. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3771. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3772. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3773. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3774. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3775. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3776. return this;
  3777. },
  3778. intersectsObject: function () {
  3779. var sphere = new THREE.Sphere();
  3780. return function ( object ) {
  3781. var geometry = object.geometry;
  3782. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3783. sphere.copy( geometry.boundingSphere );
  3784. sphere.applyMatrix4( object.matrixWorld );
  3785. return this.intersectsSphere( sphere );
  3786. };
  3787. }(),
  3788. intersectsSphere: function ( sphere ) {
  3789. var planes = this.planes;
  3790. var center = sphere.center;
  3791. var negRadius = - sphere.radius;
  3792. for ( var i = 0; i < 6; i ++ ) {
  3793. var distance = planes[ i ].distanceToPoint( center );
  3794. if ( distance < negRadius ) {
  3795. return false;
  3796. }
  3797. }
  3798. return true;
  3799. },
  3800. intersectsBox: function () {
  3801. var p1 = new THREE.Vector3(),
  3802. p2 = new THREE.Vector3();
  3803. return function ( box ) {
  3804. var planes = this.planes;
  3805. for ( var i = 0; i < 6 ; i ++ ) {
  3806. var plane = planes[ i ];
  3807. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3808. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3809. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3810. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3811. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3812. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3813. var d1 = plane.distanceToPoint( p1 );
  3814. var d2 = plane.distanceToPoint( p2 );
  3815. // if both outside plane, no intersection
  3816. if ( d1 < 0 && d2 < 0 ) {
  3817. return false;
  3818. }
  3819. }
  3820. return true;
  3821. };
  3822. }(),
  3823. containsPoint: function ( point ) {
  3824. var planes = this.planes;
  3825. for ( var i = 0; i < 6; i ++ ) {
  3826. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3827. return false;
  3828. }
  3829. }
  3830. return true;
  3831. },
  3832. clone: function () {
  3833. return new THREE.Frustum().copy( this );
  3834. }
  3835. };
  3836. // File:src/math/Plane.js
  3837. /**
  3838. * @author bhouston / http://exocortex.com
  3839. */
  3840. THREE.Plane = function ( normal, constant ) {
  3841. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3842. this.constant = ( constant !== undefined ) ? constant : 0;
  3843. };
  3844. THREE.Plane.prototype = {
  3845. constructor: THREE.Plane,
  3846. set: function ( normal, constant ) {
  3847. this.normal.copy( normal );
  3848. this.constant = constant;
  3849. return this;
  3850. },
  3851. setComponents: function ( x, y, z, w ) {
  3852. this.normal.set( x, y, z );
  3853. this.constant = w;
  3854. return this;
  3855. },
  3856. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3857. this.normal.copy( normal );
  3858. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3859. return this;
  3860. },
  3861. setFromCoplanarPoints: function () {
  3862. var v1 = new THREE.Vector3();
  3863. var v2 = new THREE.Vector3();
  3864. return function ( a, b, c ) {
  3865. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3866. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3867. this.setFromNormalAndCoplanarPoint( normal, a );
  3868. return this;
  3869. };
  3870. }(),
  3871. copy: function ( plane ) {
  3872. this.normal.copy( plane.normal );
  3873. this.constant = plane.constant;
  3874. return this;
  3875. },
  3876. normalize: function () {
  3877. // Note: will lead to a divide by zero if the plane is invalid.
  3878. var inverseNormalLength = 1.0 / this.normal.length();
  3879. this.normal.multiplyScalar( inverseNormalLength );
  3880. this.constant *= inverseNormalLength;
  3881. return this;
  3882. },
  3883. negate: function () {
  3884. this.constant *= - 1;
  3885. this.normal.negate();
  3886. return this;
  3887. },
  3888. distanceToPoint: function ( point ) {
  3889. return this.normal.dot( point ) + this.constant;
  3890. },
  3891. distanceToSphere: function ( sphere ) {
  3892. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3893. },
  3894. projectPoint: function ( point, optionalTarget ) {
  3895. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3896. },
  3897. orthoPoint: function ( point, optionalTarget ) {
  3898. var perpendicularMagnitude = this.distanceToPoint( point );
  3899. var result = optionalTarget || new THREE.Vector3();
  3900. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3901. },
  3902. isIntersectionLine: function ( line ) {
  3903. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3904. var startSign = this.distanceToPoint( line.start );
  3905. var endSign = this.distanceToPoint( line.end );
  3906. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3907. },
  3908. intersectLine: function () {
  3909. var v1 = new THREE.Vector3();
  3910. return function ( line, optionalTarget ) {
  3911. var result = optionalTarget || new THREE.Vector3();
  3912. var direction = line.delta( v1 );
  3913. var denominator = this.normal.dot( direction );
  3914. if ( denominator === 0 ) {
  3915. // line is coplanar, return origin
  3916. if ( this.distanceToPoint( line.start ) === 0 ) {
  3917. return result.copy( line.start );
  3918. }
  3919. // Unsure if this is the correct method to handle this case.
  3920. return undefined;
  3921. }
  3922. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3923. if ( t < 0 || t > 1 ) {
  3924. return undefined;
  3925. }
  3926. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  3927. };
  3928. }(),
  3929. coplanarPoint: function ( optionalTarget ) {
  3930. var result = optionalTarget || new THREE.Vector3();
  3931. return result.copy( this.normal ).multiplyScalar( - this.constant );
  3932. },
  3933. applyMatrix4: function () {
  3934. var v1 = new THREE.Vector3();
  3935. var v2 = new THREE.Vector3();
  3936. var m1 = new THREE.Matrix3();
  3937. return function ( matrix, optionalNormalMatrix ) {
  3938. // compute new normal based on theory here:
  3939. // http://www.songho.ca/opengl/gl_normaltransform.html
  3940. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3941. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  3942. var newCoplanarPoint = this.coplanarPoint( v2 );
  3943. newCoplanarPoint.applyMatrix4( matrix );
  3944. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  3945. return this;
  3946. };
  3947. }(),
  3948. translate: function ( offset ) {
  3949. this.constant = this.constant - offset.dot( this.normal );
  3950. return this;
  3951. },
  3952. equals: function ( plane ) {
  3953. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  3954. },
  3955. clone: function () {
  3956. return new THREE.Plane().copy( this );
  3957. }
  3958. };
  3959. // File:src/math/Math.js
  3960. /**
  3961. * @author alteredq / http://alteredqualia.com/
  3962. * @author mrdoob / http://mrdoob.com/
  3963. */
  3964. THREE.Math = {
  3965. generateUUID: function () {
  3966. // http://www.broofa.com/Tools/Math.uuid.htm
  3967. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  3968. var uuid = new Array( 36 );
  3969. var rnd = 0, r;
  3970. return function () {
  3971. for ( var i = 0; i < 36; i ++ ) {
  3972. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  3973. uuid[ i ] = '-';
  3974. } else if ( i === 14 ) {
  3975. uuid[ i ] = '4';
  3976. } else {
  3977. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  3978. r = rnd & 0xf;
  3979. rnd = rnd >> 4;
  3980. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  3981. }
  3982. }
  3983. return uuid.join( '' );
  3984. };
  3985. }(),
  3986. // Clamp value to range <a, b>
  3987. clamp: function ( x, a, b ) {
  3988. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  3989. },
  3990. // Clamp value to range <a, inf)
  3991. clampBottom: function ( x, a ) {
  3992. return x < a ? a : x;
  3993. },
  3994. // compute euclidian modulo of m % n
  3995. // https://en.wikipedia.org/wiki/Modulo_operation
  3996. euclideanModulo: function ( n, m ) {
  3997. return ( ( n % m ) + m ) % m;
  3998. },
  3999. // Linear mapping from range <a1, a2> to range <b1, b2>
  4000. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4001. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4002. },
  4003. // http://en.wikipedia.org/wiki/Smoothstep
  4004. smoothstep: function ( x, min, max ) {
  4005. if ( x <= min ) return 0;
  4006. if ( x >= max ) return 1;
  4007. x = ( x - min ) / ( max - min );
  4008. return x * x * ( 3 - 2 * x );
  4009. },
  4010. smootherstep: function ( x, min, max ) {
  4011. if ( x <= min ) return 0;
  4012. if ( x >= max ) return 1;
  4013. x = ( x - min ) / ( max - min );
  4014. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4015. },
  4016. // Random float from <0, 1> with 16 bits of randomness
  4017. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4018. random16: function () {
  4019. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4020. },
  4021. // Random integer from <low, high> interval
  4022. randInt: function ( low, high ) {
  4023. return Math.floor( this.randFloat( low, high ) );
  4024. },
  4025. // Random float from <low, high> interval
  4026. randFloat: function ( low, high ) {
  4027. return low + Math.random() * ( high - low );
  4028. },
  4029. // Random float from <-range/2, range/2> interval
  4030. randFloatSpread: function ( range ) {
  4031. return range * ( 0.5 - Math.random() );
  4032. },
  4033. degToRad: function () {
  4034. var degreeToRadiansFactor = Math.PI / 180;
  4035. return function ( degrees ) {
  4036. return degrees * degreeToRadiansFactor;
  4037. };
  4038. }(),
  4039. radToDeg: function () {
  4040. var radianToDegreesFactor = 180 / Math.PI;
  4041. return function ( radians ) {
  4042. return radians * radianToDegreesFactor;
  4043. };
  4044. }(),
  4045. isPowerOfTwo: function ( value ) {
  4046. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4047. },
  4048. nextPowerOfTwo: function ( value ) {
  4049. value --;
  4050. value |= value >> 1;
  4051. value |= value >> 2;
  4052. value |= value >> 4;
  4053. value |= value >> 8;
  4054. value |= value >> 16;
  4055. value ++;
  4056. return value;
  4057. }
  4058. };
  4059. // File:src/math/Spline.js
  4060. /**
  4061. * Spline from Tween.js, slightly optimized (and trashed)
  4062. * http://sole.github.com/tween.js/examples/05_spline.html
  4063. *
  4064. * @author mrdoob / http://mrdoob.com/
  4065. * @author alteredq / http://alteredqualia.com/
  4066. */
  4067. THREE.Spline = function ( points ) {
  4068. this.points = points;
  4069. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4070. point, intPoint, weight, w2, w3,
  4071. pa, pb, pc, pd;
  4072. this.initFromArray = function ( a ) {
  4073. this.points = [];
  4074. for ( var i = 0; i < a.length; i ++ ) {
  4075. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4076. }
  4077. };
  4078. this.getPoint = function ( k ) {
  4079. point = ( this.points.length - 1 ) * k;
  4080. intPoint = Math.floor( point );
  4081. weight = point - intPoint;
  4082. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4083. c[ 1 ] = intPoint;
  4084. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4085. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4086. pa = this.points[ c[ 0 ] ];
  4087. pb = this.points[ c[ 1 ] ];
  4088. pc = this.points[ c[ 2 ] ];
  4089. pd = this.points[ c[ 3 ] ];
  4090. w2 = weight * weight;
  4091. w3 = weight * w2;
  4092. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4093. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4094. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4095. return v3;
  4096. };
  4097. this.getControlPointsArray = function () {
  4098. var i, p, l = this.points.length,
  4099. coords = [];
  4100. for ( i = 0; i < l; i ++ ) {
  4101. p = this.points[ i ];
  4102. coords[ i ] = [ p.x, p.y, p.z ];
  4103. }
  4104. return coords;
  4105. };
  4106. // approximate length by summing linear segments
  4107. this.getLength = function ( nSubDivisions ) {
  4108. var i, index, nSamples, position,
  4109. point = 0, intPoint = 0, oldIntPoint = 0,
  4110. oldPosition = new THREE.Vector3(),
  4111. tmpVec = new THREE.Vector3(),
  4112. chunkLengths = [],
  4113. totalLength = 0;
  4114. // first point has 0 length
  4115. chunkLengths[ 0 ] = 0;
  4116. if ( ! nSubDivisions ) nSubDivisions = 100;
  4117. nSamples = this.points.length * nSubDivisions;
  4118. oldPosition.copy( this.points[ 0 ] );
  4119. for ( i = 1; i < nSamples; i ++ ) {
  4120. index = i / nSamples;
  4121. position = this.getPoint( index );
  4122. tmpVec.copy( position );
  4123. totalLength += tmpVec.distanceTo( oldPosition );
  4124. oldPosition.copy( position );
  4125. point = ( this.points.length - 1 ) * index;
  4126. intPoint = Math.floor( point );
  4127. if ( intPoint !== oldIntPoint ) {
  4128. chunkLengths[ intPoint ] = totalLength;
  4129. oldIntPoint = intPoint;
  4130. }
  4131. }
  4132. // last point ends with total length
  4133. chunkLengths[ chunkLengths.length ] = totalLength;
  4134. return { chunks: chunkLengths, total: totalLength };
  4135. };
  4136. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4137. var i, j,
  4138. index, indexCurrent, indexNext,
  4139. realDistance,
  4140. sampling, position,
  4141. newpoints = [],
  4142. tmpVec = new THREE.Vector3(),
  4143. sl = this.getLength();
  4144. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4145. for ( i = 1; i < this.points.length; i ++ ) {
  4146. //tmpVec.copy( this.points[ i - 1 ] );
  4147. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4148. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4149. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4150. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4151. indexNext = i / ( this.points.length - 1 );
  4152. for ( j = 1; j < sampling - 1; j ++ ) {
  4153. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4154. position = this.getPoint( index );
  4155. newpoints.push( tmpVec.copy( position ).clone() );
  4156. }
  4157. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4158. }
  4159. this.points = newpoints;
  4160. };
  4161. // Catmull-Rom
  4162. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4163. var v0 = ( p2 - p0 ) * 0.5,
  4164. v1 = ( p3 - p1 ) * 0.5;
  4165. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4166. }
  4167. };
  4168. // File:src/math/Triangle.js
  4169. /**
  4170. * @author bhouston / http://exocortex.com
  4171. * @author mrdoob / http://mrdoob.com/
  4172. */
  4173. THREE.Triangle = function ( a, b, c ) {
  4174. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4175. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4176. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4177. };
  4178. THREE.Triangle.normal = function () {
  4179. var v0 = new THREE.Vector3();
  4180. return function ( a, b, c, optionalTarget ) {
  4181. var result = optionalTarget || new THREE.Vector3();
  4182. result.subVectors( c, b );
  4183. v0.subVectors( a, b );
  4184. result.cross( v0 );
  4185. var resultLengthSq = result.lengthSq();
  4186. if ( resultLengthSq > 0 ) {
  4187. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4188. }
  4189. return result.set( 0, 0, 0 );
  4190. };
  4191. }();
  4192. // static/instance method to calculate barycentric coordinates
  4193. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4194. THREE.Triangle.barycoordFromPoint = function () {
  4195. var v0 = new THREE.Vector3();
  4196. var v1 = new THREE.Vector3();
  4197. var v2 = new THREE.Vector3();
  4198. return function ( point, a, b, c, optionalTarget ) {
  4199. v0.subVectors( c, a );
  4200. v1.subVectors( b, a );
  4201. v2.subVectors( point, a );
  4202. var dot00 = v0.dot( v0 );
  4203. var dot01 = v0.dot( v1 );
  4204. var dot02 = v0.dot( v2 );
  4205. var dot11 = v1.dot( v1 );
  4206. var dot12 = v1.dot( v2 );
  4207. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4208. var result = optionalTarget || new THREE.Vector3();
  4209. // collinear or singular triangle
  4210. if ( denom === 0 ) {
  4211. // arbitrary location outside of triangle?
  4212. // not sure if this is the best idea, maybe should be returning undefined
  4213. return result.set( - 2, - 1, - 1 );
  4214. }
  4215. var invDenom = 1 / denom;
  4216. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4217. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4218. // barycentric coordinates must always sum to 1
  4219. return result.set( 1 - u - v, v, u );
  4220. };
  4221. }();
  4222. THREE.Triangle.containsPoint = function () {
  4223. var v1 = new THREE.Vector3();
  4224. return function ( point, a, b, c ) {
  4225. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4226. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4227. };
  4228. }();
  4229. THREE.Triangle.prototype = {
  4230. constructor: THREE.Triangle,
  4231. set: function ( a, b, c ) {
  4232. this.a.copy( a );
  4233. this.b.copy( b );
  4234. this.c.copy( c );
  4235. return this;
  4236. },
  4237. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4238. this.a.copy( points[ i0 ] );
  4239. this.b.copy( points[ i1 ] );
  4240. this.c.copy( points[ i2 ] );
  4241. return this;
  4242. },
  4243. copy: function ( triangle ) {
  4244. this.a.copy( triangle.a );
  4245. this.b.copy( triangle.b );
  4246. this.c.copy( triangle.c );
  4247. return this;
  4248. },
  4249. area: function () {
  4250. var v0 = new THREE.Vector3();
  4251. var v1 = new THREE.Vector3();
  4252. return function () {
  4253. v0.subVectors( this.c, this.b );
  4254. v1.subVectors( this.a, this.b );
  4255. return v0.cross( v1 ).length() * 0.5;
  4256. };
  4257. }(),
  4258. midpoint: function ( optionalTarget ) {
  4259. var result = optionalTarget || new THREE.Vector3();
  4260. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4261. },
  4262. normal: function ( optionalTarget ) {
  4263. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4264. },
  4265. plane: function ( optionalTarget ) {
  4266. var result = optionalTarget || new THREE.Plane();
  4267. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4268. },
  4269. barycoordFromPoint: function ( point, optionalTarget ) {
  4270. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4271. },
  4272. containsPoint: function ( point ) {
  4273. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4274. },
  4275. equals: function ( triangle ) {
  4276. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4277. },
  4278. clone: function () {
  4279. return new THREE.Triangle().copy( this );
  4280. }
  4281. };
  4282. // File:src/core/Clock.js
  4283. /**
  4284. * @author alteredq / http://alteredqualia.com/
  4285. */
  4286. THREE.Clock = function ( autoStart ) {
  4287. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4288. this.startTime = 0;
  4289. this.oldTime = 0;
  4290. this.elapsedTime = 0;
  4291. this.running = false;
  4292. };
  4293. THREE.Clock.prototype = {
  4294. constructor: THREE.Clock,
  4295. start: function () {
  4296. this.startTime = self.performance !== undefined && self.performance.now !== undefined
  4297. ? self.performance.now()
  4298. : Date.now();
  4299. this.oldTime = this.startTime;
  4300. this.running = true;
  4301. },
  4302. stop: function () {
  4303. this.getElapsedTime();
  4304. this.running = false;
  4305. },
  4306. getElapsedTime: function () {
  4307. this.getDelta();
  4308. return this.elapsedTime;
  4309. },
  4310. getDelta: function () {
  4311. var diff = 0;
  4312. if ( this.autoStart && ! this.running ) {
  4313. this.start();
  4314. }
  4315. if ( this.running ) {
  4316. var newTime = self.performance !== undefined && self.performance.now !== undefined
  4317. ? self.performance.now()
  4318. : Date.now();
  4319. diff = 0.001 * ( newTime - this.oldTime );
  4320. this.oldTime = newTime;
  4321. this.elapsedTime += diff;
  4322. }
  4323. return diff;
  4324. }
  4325. };
  4326. // File:src/core/EventDispatcher.js
  4327. /**
  4328. * https://github.com/mrdoob/eventdispatcher.js/
  4329. */
  4330. THREE.EventDispatcher = function () {};
  4331. THREE.EventDispatcher.prototype = {
  4332. constructor: THREE.EventDispatcher,
  4333. apply: function ( object ) {
  4334. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4335. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4336. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4337. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4338. },
  4339. addEventListener: function ( type, listener ) {
  4340. if ( this._listeners === undefined ) this._listeners = {};
  4341. var listeners = this._listeners;
  4342. if ( listeners[ type ] === undefined ) {
  4343. listeners[ type ] = [];
  4344. }
  4345. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4346. listeners[ type ].push( listener );
  4347. }
  4348. },
  4349. hasEventListener: function ( type, listener ) {
  4350. if ( this._listeners === undefined ) return false;
  4351. var listeners = this._listeners;
  4352. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4353. return true;
  4354. }
  4355. return false;
  4356. },
  4357. removeEventListener: function ( type, listener ) {
  4358. if ( this._listeners === undefined ) return;
  4359. var listeners = this._listeners;
  4360. var listenerArray = listeners[ type ];
  4361. if ( listenerArray !== undefined ) {
  4362. var index = listenerArray.indexOf( listener );
  4363. if ( index !== - 1 ) {
  4364. listenerArray.splice( index, 1 );
  4365. }
  4366. }
  4367. },
  4368. dispatchEvent: function ( event ) {
  4369. if ( this._listeners === undefined ) return;
  4370. var listeners = this._listeners;
  4371. var listenerArray = listeners[ event.type ];
  4372. if ( listenerArray !== undefined ) {
  4373. event.target = this;
  4374. var array = [];
  4375. var length = listenerArray.length;
  4376. for ( var i = 0; i < length; i ++ ) {
  4377. array[ i ] = listenerArray[ i ];
  4378. }
  4379. for ( var i = 0; i < length; i ++ ) {
  4380. array[ i ].call( this, event );
  4381. }
  4382. }
  4383. }
  4384. };
  4385. // File:src/core/Raycaster.js
  4386. /**
  4387. * @author mrdoob / http://mrdoob.com/
  4388. * @author bhouston / http://exocortex.com/
  4389. * @author stephomi / http://stephaneginier.com/
  4390. */
  4391. ( function ( THREE ) {
  4392. THREE.Raycaster = function ( origin, direction, near, far ) {
  4393. this.ray = new THREE.Ray( origin, direction );
  4394. // direction is assumed to be normalized (for accurate distance calculations)
  4395. this.near = near || 0;
  4396. this.far = far || Infinity;
  4397. this.params = {
  4398. Sprite: {},
  4399. Mesh: {},
  4400. PointCloud: { threshold: 1 },
  4401. LOD: {},
  4402. Line: {}
  4403. };
  4404. };
  4405. var descSort = function ( a, b ) {
  4406. return a.distance - b.distance;
  4407. };
  4408. var intersectObject = function ( object, raycaster, intersects, recursive ) {
  4409. if ( object.visible === false ) return;
  4410. object.raycast( raycaster, intersects );
  4411. if ( recursive === true ) {
  4412. var children = object.children;
  4413. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4414. intersectObject( children[ i ], raycaster, intersects, true );
  4415. }
  4416. }
  4417. };
  4418. //
  4419. THREE.Raycaster.prototype = {
  4420. constructor: THREE.Raycaster,
  4421. linePrecision: 1,
  4422. set: function ( origin, direction ) {
  4423. // direction is assumed to be normalized (for accurate distance calculations)
  4424. this.ray.set( origin, direction );
  4425. },
  4426. setFromCamera: function ( coords, camera ) {
  4427. if ( camera instanceof THREE.PerspectiveCamera ) {
  4428. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4429. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4430. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4431. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4432. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4433. } else {
  4434. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4435. }
  4436. },
  4437. intersectObject: function ( object, recursive ) {
  4438. var intersects = [];
  4439. intersectObject( object, this, intersects, recursive );
  4440. intersects.sort( descSort );
  4441. return intersects;
  4442. },
  4443. intersectObjects: function ( objects, recursive ) {
  4444. var intersects = [];
  4445. if ( Array.isArray( objects ) === false ) {
  4446. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4447. return intersects;
  4448. }
  4449. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4450. intersectObject( objects[ i ], this, intersects, recursive );
  4451. }
  4452. intersects.sort( descSort );
  4453. return intersects;
  4454. }
  4455. };
  4456. }( THREE ) );
  4457. // File:src/core/Object3D.js
  4458. /**
  4459. * @author mrdoob / http://mrdoob.com/
  4460. * @author mikael emtinger / http://gomo.se/
  4461. * @author alteredq / http://alteredqualia.com/
  4462. * @author WestLangley / http://github.com/WestLangley
  4463. * @author elephantatwork / www.elephantatwork.ch
  4464. */
  4465. THREE.Object3D = function () {
  4466. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4467. this.uuid = THREE.Math.generateUUID();
  4468. this.name = '';
  4469. this.type = 'Object3D';
  4470. this.parent = undefined;
  4471. this.children = [];
  4472. this.up = THREE.Object3D.DefaultUp.clone();
  4473. var position = new THREE.Vector3();
  4474. var rotation = new THREE.Euler();
  4475. var quaternion = new THREE.Quaternion();
  4476. var scale = new THREE.Vector3( 1, 1, 1 );
  4477. var onRotationChange = function () {
  4478. quaternion.setFromEuler( rotation, false );
  4479. };
  4480. var onQuaternionChange = function () {
  4481. rotation.setFromQuaternion( quaternion, undefined, false );
  4482. };
  4483. rotation.onChange( onRotationChange );
  4484. quaternion.onChange( onQuaternionChange );
  4485. Object.defineProperties( this, {
  4486. position: {
  4487. enumerable: true,
  4488. value: position
  4489. },
  4490. rotation: {
  4491. enumerable: true,
  4492. value: rotation
  4493. },
  4494. quaternion: {
  4495. enumerable: true,
  4496. value: quaternion
  4497. },
  4498. scale: {
  4499. enumerable: true,
  4500. value: scale
  4501. }
  4502. } );
  4503. this.rotationAutoUpdate = true;
  4504. this.matrix = new THREE.Matrix4();
  4505. this.matrixWorld = new THREE.Matrix4();
  4506. this.matrixAutoUpdate = true;
  4507. this.matrixWorldNeedsUpdate = false;
  4508. this.visible = true;
  4509. this.castShadow = false;
  4510. this.receiveShadow = false;
  4511. this.frustumCulled = true;
  4512. this.renderOrder = 0;
  4513. this.userData = {};
  4514. };
  4515. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4516. THREE.Object3D.prototype = {
  4517. constructor: THREE.Object3D,
  4518. get eulerOrder () {
  4519. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4520. return this.rotation.order;
  4521. },
  4522. set eulerOrder ( value ) {
  4523. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4524. this.rotation.order = value;
  4525. },
  4526. get useQuaternion () {
  4527. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4528. },
  4529. set useQuaternion ( value ) {
  4530. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4531. },
  4532. set renderDepth ( value ) {
  4533. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  4534. },
  4535. applyMatrix: function ( matrix ) {
  4536. this.matrix.multiplyMatrices( matrix, this.matrix );
  4537. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4538. },
  4539. setRotationFromAxisAngle: function ( axis, angle ) {
  4540. // assumes axis is normalized
  4541. this.quaternion.setFromAxisAngle( axis, angle );
  4542. },
  4543. setRotationFromEuler: function ( euler ) {
  4544. this.quaternion.setFromEuler( euler, true );
  4545. },
  4546. setRotationFromMatrix: function ( m ) {
  4547. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4548. this.quaternion.setFromRotationMatrix( m );
  4549. },
  4550. setRotationFromQuaternion: function ( q ) {
  4551. // assumes q is normalized
  4552. this.quaternion.copy( q );
  4553. },
  4554. rotateOnAxis: function () {
  4555. // rotate object on axis in object space
  4556. // axis is assumed to be normalized
  4557. var q1 = new THREE.Quaternion();
  4558. return function ( axis, angle ) {
  4559. q1.setFromAxisAngle( axis, angle );
  4560. this.quaternion.multiply( q1 );
  4561. return this;
  4562. }
  4563. }(),
  4564. rotateX: function () {
  4565. var v1 = new THREE.Vector3( 1, 0, 0 );
  4566. return function ( angle ) {
  4567. return this.rotateOnAxis( v1, angle );
  4568. };
  4569. }(),
  4570. rotateY: function () {
  4571. var v1 = new THREE.Vector3( 0, 1, 0 );
  4572. return function ( angle ) {
  4573. return this.rotateOnAxis( v1, angle );
  4574. };
  4575. }(),
  4576. rotateZ: function () {
  4577. var v1 = new THREE.Vector3( 0, 0, 1 );
  4578. return function ( angle ) {
  4579. return this.rotateOnAxis( v1, angle );
  4580. };
  4581. }(),
  4582. translateOnAxis: function () {
  4583. // translate object by distance along axis in object space
  4584. // axis is assumed to be normalized
  4585. var v1 = new THREE.Vector3();
  4586. return function ( axis, distance ) {
  4587. v1.copy( axis ).applyQuaternion( this.quaternion );
  4588. this.position.add( v1.multiplyScalar( distance ) );
  4589. return this;
  4590. }
  4591. }(),
  4592. translate: function ( distance, axis ) {
  4593. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4594. return this.translateOnAxis( axis, distance );
  4595. },
  4596. translateX: function () {
  4597. var v1 = new THREE.Vector3( 1, 0, 0 );
  4598. return function ( distance ) {
  4599. return this.translateOnAxis( v1, distance );
  4600. };
  4601. }(),
  4602. translateY: function () {
  4603. var v1 = new THREE.Vector3( 0, 1, 0 );
  4604. return function ( distance ) {
  4605. return this.translateOnAxis( v1, distance );
  4606. };
  4607. }(),
  4608. translateZ: function () {
  4609. var v1 = new THREE.Vector3( 0, 0, 1 );
  4610. return function ( distance ) {
  4611. return this.translateOnAxis( v1, distance );
  4612. };
  4613. }(),
  4614. localToWorld: function ( vector ) {
  4615. return vector.applyMatrix4( this.matrixWorld );
  4616. },
  4617. worldToLocal: function () {
  4618. var m1 = new THREE.Matrix4();
  4619. return function ( vector ) {
  4620. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4621. };
  4622. }(),
  4623. lookAt: function () {
  4624. // This routine does not support objects with rotated and/or translated parent(s)
  4625. var m1 = new THREE.Matrix4();
  4626. return function ( vector ) {
  4627. m1.lookAt( vector, this.position, this.up );
  4628. this.quaternion.setFromRotationMatrix( m1 );
  4629. };
  4630. }(),
  4631. add: function ( object ) {
  4632. if ( arguments.length > 1 ) {
  4633. for ( var i = 0; i < arguments.length; i ++ ) {
  4634. this.add( arguments[ i ] );
  4635. }
  4636. return this;
  4637. }
  4638. if ( object === this ) {
  4639. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4640. return this;
  4641. }
  4642. if ( object instanceof THREE.Object3D ) {
  4643. if ( object.parent !== undefined ) {
  4644. object.parent.remove( object );
  4645. }
  4646. object.parent = this;
  4647. object.dispatchEvent( { type: 'added' } );
  4648. this.children.push( object );
  4649. } else {
  4650. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4651. }
  4652. return this;
  4653. },
  4654. remove: function ( object ) {
  4655. if ( arguments.length > 1 ) {
  4656. for ( var i = 0; i < arguments.length; i ++ ) {
  4657. this.remove( arguments[ i ] );
  4658. }
  4659. }
  4660. var index = this.children.indexOf( object );
  4661. if ( index !== - 1 ) {
  4662. object.parent = undefined;
  4663. object.dispatchEvent( { type: 'removed' } );
  4664. this.children.splice( index, 1 );
  4665. }
  4666. },
  4667. getChildByName: function ( name ) {
  4668. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4669. return this.getObjectByName( name );
  4670. },
  4671. getObjectById: function ( id ) {
  4672. return this.getObjectByProperty( 'id', id );
  4673. },
  4674. getObjectByName: function ( name ) {
  4675. return this.getObjectByProperty( 'name', name );
  4676. },
  4677. getObjectByProperty: function ( name, value ) {
  4678. if ( this[ name ] === value ) return this;
  4679. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4680. var child = this.children[ i ];
  4681. var object = child.getObjectByProperty( name, value );
  4682. if ( object !== undefined ) {
  4683. return object;
  4684. }
  4685. }
  4686. return undefined;
  4687. },
  4688. getWorldPosition: function ( optionalTarget ) {
  4689. var result = optionalTarget || new THREE.Vector3();
  4690. this.updateMatrixWorld( true );
  4691. return result.setFromMatrixPosition( this.matrixWorld );
  4692. },
  4693. getWorldQuaternion: function () {
  4694. var position = new THREE.Vector3();
  4695. var scale = new THREE.Vector3();
  4696. return function ( optionalTarget ) {
  4697. var result = optionalTarget || new THREE.Quaternion();
  4698. this.updateMatrixWorld( true );
  4699. this.matrixWorld.decompose( position, result, scale );
  4700. return result;
  4701. }
  4702. }(),
  4703. getWorldRotation: function () {
  4704. var quaternion = new THREE.Quaternion();
  4705. return function ( optionalTarget ) {
  4706. var result = optionalTarget || new THREE.Euler();
  4707. this.getWorldQuaternion( quaternion );
  4708. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4709. }
  4710. }(),
  4711. getWorldScale: function () {
  4712. var position = new THREE.Vector3();
  4713. var quaternion = new THREE.Quaternion();
  4714. return function ( optionalTarget ) {
  4715. var result = optionalTarget || new THREE.Vector3();
  4716. this.updateMatrixWorld( true );
  4717. this.matrixWorld.decompose( position, quaternion, result );
  4718. return result;
  4719. }
  4720. }(),
  4721. getWorldDirection: function () {
  4722. var quaternion = new THREE.Quaternion();
  4723. return function ( optionalTarget ) {
  4724. var result = optionalTarget || new THREE.Vector3();
  4725. this.getWorldQuaternion( quaternion );
  4726. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4727. }
  4728. }(),
  4729. raycast: function () {},
  4730. traverse: function ( callback ) {
  4731. callback( this );
  4732. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4733. this.children[ i ].traverse( callback );
  4734. }
  4735. },
  4736. traverseVisible: function ( callback ) {
  4737. if ( this.visible === false ) return;
  4738. callback( this );
  4739. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4740. this.children[ i ].traverseVisible( callback );
  4741. }
  4742. },
  4743. traverseAncestors: function ( callback ) {
  4744. if ( this.parent ) {
  4745. callback( this.parent );
  4746. this.parent.traverseAncestors( callback );
  4747. }
  4748. },
  4749. updateMatrix: function () {
  4750. this.matrix.compose( this.position, this.quaternion, this.scale );
  4751. this.matrixWorldNeedsUpdate = true;
  4752. },
  4753. updateMatrixWorld: function ( force ) {
  4754. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4755. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4756. if ( this.parent === undefined ) {
  4757. this.matrixWorld.copy( this.matrix );
  4758. } else {
  4759. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4760. }
  4761. this.matrixWorldNeedsUpdate = false;
  4762. force = true;
  4763. }
  4764. // update children
  4765. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4766. this.children[ i ].updateMatrixWorld( force );
  4767. }
  4768. },
  4769. toJSON: function ( meta ) {
  4770. var isRootObject = ( meta === undefined );
  4771. var data = {};
  4772. // meta is a hash used to collect geometries, materials.
  4773. // not providing it implies that this is the root object
  4774. // being serialized.
  4775. if ( isRootObject ) {
  4776. // initialize meta obj
  4777. meta = {
  4778. geometries: {},
  4779. materials: {},
  4780. textures: {},
  4781. images: {}
  4782. };
  4783. data.metadata = {
  4784. version: 4.4,
  4785. type: 'Object',
  4786. generator: 'Object3D.toJSON'
  4787. };
  4788. }
  4789. // standard Object3D serialization
  4790. data.uuid = this.uuid;
  4791. data.type = this.type;
  4792. if ( this.name !== '' ) data.name = this.name;
  4793. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4794. if ( this.visible !== true ) data.visible = this.visible;
  4795. data.matrix = this.matrix.toArray();
  4796. if ( this.children.length > 0 ) {
  4797. data.children = [];
  4798. for ( var i = 0; i < this.children.length; i ++ ) {
  4799. data.children.push( this.children[ i ].toJSON( meta ).object );
  4800. }
  4801. }
  4802. var output = {};
  4803. if ( isRootObject ) {
  4804. var geometries = extractFromCache( meta.geometries );
  4805. var materials = extractFromCache( meta.materials );
  4806. var textures = extractFromCache( meta.textures );
  4807. var images = extractFromCache( meta.images );
  4808. if ( geometries.length > 0 ) output.geometries = geometries;
  4809. if ( materials.length > 0 ) output.materials = materials;
  4810. if ( textures.length > 0 ) output.textures = textures;
  4811. if ( images.length > 0 ) output.images = images;
  4812. }
  4813. output.object = data;
  4814. return output;
  4815. // extract data from the cache hash
  4816. // remove metadata on each item
  4817. // and return as array
  4818. function extractFromCache ( cache ) {
  4819. var values = [];
  4820. for ( var key in cache ) {
  4821. var data = cache[ key ];
  4822. delete data.metadata;
  4823. values.push( data );
  4824. }
  4825. return values;
  4826. }
  4827. },
  4828. clone: function ( object, recursive ) {
  4829. if ( object === undefined ) object = new THREE.Object3D();
  4830. if ( recursive === undefined ) recursive = true;
  4831. object.name = this.name;
  4832. object.up.copy( this.up );
  4833. object.position.copy( this.position );
  4834. object.quaternion.copy( this.quaternion );
  4835. object.scale.copy( this.scale );
  4836. object.rotationAutoUpdate = this.rotationAutoUpdate;
  4837. object.matrix.copy( this.matrix );
  4838. object.matrixWorld.copy( this.matrixWorld );
  4839. object.matrixAutoUpdate = this.matrixAutoUpdate;
  4840. object.matrixWorldNeedsUpdate = this.matrixWorldNeedsUpdate;
  4841. object.visible = this.visible;
  4842. object.castShadow = this.castShadow;
  4843. object.receiveShadow = this.receiveShadow;
  4844. object.frustumCulled = this.frustumCulled;
  4845. object.renderOrder = this.renderOrder;
  4846. object.userData = JSON.parse( JSON.stringify( this.userData ) );
  4847. if ( recursive === true ) {
  4848. for ( var i = 0; i < this.children.length; i ++ ) {
  4849. var child = this.children[ i ];
  4850. object.add( child.clone() );
  4851. }
  4852. }
  4853. return object;
  4854. }
  4855. };
  4856. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4857. THREE.Object3DIdCount = 0;
  4858. // File:src/core/Face3.js
  4859. /**
  4860. * @author mrdoob / http://mrdoob.com/
  4861. * @author alteredq / http://alteredqualia.com/
  4862. */
  4863. THREE.Face3 = function ( a, b, c, normal, color ) {
  4864. this.a = a;
  4865. this.b = b;
  4866. this.c = c;
  4867. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  4868. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4869. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  4870. this.vertexColors = Array.isArray( color ) ? color : [];
  4871. this.vertexTangents = [];
  4872. };
  4873. THREE.Face3.prototype = {
  4874. constructor: THREE.Face3,
  4875. clone: function () {
  4876. var face = new THREE.Face3( this.a, this.b, this.c );
  4877. face.normal.copy( this.normal );
  4878. face.color.copy( this.color );
  4879. for ( var i = 0, il = this.vertexNormals.length; i < il; i ++ ) {
  4880. face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
  4881. }
  4882. for ( var i = 0, il = this.vertexColors.length; i < il; i ++ ) {
  4883. face.vertexColors[ i ] = this.vertexColors[ i ].clone();
  4884. }
  4885. for ( var i = 0, il = this.vertexTangents.length; i < il; i ++ ) {
  4886. face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
  4887. }
  4888. return face;
  4889. }
  4890. };
  4891. // File:src/core/Face4.js
  4892. /**
  4893. * @author mrdoob / http://mrdoob.com/
  4894. */
  4895. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  4896. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  4897. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  4898. };
  4899. // File:src/core/BufferAttribute.js
  4900. /**
  4901. * @author mrdoob / http://mrdoob.com/
  4902. */
  4903. THREE.BufferAttribute = function ( array, itemSize ) {
  4904. this.uuid = THREE.Math.generateUUID();
  4905. this.array = array;
  4906. this.itemSize = itemSize;
  4907. this.version = 0;
  4908. };
  4909. THREE.BufferAttribute.prototype = {
  4910. constructor: THREE.BufferAttribute,
  4911. get length () {
  4912. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  4913. return this.array.length;
  4914. },
  4915. get count() {
  4916. return this.array.length / this.itemSize;
  4917. },
  4918. set needsUpdate( value ) {
  4919. if ( value === true ) this.version ++;
  4920. },
  4921. copyAt: function ( index1, attribute, index2 ) {
  4922. index1 *= this.itemSize;
  4923. index2 *= attribute.itemSize;
  4924. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  4925. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  4926. }
  4927. return this;
  4928. },
  4929. copyArray: function ( array ) {
  4930. this.array.set( array );
  4931. return this;
  4932. },
  4933. copyColorsArray: function ( colors ) {
  4934. var array = this.array, offset = 0;
  4935. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  4936. var color = colors[ i ];
  4937. if ( color === undefined ) {
  4938. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  4939. color = new THREE.Color();
  4940. }
  4941. array[ offset ++ ] = color.r;
  4942. array[ offset ++ ] = color.g;
  4943. array[ offset ++ ] = color.b;
  4944. }
  4945. return this;
  4946. },
  4947. copyIndicesArray: function ( indices ) {
  4948. var array = this.array, offset = 0;
  4949. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  4950. var index = indices[ i ];
  4951. array[ offset ++ ] = index.a;
  4952. array[ offset ++ ] = index.b;
  4953. array[ offset ++ ] = index.c;
  4954. }
  4955. return this;
  4956. },
  4957. copyVector2sArray: function ( vectors ) {
  4958. var array = this.array, offset = 0;
  4959. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  4960. var vector = vectors[ i ];
  4961. if ( vector === undefined ) {
  4962. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  4963. vector = new THREE.Vector2();
  4964. }
  4965. array[ offset ++ ] = vector.x;
  4966. array[ offset ++ ] = vector.y;
  4967. }
  4968. return this;
  4969. },
  4970. copyVector3sArray: function ( vectors ) {
  4971. var array = this.array, offset = 0;
  4972. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  4973. var vector = vectors[ i ];
  4974. if ( vector === undefined ) {
  4975. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  4976. vector = new THREE.Vector3();
  4977. }
  4978. array[ offset ++ ] = vector.x;
  4979. array[ offset ++ ] = vector.y;
  4980. array[ offset ++ ] = vector.z;
  4981. }
  4982. return this;
  4983. },
  4984. copyVector4sArray: function ( vectors ) {
  4985. var array = this.array, offset = 0;
  4986. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  4987. var vector = vectors[ i ];
  4988. if ( vector === undefined ) {
  4989. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  4990. vector = new THREE.Vector4();
  4991. }
  4992. array[ offset ++ ] = vector.x;
  4993. array[ offset ++ ] = vector.y;
  4994. array[ offset ++ ] = vector.z;
  4995. array[ offset ++ ] = vector.w;
  4996. }
  4997. return this;
  4998. },
  4999. set: function ( value, offset ) {
  5000. if ( offset === undefined ) offset = 0;
  5001. this.array.set( value, offset );
  5002. return this;
  5003. },
  5004. getX: function ( index ) {
  5005. return this.array[ index * this.itemSize ];
  5006. },
  5007. setX: function ( index, x ) {
  5008. this.array[ index * this.itemSize ] = x;
  5009. return this;
  5010. },
  5011. getY: function ( index ) {
  5012. return this.array[ index * this.itemSize + 1 ];
  5013. },
  5014. setY: function ( index, y ) {
  5015. this.array[ index * this.itemSize + 1 ] = y;
  5016. return this;
  5017. },
  5018. getZ: function ( index ) {
  5019. return this.array[ index * this.itemSize + 2 ];
  5020. },
  5021. setZ: function ( index, z ) {
  5022. this.array[ index * this.itemSize + 2 ] = z;
  5023. return this;
  5024. },
  5025. getW: function ( index ) {
  5026. return this.array[ index * this.itemSize + 3 ];
  5027. },
  5028. setW: function ( index, w ) {
  5029. this.array[ index * this.itemSize + 3 ] = w;
  5030. return this;
  5031. },
  5032. setXY: function ( index, x, y ) {
  5033. index *= this.itemSize;
  5034. this.array[ index + 0 ] = x;
  5035. this.array[ index + 1 ] = y;
  5036. return this;
  5037. },
  5038. setXYZ: function ( index, x, y, z ) {
  5039. index *= this.itemSize;
  5040. this.array[ index + 0 ] = x;
  5041. this.array[ index + 1 ] = y;
  5042. this.array[ index + 2 ] = z;
  5043. return this;
  5044. },
  5045. setXYZW: function ( index, x, y, z, w ) {
  5046. index *= this.itemSize;
  5047. this.array[ index + 0 ] = x;
  5048. this.array[ index + 1 ] = y;
  5049. this.array[ index + 2 ] = z;
  5050. this.array[ index + 3 ] = w;
  5051. return this;
  5052. },
  5053. clone: function () {
  5054. return new THREE.BufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5055. }
  5056. };
  5057. //
  5058. THREE.Int8Attribute = function ( array, itemSize ) {
  5059. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5060. };
  5061. THREE.Uint8Attribute = function ( array, itemSize ) {
  5062. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5063. };
  5064. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5065. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5066. };
  5067. THREE.Int16Attribute = function ( array, itemSize ) {
  5068. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5069. };
  5070. THREE.Uint16Attribute = function ( array, itemSize ) {
  5071. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5072. };
  5073. THREE.Int32Attribute = function ( array, itemSize ) {
  5074. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5075. };
  5076. THREE.Uint32Attribute = function ( array, itemSize ) {
  5077. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5078. };
  5079. THREE.Float32Attribute = function ( array, itemSize ) {
  5080. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5081. };
  5082. THREE.Float64Attribute = function ( array, itemSize ) {
  5083. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5084. };
  5085. // File:src/core/DynamicBufferAttribute.js
  5086. /**
  5087. * @author benaadams / https://twitter.com/ben_a_adams
  5088. * @author mrdoob / http://mrdoob.com/
  5089. */
  5090. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5091. THREE.BufferAttribute.call( this, array, itemSize );
  5092. this.updateRange = { offset: 0, count: -1 };
  5093. };
  5094. THREE.DynamicBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5095. THREE.DynamicBufferAttribute.prototype.constructor = THREE.DynamicBufferAttribute;
  5096. THREE.DynamicBufferAttribute.prototype.clone = function () {
  5097. return new THREE.DynamicBufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5098. };
  5099. // File:src/core/InstancedBufferAttribute.js
  5100. /**
  5101. * @author benaadams / https://twitter.com/ben_a_adams
  5102. */
  5103. THREE.InstancedBufferAttribute = function (array, itemSize, meshPerAttribute, dynamic) {
  5104. THREE.DynamicBufferAttribute.call( this, array, itemSize );
  5105. this.dynamic = dynamic || false;
  5106. this.meshPerAttribute = meshPerAttribute || 1;
  5107. };
  5108. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.DynamicBufferAttribute.prototype );
  5109. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5110. THREE.InstancedBufferAttribute.prototype.clone = function () {
  5111. return new THREE.InstancedBufferAttribute( new this.array.constructor( this.array ), this.itemSize, this.meshPerAttribute, this.dynamic );
  5112. };
  5113. // File:src/core/InterleavedBuffer.js
  5114. /**
  5115. * @author benaadams / https://twitter.com/ben_a_adams
  5116. */
  5117. THREE.InterleavedBuffer = function ( array, stride, dynamic ) {
  5118. this.uuid = THREE.Math.generateUUID();
  5119. this.array = array;
  5120. this.stride = stride;
  5121. this.version = 0;
  5122. this.dynamic = dynamic || false;
  5123. this.updateRange = { offset: 0, count: -1 };
  5124. };
  5125. THREE.InterleavedBuffer.prototype = {
  5126. constructor: THREE.InterleavedBuffer,
  5127. get length () {
  5128. return this.array.length;
  5129. },
  5130. get count () {
  5131. return this.array.length / this.stride;
  5132. },
  5133. set needsUpdate( value ) {
  5134. if ( value === true ) this.version ++;
  5135. },
  5136. copyAt: function ( index1, attribute, index2 ) {
  5137. index1 *= this.stride;
  5138. index2 *= attribute.stride;
  5139. for ( var i = 0, l = this.stride; i < l; i++ ) {
  5140. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5141. }
  5142. return this;
  5143. },
  5144. set: function ( value, offset ) {
  5145. if ( offset === undefined ) offset = 0;
  5146. this.array.set( value, offset );
  5147. return this;
  5148. },
  5149. clone: function () {
  5150. return new THREE.InterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic );
  5151. }
  5152. };
  5153. // File:src/core/InstancedInterleavedBuffer.js
  5154. /**
  5155. * @author benaadams / https://twitter.com/ben_a_adams
  5156. */
  5157. THREE.InstancedInterleavedBuffer = function ( array, stride, dynamic, meshPerAttribute ) {
  5158. THREE.InterleavedBuffer.call( this, array, stride, dynamic );
  5159. this.meshPerAttribute = meshPerAttribute || 1;
  5160. };
  5161. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5162. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5163. THREE.InstancedInterleavedBuffer.prototype.clone = function () {
  5164. return new THREE.InstancedInterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic, this.meshPerAttribute );
  5165. };
  5166. // File:src/core/InterleavedBufferAttribute.js
  5167. /**
  5168. * @author benaadams / https://twitter.com/ben_a_adams
  5169. */
  5170. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5171. this.uuid = THREE.Math.generateUUID();
  5172. this.data = interleavedBuffer;
  5173. this.itemSize = itemSize;
  5174. this.offset = offset;
  5175. };
  5176. THREE.InterleavedBufferAttribute.prototype = {
  5177. constructor: THREE.InterleavedBufferAttribute,
  5178. get length() {
  5179. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5180. return this.array.length;
  5181. },
  5182. get count() {
  5183. return this.data.array.length / this.data.stride;
  5184. },
  5185. setX: function ( index, x ) {
  5186. this.data.array[ index * this.data.stride + this.offset ] = x;
  5187. return this;
  5188. },
  5189. setY: function ( index, y ) {
  5190. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5191. return this;
  5192. },
  5193. setZ: function ( index, z ) {
  5194. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5195. return this;
  5196. },
  5197. setW: function ( index, w ) {
  5198. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5199. return this;
  5200. },
  5201. getX: function ( index ) {
  5202. return this.data.array[ index * this.data.stride + this.offset ];
  5203. },
  5204. getY: function ( index ) {
  5205. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5206. },
  5207. getZ: function ( index ) {
  5208. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5209. },
  5210. getW: function ( index ) {
  5211. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5212. },
  5213. setXY: function ( index, x, y ) {
  5214. index = index * this.data.stride + this.offset;
  5215. this.data.array[ index + 0 ] = x;
  5216. this.data.array[ index + 1 ] = y;
  5217. return this;
  5218. },
  5219. setXYZ: function ( index, x, y, z ) {
  5220. index = index * this.data.stride + this.offset;
  5221. this.data.array[ index + 0 ] = x;
  5222. this.data.array[ index + 1 ] = y;
  5223. this.data.array[ index + 2 ] = z;
  5224. return this;
  5225. },
  5226. setXYZW: function ( index, x, y, z, w ) {
  5227. index = index * this.data.stride + this.offset;
  5228. this.data.array[ index + 0 ] = x;
  5229. this.data.array[ index + 1 ] = y;
  5230. this.data.array[ index + 2 ] = z;
  5231. this.data.array[ index + 3 ] = w;
  5232. return this;
  5233. }
  5234. };
  5235. // File:src/core/Geometry.js
  5236. /**
  5237. * @author mrdoob / http://mrdoob.com/
  5238. * @author kile / http://kile.stravaganza.org/
  5239. * @author alteredq / http://alteredqualia.com/
  5240. * @author mikael emtinger / http://gomo.se/
  5241. * @author zz85 / http://www.lab4games.net/zz85/blog
  5242. * @author bhouston / http://exocortex.com
  5243. */
  5244. THREE.Geometry = function () {
  5245. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5246. this.uuid = THREE.Math.generateUUID();
  5247. this.name = '';
  5248. this.type = 'Geometry';
  5249. this.vertices = [];
  5250. this.colors = [];
  5251. this.faces = [];
  5252. this.faceVertexUvs = [ [] ];
  5253. this.morphTargets = [];
  5254. this.morphColors = [];
  5255. this.morphNormals = [];
  5256. this.skinWeights = [];
  5257. this.skinIndices = [];
  5258. this.lineDistances = [];
  5259. this.boundingBox = null;
  5260. this.boundingSphere = null;
  5261. this.hasTangents = false;
  5262. // update flags
  5263. this.verticesNeedUpdate = false;
  5264. this.elementsNeedUpdate = false;
  5265. this.uvsNeedUpdate = false;
  5266. this.normalsNeedUpdate = false;
  5267. this.tangentsNeedUpdate = false;
  5268. this.colorsNeedUpdate = false;
  5269. this.lineDistancesNeedUpdate = false;
  5270. };
  5271. THREE.Geometry.prototype = {
  5272. constructor: THREE.Geometry,
  5273. applyMatrix: function ( matrix ) {
  5274. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5275. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5276. var vertex = this.vertices[ i ];
  5277. vertex.applyMatrix4( matrix );
  5278. }
  5279. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5280. var face = this.faces[ i ];
  5281. face.normal.applyMatrix3( normalMatrix ).normalize();
  5282. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5283. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5284. }
  5285. }
  5286. if ( this.boundingBox !== null ) {
  5287. this.computeBoundingBox();
  5288. }
  5289. if ( this.boundingSphere !== null ) {
  5290. this.computeBoundingSphere();
  5291. }
  5292. this.verticesNeedUpdate = true;
  5293. this.normalsNeedUpdate = true;
  5294. },
  5295. fromBufferGeometry: function ( geometry ) {
  5296. var scope = this;
  5297. var attributes = geometry.attributes;
  5298. var vertices = attributes.position.array;
  5299. var indices = attributes.index !== undefined ? attributes.index.array : undefined;
  5300. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5301. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5302. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5303. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5304. var tangents = attributes.tangent !== undefined ? attributes.tangent.array : undefined;
  5305. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5306. if ( tangents !== undefined ) this.hasTangents = true;
  5307. var tempNormals = [];
  5308. var tempUVs = [];
  5309. var tempUVs2 = [];
  5310. var tempTangents = [];
  5311. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5312. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5313. if ( normals !== undefined ) {
  5314. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5315. }
  5316. if ( colors !== undefined ) {
  5317. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5318. }
  5319. if ( uvs !== undefined ) {
  5320. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5321. }
  5322. if ( uvs2 !== undefined ) {
  5323. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5324. }
  5325. if ( tangents !== undefined ) {
  5326. tempTangents.push( new THREE.Vector4( tangents[ k ], tangents[ k + 1 ], tangents[ k + 2 ], tangents[ k + 3 ] ) );
  5327. }
  5328. }
  5329. var addFace = function ( a, b, c ) {
  5330. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5331. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5332. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5333. scope.faces.push( face );
  5334. if ( uvs !== undefined ) {
  5335. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5336. }
  5337. if ( uvs2 !== undefined ) {
  5338. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5339. }
  5340. if ( tangents !== undefined ) {
  5341. face.vertexTangents.push( tempTangents[ a ].clone(), tempTangents[ b ].clone(), tempTangents[ c ].clone() );
  5342. }
  5343. };
  5344. if ( indices !== undefined ) {
  5345. var drawcalls = geometry.drawcalls;
  5346. if ( drawcalls.length > 0 ) {
  5347. for ( var i = 0; i < drawcalls.length; i ++ ) {
  5348. var drawcall = drawcalls[ i ];
  5349. var start = drawcall.start;
  5350. var count = drawcall.count;
  5351. var index = drawcall.index;
  5352. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5353. addFace( index + indices[ j ], index + indices[ j + 1 ], index + indices[ j + 2 ] );
  5354. }
  5355. }
  5356. } else {
  5357. for ( var i = 0; i < indices.length; i += 3 ) {
  5358. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5359. }
  5360. }
  5361. } else {
  5362. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5363. addFace( i, i + 1, i + 2 );
  5364. }
  5365. }
  5366. this.computeFaceNormals();
  5367. if ( geometry.boundingBox !== null ) {
  5368. this.boundingBox = geometry.boundingBox.clone();
  5369. }
  5370. if ( geometry.boundingSphere !== null ) {
  5371. this.boundingSphere = geometry.boundingSphere.clone();
  5372. }
  5373. return this;
  5374. },
  5375. center: function () {
  5376. this.computeBoundingBox();
  5377. var offset = this.boundingBox.center().negate();
  5378. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  5379. return offset;
  5380. },
  5381. normalize: function () {
  5382. this.computeBoundingSphere();
  5383. var center = this.boundingSphere.center;
  5384. var radius = this.boundingSphere.radius;
  5385. var s = radius === 0 ? 1 : 1.0 / radius;
  5386. var matrix = new THREE.Matrix4();
  5387. matrix.set(
  5388. s, 0, 0, -s * center.x,
  5389. 0, s, 0, -s * center.y,
  5390. 0, 0, s, -s * center.z,
  5391. 0, 0, 0, 1
  5392. );
  5393. this.applyMatrix( matrix );
  5394. return this;
  5395. },
  5396. computeFaceNormals: function () {
  5397. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5398. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5399. var face = this.faces[ f ];
  5400. var vA = this.vertices[ face.a ];
  5401. var vB = this.vertices[ face.b ];
  5402. var vC = this.vertices[ face.c ];
  5403. cb.subVectors( vC, vB );
  5404. ab.subVectors( vA, vB );
  5405. cb.cross( ab );
  5406. cb.normalize();
  5407. face.normal.copy( cb );
  5408. }
  5409. },
  5410. computeVertexNormals: function ( areaWeighted ) {
  5411. var v, vl, f, fl, face, vertices;
  5412. vertices = new Array( this.vertices.length );
  5413. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5414. vertices[ v ] = new THREE.Vector3();
  5415. }
  5416. if ( areaWeighted ) {
  5417. // vertex normals weighted by triangle areas
  5418. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5419. var vA, vB, vC;
  5420. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5421. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5422. face = this.faces[ f ];
  5423. vA = this.vertices[ face.a ];
  5424. vB = this.vertices[ face.b ];
  5425. vC = this.vertices[ face.c ];
  5426. cb.subVectors( vC, vB );
  5427. ab.subVectors( vA, vB );
  5428. cb.cross( ab );
  5429. vertices[ face.a ].add( cb );
  5430. vertices[ face.b ].add( cb );
  5431. vertices[ face.c ].add( cb );
  5432. }
  5433. } else {
  5434. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5435. face = this.faces[ f ];
  5436. vertices[ face.a ].add( face.normal );
  5437. vertices[ face.b ].add( face.normal );
  5438. vertices[ face.c ].add( face.normal );
  5439. }
  5440. }
  5441. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5442. vertices[ v ].normalize();
  5443. }
  5444. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5445. face = this.faces[ f ];
  5446. var vertexNormals = face.vertexNormals;
  5447. if ( vertexNormals.length === 3 ) {
  5448. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5449. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5450. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5451. } else {
  5452. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5453. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5454. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5455. }
  5456. }
  5457. },
  5458. computeMorphNormals: function () {
  5459. var i, il, f, fl, face;
  5460. // save original normals
  5461. // - create temp variables on first access
  5462. // otherwise just copy (for faster repeated calls)
  5463. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5464. face = this.faces[ f ];
  5465. if ( ! face.__originalFaceNormal ) {
  5466. face.__originalFaceNormal = face.normal.clone();
  5467. } else {
  5468. face.__originalFaceNormal.copy( face.normal );
  5469. }
  5470. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5471. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5472. if ( ! face.__originalVertexNormals[ i ] ) {
  5473. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5474. } else {
  5475. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5476. }
  5477. }
  5478. }
  5479. // use temp geometry to compute face and vertex normals for each morph
  5480. var tmpGeo = new THREE.Geometry();
  5481. tmpGeo.faces = this.faces;
  5482. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5483. // create on first access
  5484. if ( ! this.morphNormals[ i ] ) {
  5485. this.morphNormals[ i ] = {};
  5486. this.morphNormals[ i ].faceNormals = [];
  5487. this.morphNormals[ i ].vertexNormals = [];
  5488. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5489. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5490. var faceNormal, vertexNormals;
  5491. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5492. faceNormal = new THREE.Vector3();
  5493. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5494. dstNormalsFace.push( faceNormal );
  5495. dstNormalsVertex.push( vertexNormals );
  5496. }
  5497. }
  5498. var morphNormals = this.morphNormals[ i ];
  5499. // set vertices to morph target
  5500. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5501. // compute morph normals
  5502. tmpGeo.computeFaceNormals();
  5503. tmpGeo.computeVertexNormals();
  5504. // store morph normals
  5505. var faceNormal, vertexNormals;
  5506. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5507. face = this.faces[ f ];
  5508. faceNormal = morphNormals.faceNormals[ f ];
  5509. vertexNormals = morphNormals.vertexNormals[ f ];
  5510. faceNormal.copy( face.normal );
  5511. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5512. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5513. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5514. }
  5515. }
  5516. // restore original normals
  5517. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5518. face = this.faces[ f ];
  5519. face.normal = face.__originalFaceNormal;
  5520. face.vertexNormals = face.__originalVertexNormals;
  5521. }
  5522. },
  5523. computeTangents: function () {
  5524. // based on http://www.terathon.com/code/tangent.html
  5525. // tangents go to vertices
  5526. var f, fl, v, vl, i, vertexIndex,
  5527. face, uv, vA, vB, vC, uvA, uvB, uvC,
  5528. x1, x2, y1, y2, z1, z2,
  5529. s1, s2, t1, t2, r, t, test,
  5530. tan1 = [], tan2 = [],
  5531. sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
  5532. tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
  5533. n = new THREE.Vector3(), w;
  5534. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5535. tan1[ v ] = new THREE.Vector3();
  5536. tan2[ v ] = new THREE.Vector3();
  5537. }
  5538. function handleTriangle( context, a, b, c, ua, ub, uc ) {
  5539. vA = context.vertices[ a ];
  5540. vB = context.vertices[ b ];
  5541. vC = context.vertices[ c ];
  5542. uvA = uv[ ua ];
  5543. uvB = uv[ ub ];
  5544. uvC = uv[ uc ];
  5545. x1 = vB.x - vA.x;
  5546. x2 = vC.x - vA.x;
  5547. y1 = vB.y - vA.y;
  5548. y2 = vC.y - vA.y;
  5549. z1 = vB.z - vA.z;
  5550. z2 = vC.z - vA.z;
  5551. s1 = uvB.x - uvA.x;
  5552. s2 = uvC.x - uvA.x;
  5553. t1 = uvB.y - uvA.y;
  5554. t2 = uvC.y - uvA.y;
  5555. r = 1.0 / ( s1 * t2 - s2 * t1 );
  5556. sdir.set( ( t2 * x1 - t1 * x2 ) * r,
  5557. ( t2 * y1 - t1 * y2 ) * r,
  5558. ( t2 * z1 - t1 * z2 ) * r );
  5559. tdir.set( ( s1 * x2 - s2 * x1 ) * r,
  5560. ( s1 * y2 - s2 * y1 ) * r,
  5561. ( s1 * z2 - s2 * z1 ) * r );
  5562. tan1[ a ].add( sdir );
  5563. tan1[ b ].add( sdir );
  5564. tan1[ c ].add( sdir );
  5565. tan2[ a ].add( tdir );
  5566. tan2[ b ].add( tdir );
  5567. tan2[ c ].add( tdir );
  5568. }
  5569. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5570. face = this.faces[ f ];
  5571. uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
  5572. handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
  5573. }
  5574. var faceIndex = [ 'a', 'b', 'c', 'd' ];
  5575. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5576. face = this.faces[ f ];
  5577. for ( i = 0; i < Math.min( face.vertexNormals.length, 3 ); i ++ ) {
  5578. n.copy( face.vertexNormals[ i ] );
  5579. vertexIndex = face[ faceIndex[ i ] ];
  5580. t = tan1[ vertexIndex ];
  5581. // Gram-Schmidt orthogonalize
  5582. tmp.copy( t );
  5583. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  5584. // Calculate handedness
  5585. tmp2.crossVectors( face.vertexNormals[ i ], t );
  5586. test = tmp2.dot( tan2[ vertexIndex ] );
  5587. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  5588. face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
  5589. }
  5590. }
  5591. this.hasTangents = true;
  5592. },
  5593. computeLineDistances: function () {
  5594. var d = 0;
  5595. var vertices = this.vertices;
  5596. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5597. if ( i > 0 ) {
  5598. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5599. }
  5600. this.lineDistances[ i ] = d;
  5601. }
  5602. },
  5603. computeBoundingBox: function () {
  5604. if ( this.boundingBox === null ) {
  5605. this.boundingBox = new THREE.Box3();
  5606. }
  5607. this.boundingBox.setFromPoints( this.vertices );
  5608. },
  5609. computeBoundingSphere: function () {
  5610. if ( this.boundingSphere === null ) {
  5611. this.boundingSphere = new THREE.Sphere();
  5612. }
  5613. this.boundingSphere.setFromPoints( this.vertices );
  5614. },
  5615. merge: function ( geometry, matrix ) {
  5616. if ( geometry instanceof THREE.Geometry === false ) {
  5617. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5618. return;
  5619. }
  5620. var normalMatrix,
  5621. vertexOffset = this.vertices.length,
  5622. vertices1 = this.vertices,
  5623. vertices2 = geometry.vertices,
  5624. faces1 = this.faces,
  5625. faces2 = geometry.faces,
  5626. uvs1 = this.faceVertexUvs[ 0 ],
  5627. uvs2 = geometry.faceVertexUvs[ 0 ];
  5628. if ( matrix !== undefined ) {
  5629. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5630. }
  5631. // vertices
  5632. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5633. var vertex = vertices2[ i ];
  5634. var vertexCopy = vertex.clone();
  5635. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5636. vertices1.push( vertexCopy );
  5637. }
  5638. // faces
  5639. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5640. var face = faces2[ i ], faceCopy, normal, color,
  5641. faceVertexNormals = face.vertexNormals,
  5642. faceVertexColors = face.vertexColors;
  5643. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5644. faceCopy.normal.copy( face.normal );
  5645. if ( normalMatrix !== undefined ) {
  5646. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5647. }
  5648. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5649. normal = faceVertexNormals[ j ].clone();
  5650. if ( normalMatrix !== undefined ) {
  5651. normal.applyMatrix3( normalMatrix ).normalize();
  5652. }
  5653. faceCopy.vertexNormals.push( normal );
  5654. }
  5655. faceCopy.color.copy( face.color );
  5656. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5657. color = faceVertexColors[ j ];
  5658. faceCopy.vertexColors.push( color.clone() );
  5659. }
  5660. faces1.push( faceCopy );
  5661. }
  5662. // uvs
  5663. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5664. var uv = uvs2[ i ], uvCopy = [];
  5665. if ( uv === undefined ) {
  5666. continue;
  5667. }
  5668. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5669. uvCopy.push( uv[ j ].clone() );
  5670. }
  5671. uvs1.push( uvCopy );
  5672. }
  5673. },
  5674. mergeMesh: function ( mesh ) {
  5675. if ( mesh instanceof THREE.Mesh === false ) {
  5676. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5677. return;
  5678. }
  5679. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5680. this.merge( mesh.geometry, mesh.matrix );
  5681. },
  5682. /*
  5683. * Checks for duplicate vertices with hashmap.
  5684. * Duplicated vertices are removed
  5685. * and faces' vertices are updated.
  5686. */
  5687. mergeVertices: function () {
  5688. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5689. var unique = [], changes = [];
  5690. var v, key;
  5691. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5692. var precision = Math.pow( 10, precisionPoints );
  5693. var i, il, face;
  5694. var indices, j, jl;
  5695. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5696. v = this.vertices[ i ];
  5697. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5698. if ( verticesMap[ key ] === undefined ) {
  5699. verticesMap[ key ] = i;
  5700. unique.push( this.vertices[ i ] );
  5701. changes[ i ] = unique.length - 1;
  5702. } else {
  5703. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5704. changes[ i ] = changes[ verticesMap[ key ] ];
  5705. }
  5706. }
  5707. // if faces are completely degenerate after merging vertices, we
  5708. // have to remove them from the geometry.
  5709. var faceIndicesToRemove = [];
  5710. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5711. face = this.faces[ i ];
  5712. face.a = changes[ face.a ];
  5713. face.b = changes[ face.b ];
  5714. face.c = changes[ face.c ];
  5715. indices = [ face.a, face.b, face.c ];
  5716. var dupIndex = - 1;
  5717. // if any duplicate vertices are found in a Face3
  5718. // we have to remove the face as nothing can be saved
  5719. for ( var n = 0; n < 3; n ++ ) {
  5720. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5721. dupIndex = n;
  5722. faceIndicesToRemove.push( i );
  5723. break;
  5724. }
  5725. }
  5726. }
  5727. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5728. var idx = faceIndicesToRemove[ i ];
  5729. this.faces.splice( idx, 1 );
  5730. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5731. this.faceVertexUvs[ j ].splice( idx, 1 );
  5732. }
  5733. }
  5734. // Use unique set of vertices
  5735. var diff = this.vertices.length - unique.length;
  5736. this.vertices = unique;
  5737. return diff;
  5738. },
  5739. toJSON: function () {
  5740. var data = {
  5741. metadata: {
  5742. version: 4.4,
  5743. type: 'Geometry',
  5744. generator: 'Geometry.toJSON'
  5745. }
  5746. };
  5747. // standard Geometry serialization
  5748. data.uuid = this.uuid;
  5749. data.type = this.type;
  5750. if ( this.name !== '' ) data.name = this.name;
  5751. if ( this.parameters !== undefined ) {
  5752. var parameters = this.parameters;
  5753. for ( var key in parameters ) {
  5754. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5755. }
  5756. return data;
  5757. }
  5758. var vertices = [];
  5759. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5760. var vertex = this.vertices[ i ];
  5761. vertices.push( vertex.x, vertex.y, vertex.z );
  5762. }
  5763. var faces = [];
  5764. var normals = [];
  5765. var normalsHash = {};
  5766. var colors = [];
  5767. var colorsHash = {};
  5768. var uvs = [];
  5769. var uvsHash = {};
  5770. for ( var i = 0; i < this.faces.length; i ++ ) {
  5771. var face = this.faces[ i ];
  5772. var hasMaterial = false; // face.materialIndex !== undefined;
  5773. var hasFaceUv = false; // deprecated
  5774. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5775. var hasFaceNormal = face.normal.length() > 0;
  5776. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5777. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5778. var hasFaceVertexColor = face.vertexColors.length > 0;
  5779. var faceType = 0;
  5780. faceType = setBit( faceType, 0, 0 );
  5781. faceType = setBit( faceType, 1, hasMaterial );
  5782. faceType = setBit( faceType, 2, hasFaceUv );
  5783. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5784. faceType = setBit( faceType, 4, hasFaceNormal );
  5785. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5786. faceType = setBit( faceType, 6, hasFaceColor );
  5787. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5788. faces.push( faceType );
  5789. faces.push( face.a, face.b, face.c );
  5790. if ( hasFaceVertexUv ) {
  5791. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5792. faces.push(
  5793. getUvIndex( faceVertexUvs[ 0 ] ),
  5794. getUvIndex( faceVertexUvs[ 1 ] ),
  5795. getUvIndex( faceVertexUvs[ 2 ] )
  5796. );
  5797. }
  5798. if ( hasFaceNormal ) {
  5799. faces.push( getNormalIndex( face.normal ) );
  5800. }
  5801. if ( hasFaceVertexNormal ) {
  5802. var vertexNormals = face.vertexNormals;
  5803. faces.push(
  5804. getNormalIndex( vertexNormals[ 0 ] ),
  5805. getNormalIndex( vertexNormals[ 1 ] ),
  5806. getNormalIndex( vertexNormals[ 2 ] )
  5807. );
  5808. }
  5809. if ( hasFaceColor ) {
  5810. faces.push( getColorIndex( face.color ) );
  5811. }
  5812. if ( hasFaceVertexColor ) {
  5813. var vertexColors = face.vertexColors;
  5814. faces.push(
  5815. getColorIndex( vertexColors[ 0 ] ),
  5816. getColorIndex( vertexColors[ 1 ] ),
  5817. getColorIndex( vertexColors[ 2 ] )
  5818. );
  5819. }
  5820. }
  5821. function setBit( value, position, enabled ) {
  5822. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position) );
  5823. }
  5824. function getNormalIndex( normal ) {
  5825. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5826. if ( normalsHash[ hash ] !== undefined ) {
  5827. return normalsHash[ hash ];
  5828. }
  5829. normalsHash[ hash ] = normals.length / 3;
  5830. normals.push( normal.x, normal.y, normal.z );
  5831. return normalsHash[ hash ];
  5832. }
  5833. function getColorIndex( color ) {
  5834. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5835. if ( colorsHash[ hash ] !== undefined ) {
  5836. return colorsHash[ hash ];
  5837. }
  5838. colorsHash[ hash ] = colors.length;
  5839. colors.push( color.getHex() );
  5840. return colorsHash[ hash ];
  5841. }
  5842. function getUvIndex( uv ) {
  5843. var hash = uv.x.toString() + uv.y.toString();
  5844. if ( uvsHash[ hash ] !== undefined ) {
  5845. return uvsHash[ hash ];
  5846. }
  5847. uvsHash[ hash ] = uvs.length / 2;
  5848. uvs.push( uv.x, uv.y );
  5849. return uvsHash[ hash ];
  5850. }
  5851. data.data = {};
  5852. data.data.vertices = vertices;
  5853. data.data.normals = normals;
  5854. if ( colors.length > 0 ) data.data.colors = colors;
  5855. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  5856. data.data.faces = faces;
  5857. return data;
  5858. },
  5859. clone: function () {
  5860. var geometry = new THREE.Geometry();
  5861. var vertices = this.vertices;
  5862. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5863. geometry.vertices.push( vertices[ i ].clone() );
  5864. }
  5865. var faces = this.faces;
  5866. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  5867. geometry.faces.push( faces[ i ].clone() );
  5868. }
  5869. for ( var i = 0, il = this.faceVertexUvs.length; i < il; i ++ ) {
  5870. var faceVertexUvs = this.faceVertexUvs[ i ];
  5871. if ( geometry.faceVertexUvs[ i ] === undefined ) {
  5872. geometry.faceVertexUvs[ i ] = [];
  5873. }
  5874. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  5875. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  5876. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  5877. var uv = uvs[ k ];
  5878. uvsCopy.push( uv.clone() );
  5879. }
  5880. geometry.faceVertexUvs[ i ].push( uvsCopy );
  5881. }
  5882. }
  5883. return geometry;
  5884. },
  5885. dispose: function () {
  5886. this.dispatchEvent( { type: 'dispose' } );
  5887. },
  5888. // Backwards compatibility
  5889. set groupsNeedUpdate ( value ) {
  5890. if ( value === true ) this.dispose();
  5891. }
  5892. };
  5893. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  5894. THREE.GeometryIdCount = 0;
  5895. // File:src/core/DirectGeometry.js
  5896. /**
  5897. * @author mrdoob / http://mrdoob.com/
  5898. */
  5899. THREE.DirectGeometry = function () {
  5900. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5901. this.uuid = THREE.Math.generateUUID();
  5902. this.name = '';
  5903. this.type = 'DirectGeometry';
  5904. this.indices = [];
  5905. this.vertices = [];
  5906. this.colors = [];
  5907. this.normals = [];
  5908. this.colors = [];
  5909. this.uvs = [];
  5910. this.uvs2 = [];
  5911. this.tangents = [];
  5912. this.morphTargets = [];
  5913. this.morphColors = [];
  5914. this.morphNormals = [];
  5915. this.skinWeights = [];
  5916. this.skinIndices = [];
  5917. // this.lineDistances = [];
  5918. this.boundingBox = null;
  5919. this.boundingSphere = null;
  5920. // update flags
  5921. this.verticesNeedUpdate = false;
  5922. this.normalsNeedUpdate = false;
  5923. this.colorsNeedUpdate = false;
  5924. this.uvsNeedUpdate = false;
  5925. this.tangentsNeedUpdate = false;
  5926. };
  5927. THREE.DirectGeometry.prototype = {
  5928. constructor: THREE.DirectGeometry,
  5929. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  5930. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  5931. computeFaceNormals: function () {
  5932. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  5933. return this;
  5934. },
  5935. computeVertexNormals: function () {
  5936. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  5937. return this;
  5938. },
  5939. computeTangents: function () {
  5940. console.warn( 'THREE.DirectGeometry: computeTangents() is not a method of this type of geometry.' );
  5941. return this;
  5942. },
  5943. fromGeometry: function ( geometry ) {
  5944. var faces = geometry.faces;
  5945. var vertices = geometry.vertices;
  5946. var faceVertexUvs = geometry.faceVertexUvs;
  5947. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5948. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5949. var hasTangents = geometry.hasTangents;
  5950. // morphs
  5951. var morphTargets = geometry.morphTargets;
  5952. var morphTargetsLength = morphTargets.length;
  5953. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  5954. this.morphTargets[ i ] = [];
  5955. }
  5956. var morphNormals = geometry.morphNormals;
  5957. var morphNormalsLength = morphNormals.length;
  5958. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  5959. this.morphNormals[ i ] = [];
  5960. }
  5961. var morphColors = geometry.morphColors;
  5962. var morphColorsLength = morphColors.length;
  5963. for ( var i = 0; i < morphColorsLength; i ++ ) {
  5964. this.morphColors[ i ] = [];
  5965. }
  5966. // skins
  5967. var skinIndices = geometry.skinIndices;
  5968. var skinWeights = geometry.skinWeights;
  5969. var hasSkinIndices = skinIndices.length === vertices.length;
  5970. var hasSkinWeights = skinWeights.length === vertices.length;
  5971. //
  5972. for ( var i = 0; i < faces.length; i ++ ) {
  5973. var face = faces[ i ];
  5974. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5975. var vertexNormals = face.vertexNormals;
  5976. if ( vertexNormals.length === 3 ) {
  5977. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5978. } else {
  5979. var normal = face.normal;
  5980. this.normals.push( normal, normal, normal );
  5981. }
  5982. var vertexColors = face.vertexColors;
  5983. if ( vertexColors.length === 3 ) {
  5984. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5985. } else {
  5986. var color = face.color;
  5987. this.colors.push( color, color, color );
  5988. }
  5989. if ( hasFaceVertexUv === true ) {
  5990. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  5991. if ( vertexUvs !== undefined ) {
  5992. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5993. } else {
  5994. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5995. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  5996. }
  5997. }
  5998. if ( hasFaceVertexUv2 === true ) {
  5999. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6000. if ( vertexUvs !== undefined ) {
  6001. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6002. } else {
  6003. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6004. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6005. }
  6006. }
  6007. if ( hasTangents === true ) {
  6008. var vertexTangents = face.vertexTangents;
  6009. if ( vertexTangents.length === 3 ) {
  6010. this.tangents.push( vertexTangents[ 0 ], vertexTangents[ 1 ], vertexTangents[ 2 ] );
  6011. } else {
  6012. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined tangents ', i );
  6013. this.tangents.push( new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4() );
  6014. }
  6015. }
  6016. // morphs
  6017. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6018. var morphTarget = morphTargets[ j ].vertices;
  6019. this.morphTargets[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6020. }
  6021. /*
  6022. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6023. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6024. this.morphNormals[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6025. }
  6026. for ( var j = 0; j < morphColorsLength; j ++ ) {
  6027. var morphColor = morphColors[ j ].colors;
  6028. this.morphColors[ j ].push( morphColor[ face.a ], morphColor[ face.b ], morphColor[ face.c ] );
  6029. }
  6030. */
  6031. // skins
  6032. if ( hasSkinIndices ) {
  6033. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6034. }
  6035. if ( hasSkinWeights ) {
  6036. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6037. }
  6038. }
  6039. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6040. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6041. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6042. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6043. this.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  6044. return this;
  6045. },
  6046. dispose: function () {
  6047. this.dispatchEvent( { type: 'dispose' } );
  6048. }
  6049. };
  6050. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6051. // File:src/core/BufferGeometry.js
  6052. /**
  6053. * @author alteredq / http://alteredqualia.com/
  6054. * @author mrdoob / http://mrdoob.com/
  6055. */
  6056. THREE.BufferGeometry = function () {
  6057. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6058. this.uuid = THREE.Math.generateUUID();
  6059. this.name = '';
  6060. this.type = 'BufferGeometry';
  6061. this.attributes = {};
  6062. this.morphAttributes = [];
  6063. this.drawcalls = [];
  6064. this.boundingBox = null;
  6065. this.boundingSphere = null;
  6066. };
  6067. THREE.BufferGeometry.prototype = {
  6068. constructor: THREE.BufferGeometry,
  6069. addAttribute: function ( name, attribute ) {
  6070. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6071. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6072. this.attributes[ name ] = { array: arguments[ 1 ], itemSize: arguments[ 2 ] };
  6073. return;
  6074. }
  6075. this.attributes[ name ] = attribute;
  6076. },
  6077. getAttribute: function ( name ) {
  6078. return this.attributes[ name ];
  6079. },
  6080. get offsets() {
  6081. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .drawcalls.' );
  6082. return this.drawcalls;
  6083. },
  6084. addDrawCall: function ( start, count, indexOffset ) {
  6085. this.drawcalls.push( {
  6086. start: start,
  6087. count: count,
  6088. index: indexOffset !== undefined ? indexOffset : 0
  6089. } );
  6090. },
  6091. clearDrawCalls: function () {
  6092. this.drawcalls = [];
  6093. },
  6094. applyMatrix: function ( matrix ) {
  6095. var position = this.attributes.position;
  6096. if ( position !== undefined ) {
  6097. matrix.applyToVector3Array( position.array );
  6098. position.needsUpdate = true;
  6099. }
  6100. var normal = this.attributes.normal;
  6101. if ( normal !== undefined ) {
  6102. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6103. normalMatrix.applyToVector3Array( normal.array );
  6104. normal.needsUpdate = true;
  6105. }
  6106. if ( this.boundingBox !== null ) {
  6107. this.computeBoundingBox();
  6108. }
  6109. if ( this.boundingSphere !== null ) {
  6110. this.computeBoundingSphere();
  6111. }
  6112. },
  6113. copy: function ( geometry ) {
  6114. // TODO Clear attributes? Clear drawcalls? Copy morphTargets?
  6115. var attributes = geometry.attributes;
  6116. var offsets = geometry.drawcalls;
  6117. for ( var name in attributes ) {
  6118. var attribute = attributes[ name ];
  6119. this.addAttribute( name, attribute.clone() );
  6120. }
  6121. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  6122. var offset = offsets[ i ];
  6123. this.addDrawCall( offset.start, offset.count, offset.index );
  6124. }
  6125. return this;
  6126. },
  6127. center: function () {
  6128. this.computeBoundingBox();
  6129. var offset = this.boundingBox.center().negate();
  6130. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  6131. return offset;
  6132. },
  6133. setFromObject: function ( object ) {
  6134. console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6135. var geometry = object.geometry;
  6136. if ( object instanceof THREE.PointCloud || object instanceof THREE.Line ) {
  6137. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6138. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6139. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6140. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6141. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6142. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6143. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6144. }
  6145. if ( geometry.boundingSphere !== null ) {
  6146. this.boundingSphere = geometry.boundingSphere.clone();
  6147. }
  6148. if ( geometry.boundingBox !== null ) {
  6149. this.boundingBox = geometry.boundingBox.clone();
  6150. }
  6151. } else if ( object instanceof THREE.Mesh ) {
  6152. if ( geometry instanceof THREE.Geometry ) {
  6153. this.fromGeometry( geometry );
  6154. }
  6155. }
  6156. return this;
  6157. },
  6158. updateFromObject: function ( object ) {
  6159. var geometry = object.geometry;
  6160. if ( object instanceof THREE.Mesh ) {
  6161. var direct = geometry.__directGeometry;
  6162. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6163. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6164. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6165. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6166. direct.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  6167. geometry.verticesNeedUpdate = false;
  6168. geometry.normalsNeedUpdate = false;
  6169. geometry.colorsNeedUpdate = false;
  6170. geometry.uvsNeedUpdate = false;
  6171. geometry.tangentsNeedUpdate = false;
  6172. geometry = direct;
  6173. }
  6174. if ( geometry.verticesNeedUpdate === true ) {
  6175. var attribute = this.attributes.position;
  6176. if ( attribute !== undefined ) {
  6177. attribute.copyVector3sArray( geometry.vertices );
  6178. attribute.needsUpdate = true;
  6179. }
  6180. geometry.verticesNeedUpdate = false;
  6181. }
  6182. if ( geometry.normalsNeedUpdate === true ) {
  6183. var attribute = this.attributes.normal;
  6184. if ( attribute !== undefined ) {
  6185. attribute.copyVector3sArray( geometry.normals );
  6186. attribute.needsUpdate = true;
  6187. }
  6188. geometry.normalsNeedUpdate = false;
  6189. }
  6190. if ( geometry.colorsNeedUpdate === true ) {
  6191. var attribute = this.attributes.color;
  6192. if ( attribute !== undefined ) {
  6193. attribute.copyColorsArray( geometry.colors );
  6194. attribute.needsUpdate = true;
  6195. }
  6196. geometry.colorsNeedUpdate = false;
  6197. }
  6198. if ( geometry.tangentsNeedUpdate === true ) {
  6199. var attribute = this.attributes.tangent;
  6200. if ( attribute !== undefined ) {
  6201. attribute.copyVector4sArray( geometry.tangents );
  6202. attribute.needsUpdate = true;
  6203. }
  6204. geometry.tangentsNeedUpdate = false;
  6205. }
  6206. if ( geometry.lineDistancesNeedUpdate ) {
  6207. var attribute = this.attributes.lineDistance;
  6208. if ( attribute !== undefined ) {
  6209. attribute.copyArray( geometry.lineDistances );
  6210. attribute.needsUpdate = true;
  6211. }
  6212. geometry.lineDistancesNeedUpdate = false;
  6213. }
  6214. return this;
  6215. },
  6216. fromGeometry: function ( geometry ) {
  6217. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6218. return this.fromDirectGeometry( geometry.__directGeometry );
  6219. },
  6220. fromDirectGeometry: function ( geometry ) {
  6221. var positions = new Float32Array( geometry.vertices.length * 3 );
  6222. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6223. if ( geometry.normals.length > 0 ) {
  6224. var normals = new Float32Array( geometry.normals.length * 3 );
  6225. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6226. }
  6227. if ( geometry.colors.length > 0 ) {
  6228. var colors = new Float32Array( geometry.colors.length * 3 );
  6229. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6230. }
  6231. if ( geometry.uvs.length > 0 ) {
  6232. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6233. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6234. }
  6235. if ( geometry.uvs2.length > 0 ) {
  6236. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6237. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6238. }
  6239. if ( geometry.tangents.length > 0 ) {
  6240. var tangents = new Float32Array( geometry.tangents.length * 4 );
  6241. this.addAttribute( 'tangent', new THREE.BufferAttribute( tangents, 4 ).copyVector4sArray( geometry.tangents ) );
  6242. }
  6243. if ( geometry.indices.length > 0 ) {
  6244. var indices = new Uint16Array( geometry.indices.length * 3 );
  6245. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6246. }
  6247. // morphs
  6248. if ( geometry.morphTargets.length > 0 ) {
  6249. var morphTargets = geometry.morphTargets;
  6250. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6251. var morphTarget = morphTargets[ i ];
  6252. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6253. this.morphAttributes.push( attribute.copyVector3sArray( morphTarget ) );
  6254. }
  6255. // TODO normals, colors
  6256. }
  6257. // skinning
  6258. if ( geometry.skinIndices.length > 0 ) {
  6259. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6260. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6261. }
  6262. if ( geometry.skinWeights.length > 0 ) {
  6263. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6264. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6265. }
  6266. //
  6267. if ( geometry.boundingSphere !== null ) {
  6268. this.boundingSphere = geometry.boundingSphere.clone();
  6269. }
  6270. if ( geometry.boundingBox !== null ) {
  6271. this.boundingBox = geometry.boundingBox.clone();
  6272. }
  6273. return this;
  6274. },
  6275. computeBoundingBox: function () {
  6276. var vector = new THREE.Vector3();
  6277. return function () {
  6278. if ( this.boundingBox === null ) {
  6279. this.boundingBox = new THREE.Box3();
  6280. }
  6281. var positions = this.attributes.position.array;
  6282. if ( positions ) {
  6283. var bb = this.boundingBox;
  6284. bb.makeEmpty();
  6285. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6286. vector.fromArray( positions, i );
  6287. bb.expandByPoint( vector );
  6288. }
  6289. }
  6290. if ( positions === undefined || positions.length === 0 ) {
  6291. this.boundingBox.min.set( 0, 0, 0 );
  6292. this.boundingBox.max.set( 0, 0, 0 );
  6293. }
  6294. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6295. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6296. }
  6297. };
  6298. }(),
  6299. computeBoundingSphere: function () {
  6300. var box = new THREE.Box3();
  6301. var vector = new THREE.Vector3();
  6302. return function () {
  6303. if ( this.boundingSphere === null ) {
  6304. this.boundingSphere = new THREE.Sphere();
  6305. }
  6306. var positions = this.attributes.position.array;
  6307. if ( positions ) {
  6308. box.makeEmpty();
  6309. var center = this.boundingSphere.center;
  6310. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6311. vector.fromArray( positions, i );
  6312. box.expandByPoint( vector );
  6313. }
  6314. box.center( center );
  6315. // hoping to find a boundingSphere with a radius smaller than the
  6316. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6317. var maxRadiusSq = 0;
  6318. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6319. vector.fromArray( positions, i );
  6320. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6321. }
  6322. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6323. if ( isNaN( this.boundingSphere.radius ) ) {
  6324. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6325. }
  6326. }
  6327. };
  6328. }(),
  6329. computeFaceNormals: function () {
  6330. // backwards compatibility
  6331. },
  6332. computeVertexNormals: function () {
  6333. var attributes = this.attributes;
  6334. if ( attributes.position ) {
  6335. var positions = attributes.position.array;
  6336. if ( attributes.normal === undefined ) {
  6337. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6338. } else {
  6339. // reset existing normals to zero
  6340. var normals = attributes.normal.array;
  6341. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6342. normals[ i ] = 0;
  6343. }
  6344. }
  6345. var normals = attributes.normal.array;
  6346. var vA, vB, vC,
  6347. pA = new THREE.Vector3(),
  6348. pB = new THREE.Vector3(),
  6349. pC = new THREE.Vector3(),
  6350. cb = new THREE.Vector3(),
  6351. ab = new THREE.Vector3();
  6352. // indexed elements
  6353. if ( attributes.index ) {
  6354. var indices = attributes.index.array;
  6355. if ( this.drawcalls.length === 0 ) {
  6356. this.addDrawCall( 0, indices.length );
  6357. }
  6358. for ( var j = 0, jl = this.drawcalls.length; j < jl; ++ j ) {
  6359. var start = this.drawcalls[ j ].start;
  6360. var count = this.drawcalls[ j ].count;
  6361. var index = this.drawcalls[ j ].index;
  6362. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6363. vA = ( index + indices[ i ] ) * 3;
  6364. vB = ( index + indices[ i + 1 ] ) * 3;
  6365. vC = ( index + indices[ i + 2 ] ) * 3;
  6366. pA.fromArray( positions, vA );
  6367. pB.fromArray( positions, vB );
  6368. pC.fromArray( positions, vC );
  6369. cb.subVectors( pC, pB );
  6370. ab.subVectors( pA, pB );
  6371. cb.cross( ab );
  6372. normals[ vA ] += cb.x;
  6373. normals[ vA + 1 ] += cb.y;
  6374. normals[ vA + 2 ] += cb.z;
  6375. normals[ vB ] += cb.x;
  6376. normals[ vB + 1 ] += cb.y;
  6377. normals[ vB + 2 ] += cb.z;
  6378. normals[ vC ] += cb.x;
  6379. normals[ vC + 1 ] += cb.y;
  6380. normals[ vC + 2 ] += cb.z;
  6381. }
  6382. }
  6383. } else {
  6384. // non-indexed elements (unconnected triangle soup)
  6385. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6386. pA.fromArray( positions, i );
  6387. pB.fromArray( positions, i + 3 );
  6388. pC.fromArray( positions, i + 6 );
  6389. cb.subVectors( pC, pB );
  6390. ab.subVectors( pA, pB );
  6391. cb.cross( ab );
  6392. normals[ i ] = cb.x;
  6393. normals[ i + 1 ] = cb.y;
  6394. normals[ i + 2 ] = cb.z;
  6395. normals[ i + 3 ] = cb.x;
  6396. normals[ i + 4 ] = cb.y;
  6397. normals[ i + 5 ] = cb.z;
  6398. normals[ i + 6 ] = cb.x;
  6399. normals[ i + 7 ] = cb.y;
  6400. normals[ i + 8 ] = cb.z;
  6401. }
  6402. }
  6403. this.normalizeNormals();
  6404. attributes.normal.needsUpdate = true;
  6405. }
  6406. },
  6407. computeTangents: function () {
  6408. // based on http://www.terathon.com/code/tangent.html
  6409. // (per vertex tangents)
  6410. if ( this.attributes.index === undefined ||
  6411. this.attributes.position === undefined ||
  6412. this.attributes.normal === undefined ||
  6413. this.attributes.uv === undefined ) {
  6414. console.warn( 'THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()' );
  6415. return;
  6416. }
  6417. var indices = this.attributes.index.array;
  6418. var positions = this.attributes.position.array;
  6419. var normals = this.attributes.normal.array;
  6420. var uvs = this.attributes.uv.array;
  6421. var nVertices = positions.length / 3;
  6422. if ( this.attributes.tangent === undefined ) {
  6423. this.addAttribute( 'tangent', new THREE.BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
  6424. }
  6425. var tangents = this.attributes.tangent.array;
  6426. var tan1 = [], tan2 = [];
  6427. for ( var k = 0; k < nVertices; k ++ ) {
  6428. tan1[ k ] = new THREE.Vector3();
  6429. tan2[ k ] = new THREE.Vector3();
  6430. }
  6431. var vA = new THREE.Vector3(),
  6432. vB = new THREE.Vector3(),
  6433. vC = new THREE.Vector3(),
  6434. uvA = new THREE.Vector2(),
  6435. uvB = new THREE.Vector2(),
  6436. uvC = new THREE.Vector2(),
  6437. x1, x2, y1, y2, z1, z2,
  6438. s1, s2, t1, t2, r;
  6439. var sdir = new THREE.Vector3(), tdir = new THREE.Vector3();
  6440. function handleTriangle( a, b, c ) {
  6441. vA.fromArray( positions, a * 3 );
  6442. vB.fromArray( positions, b * 3 );
  6443. vC.fromArray( positions, c * 3 );
  6444. uvA.fromArray( uvs, a * 2 );
  6445. uvB.fromArray( uvs, b * 2 );
  6446. uvC.fromArray( uvs, c * 2 );
  6447. x1 = vB.x - vA.x;
  6448. x2 = vC.x - vA.x;
  6449. y1 = vB.y - vA.y;
  6450. y2 = vC.y - vA.y;
  6451. z1 = vB.z - vA.z;
  6452. z2 = vC.z - vA.z;
  6453. s1 = uvB.x - uvA.x;
  6454. s2 = uvC.x - uvA.x;
  6455. t1 = uvB.y - uvA.y;
  6456. t2 = uvC.y - uvA.y;
  6457. r = 1.0 / ( s1 * t2 - s2 * t1 );
  6458. sdir.set(
  6459. ( t2 * x1 - t1 * x2 ) * r,
  6460. ( t2 * y1 - t1 * y2 ) * r,
  6461. ( t2 * z1 - t1 * z2 ) * r
  6462. );
  6463. tdir.set(
  6464. ( s1 * x2 - s2 * x1 ) * r,
  6465. ( s1 * y2 - s2 * y1 ) * r,
  6466. ( s1 * z2 - s2 * z1 ) * r
  6467. );
  6468. tan1[ a ].add( sdir );
  6469. tan1[ b ].add( sdir );
  6470. tan1[ c ].add( sdir );
  6471. tan2[ a ].add( tdir );
  6472. tan2[ b ].add( tdir );
  6473. tan2[ c ].add( tdir );
  6474. }
  6475. var i, il;
  6476. var j, jl;
  6477. var iA, iB, iC;
  6478. if ( this.drawcalls.length === 0 ) {
  6479. this.addDrawCall( 0, indices.length );
  6480. }
  6481. var drawcalls = this.drawcalls;
  6482. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6483. var start = drawcalls[ j ].start;
  6484. var count = drawcalls[ j ].count;
  6485. var index = drawcalls[ j ].index;
  6486. for ( i = start, il = start + count; i < il; i += 3 ) {
  6487. iA = index + indices[ i ];
  6488. iB = index + indices[ i + 1 ];
  6489. iC = index + indices[ i + 2 ];
  6490. handleTriangle( iA, iB, iC );
  6491. }
  6492. }
  6493. var tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3();
  6494. var n = new THREE.Vector3(), n2 = new THREE.Vector3();
  6495. var w, t, test;
  6496. function handleVertex( v ) {
  6497. n.fromArray( normals, v * 3 );
  6498. n2.copy( n );
  6499. t = tan1[ v ];
  6500. // Gram-Schmidt orthogonalize
  6501. tmp.copy( t );
  6502. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6503. // Calculate handedness
  6504. tmp2.crossVectors( n2, t );
  6505. test = tmp2.dot( tan2[ v ] );
  6506. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6507. tangents[ v * 4 ] = tmp.x;
  6508. tangents[ v * 4 + 1 ] = tmp.y;
  6509. tangents[ v * 4 + 2 ] = tmp.z;
  6510. tangents[ v * 4 + 3 ] = w;
  6511. }
  6512. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6513. var start = drawcalls[ j ].start;
  6514. var count = drawcalls[ j ].count;
  6515. var index = drawcalls[ j ].index;
  6516. for ( i = start, il = start + count; i < il; i += 3 ) {
  6517. iA = index + indices[ i ];
  6518. iB = index + indices[ i + 1 ];
  6519. iC = index + indices[ i + 2 ];
  6520. handleVertex( iA );
  6521. handleVertex( iB );
  6522. handleVertex( iC );
  6523. }
  6524. }
  6525. },
  6526. /*
  6527. Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices.
  6528. This method will effectively rewrite the index buffer and remap all attributes to match the new indices.
  6529. WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets.
  6530. size - Defaults to 65535 or 4294967296 if extension OES_element_index_uint supported, but allows for larger or smaller chunks.
  6531. */
  6532. computeOffsets: function ( size ) {
  6533. if ( size === undefined ) size = THREE.BufferGeometry.MaxIndex;
  6534. var indices = this.attributes.index.array;
  6535. var vertices = this.attributes.position.array;
  6536. var facesCount = ( indices.length / 3 );
  6537. var UintArray = ( ( vertices.length / 3 ) > 65535 && THREE.BufferGeometry.MaxIndex > 65535 ) ? Uint32Array : Uint16Array;
  6538. /*
  6539. console.log("Computing buffers in offsets of "+size+" -> indices:"+indices.length+" vertices:"+vertices.length);
  6540. console.log("Faces to process: "+(indices.length/3));
  6541. console.log("Reordering "+verticesCount+" vertices.");
  6542. */
  6543. var sortedIndices = new UintArray( indices.length );
  6544. var indexPtr = 0;
  6545. var vertexPtr = 0;
  6546. var tmpOffsets = [ { start:0, count:0, index:0 } ];
  6547. var offset = tmpOffsets[ 0 ];
  6548. var duplicatedVertices = 0;
  6549. var newVerticeMaps = 0;
  6550. var faceVertices = new Int32Array( 6 );
  6551. var vertexMap = new Int32Array( vertices.length );
  6552. var revVertexMap = new Int32Array( vertices.length );
  6553. for ( var j = 0; j < vertices.length; j ++ ) { vertexMap[ j ] = - 1; revVertexMap[ j ] = - 1; }
  6554. /*
  6555. Traverse every face and reorder vertices in the proper offsets of 65k.
  6556. We can have more than 'size' entries in the index buffer per offset, but only reference 'size' values.
  6557. */
  6558. for ( var findex = 0; findex < facesCount; findex ++ ) {
  6559. newVerticeMaps = 0;
  6560. for ( var vo = 0; vo < 3; vo ++ ) {
  6561. var vid = indices[ findex * 3 + vo ];
  6562. if ( vertexMap[ vid ] === - 1 ) {
  6563. //Unmapped vertex
  6564. faceVertices[ vo * 2 ] = vid;
  6565. faceVertices[ vo * 2 + 1 ] = - 1;
  6566. newVerticeMaps ++;
  6567. } else if ( vertexMap[ vid ] < offset.index ) {
  6568. //Reused vertices from previous block (duplicate)
  6569. faceVertices[ vo * 2 ] = vid;
  6570. faceVertices[ vo * 2 + 1 ] = - 1;
  6571. duplicatedVertices ++;
  6572. } else {
  6573. //Reused vertex in the current block
  6574. faceVertices[ vo * 2 ] = vid;
  6575. faceVertices[ vo * 2 + 1 ] = vertexMap[ vid ];
  6576. }
  6577. }
  6578. var faceMax = vertexPtr + newVerticeMaps;
  6579. if ( faceMax > ( offset.index + size ) ) {
  6580. var new_offset = { start:indexPtr, count:0, index:vertexPtr };
  6581. tmpOffsets.push( new_offset );
  6582. offset = new_offset;
  6583. //Re-evaluate reused vertices in light of new offset.
  6584. for ( var v = 0; v < 6; v += 2 ) {
  6585. var new_vid = faceVertices[ v + 1 ];
  6586. if ( new_vid > - 1 && new_vid < offset.index )
  6587. faceVertices[ v + 1 ] = - 1;
  6588. }
  6589. }
  6590. //Reindex the face.
  6591. for ( var v = 0; v < 6; v += 2 ) {
  6592. var vid = faceVertices[ v ];
  6593. var new_vid = faceVertices[ v + 1 ];
  6594. if ( new_vid === - 1 )
  6595. new_vid = vertexPtr ++;
  6596. vertexMap[ vid ] = new_vid;
  6597. revVertexMap[ new_vid ] = vid;
  6598. sortedIndices[ indexPtr ++ ] = new_vid - offset.index; //XXX overflows at 16bit
  6599. offset.count ++;
  6600. }
  6601. }
  6602. /* Move all attribute values to map to the new computed indices , also expand the vertex stack to match our new vertexPtr. */
  6603. this.reorderBuffers( sortedIndices, revVertexMap, vertexPtr );
  6604. this.clearDrawCalls();
  6605. for ( var i = 0; i < tmpOffsets.length; i ++ ) {
  6606. var tmpOffset = tmpOffsets[ i ];
  6607. this.addDrawCall( tmpOffset.start, tmpOffset.count, tmpOffset.index );
  6608. }
  6609. /*
  6610. var orderTime = Date.now();
  6611. console.log("Reorder time: "+(orderTime-s)+"ms");
  6612. console.log("Duplicated "+duplicatedVertices+" vertices.");
  6613. console.log("Compute Buffers time: "+(Date.now()-s)+"ms");
  6614. console.log("Draw tmpOffsets: "+tmpOffsets.length);
  6615. */
  6616. },
  6617. merge: function ( geometry, offset ) {
  6618. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6619. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6620. return;
  6621. }
  6622. if ( offset === undefined ) offset = 0;
  6623. var attributes = this.attributes;
  6624. for ( var key in attributes ) {
  6625. if ( geometry.attributes[ key ] === undefined ) continue;
  6626. var attribute1 = attributes[ key ];
  6627. var attributeArray1 = attribute1.array;
  6628. var attribute2 = geometry.attributes[ key ];
  6629. var attributeArray2 = attribute2.array;
  6630. var attributeSize = attribute2.itemSize;
  6631. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6632. attributeArray1[ j ] = attributeArray2[ i ];
  6633. }
  6634. }
  6635. return this;
  6636. },
  6637. normalizeNormals: function () {
  6638. var normals = this.attributes.normal.array;
  6639. var x, y, z, n;
  6640. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6641. x = normals[ i ];
  6642. y = normals[ i + 1 ];
  6643. z = normals[ i + 2 ];
  6644. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6645. normals[ i ] *= n;
  6646. normals[ i + 1 ] *= n;
  6647. normals[ i + 2 ] *= n;
  6648. }
  6649. },
  6650. /*
  6651. reoderBuffers:
  6652. Reorder attributes based on a new indexBuffer and indexMap.
  6653. indexBuffer - Uint16Array of the new ordered indices.
  6654. indexMap - Int32Array where the position is the new vertex ID and the value the old vertex ID for each vertex.
  6655. vertexCount - Amount of total vertices considered in this reordering (in case you want to grow the vertex stack).
  6656. */
  6657. reorderBuffers: function ( indexBuffer, indexMap, vertexCount ) {
  6658. /* Create a copy of all attributes for reordering. */
  6659. var sortedAttributes = {};
  6660. for ( var attr in this.attributes ) {
  6661. if ( attr === 'index' )
  6662. continue;
  6663. var sourceArray = this.attributes[ attr ].array;
  6664. sortedAttributes[ attr ] = new sourceArray.constructor( this.attributes[ attr ].itemSize * vertexCount );
  6665. }
  6666. /* Move attribute positions based on the new index map */
  6667. for ( var new_vid = 0; new_vid < vertexCount; new_vid ++ ) {
  6668. var vid = indexMap[ new_vid ];
  6669. for ( var attr in this.attributes ) {
  6670. if ( attr === 'index' )
  6671. continue;
  6672. var attrArray = this.attributes[ attr ].array;
  6673. var attrSize = this.attributes[ attr ].itemSize;
  6674. var sortedAttr = sortedAttributes[ attr ];
  6675. for ( var k = 0; k < attrSize; k ++ )
  6676. sortedAttr[ new_vid * attrSize + k ] = attrArray[ vid * attrSize + k ];
  6677. }
  6678. }
  6679. /* Carry the new sorted buffers locally */
  6680. this.attributes[ 'index' ].array = indexBuffer;
  6681. for ( var attr in this.attributes ) {
  6682. if ( attr === 'index' )
  6683. continue;
  6684. this.attributes[ attr ].array = sortedAttributes[ attr ];
  6685. this.attributes[ attr ].numItems = this.attributes[ attr ].itemSize * vertexCount;
  6686. }
  6687. },
  6688. toJSON: function () {
  6689. var data = {
  6690. metadata: {
  6691. version: 4.4,
  6692. type: 'BufferGeometry',
  6693. generator: 'BufferGeometry.toJSON'
  6694. }
  6695. };
  6696. // standard BufferGeometry serialization
  6697. data.uuid = this.uuid;
  6698. data.type = this.type;
  6699. if ( this.name !== '' ) data.name = this.name;
  6700. if ( this.parameters !== undefined ) {
  6701. var parameters = this.parameters;
  6702. for ( var key in parameters ) {
  6703. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6704. }
  6705. return data;
  6706. }
  6707. data.data = { attributes: {} };
  6708. var attributes = this.attributes;
  6709. var offsets = this.drawcalls;
  6710. var boundingSphere = this.boundingSphere;
  6711. for ( var key in attributes ) {
  6712. var attribute = attributes[ key ];
  6713. var array = Array.prototype.slice.call( attribute.array );
  6714. data.data.attributes[ key ] = {
  6715. itemSize: attribute.itemSize,
  6716. type: attribute.array.constructor.name,
  6717. array: array
  6718. };
  6719. }
  6720. if ( offsets.length > 0 ) {
  6721. data.data.offsets = JSON.parse( JSON.stringify( offsets ) );
  6722. }
  6723. if ( boundingSphere !== null ) {
  6724. data.data.boundingSphere = {
  6725. center: boundingSphere.center.toArray(),
  6726. radius: boundingSphere.radius
  6727. };
  6728. }
  6729. return data;
  6730. },
  6731. clone: function () {
  6732. var geometry = new THREE.BufferGeometry();
  6733. for ( var attr in this.attributes ) {
  6734. var sourceAttr = this.attributes[ attr ];
  6735. geometry.addAttribute( attr, sourceAttr.clone() );
  6736. }
  6737. for ( var i = 0, il = this.drawcalls.length; i < il; i ++ ) {
  6738. var offset = this.drawcalls[ i ];
  6739. geometry.addDrawCall( offset.start, offset.count, offset.index );
  6740. }
  6741. return geometry;
  6742. },
  6743. dispose: function () {
  6744. this.dispatchEvent( { type: 'dispose' } );
  6745. }
  6746. };
  6747. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6748. THREE.BufferGeometry.MaxIndex = 65535;
  6749. // File:src/core/InstancedBufferGeometry.js
  6750. /**
  6751. * @author benaadams / https://twitter.com/ben_a_adams
  6752. */
  6753. THREE.InstancedBufferGeometry = function () {
  6754. THREE.BufferGeometry.call( this );
  6755. this.type = 'InstancedBufferGeometry';
  6756. this.maxInstancedCount = undefined;
  6757. };
  6758. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6759. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6760. THREE.InstancedBufferGeometry.prototype.addDrawCall = function ( start, count, indexOffset, instances ) {
  6761. this.drawcalls.push( {
  6762. start: start,
  6763. count: count,
  6764. index: indexOffset !== undefined ? indexOffset : 0,
  6765. instances: instances
  6766. } );
  6767. },
  6768. THREE.InstancedBufferGeometry.prototype.clone = function () {
  6769. var geometry = new THREE.InstancedBufferGeometry();
  6770. for ( var attr in this.attributes ) {
  6771. var sourceAttr = this.attributes[attr];
  6772. geometry.addAttribute( attr, sourceAttr.clone() );
  6773. }
  6774. for ( var i = 0, il = this.drawcalls.length; i < il; i++ ) {
  6775. var offset = this.drawcalls[i];
  6776. geometry.addDrawCall( offset.start, offset.count, offset.index, offset.instances );
  6777. }
  6778. return geometry;
  6779. };
  6780. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6781. // File:src/cameras/Camera.js
  6782. /**
  6783. * @author mrdoob / http://mrdoob.com/
  6784. * @author mikael emtinger / http://gomo.se/
  6785. * @author WestLangley / http://github.com/WestLangley
  6786. */
  6787. THREE.Camera = function () {
  6788. THREE.Object3D.call( this );
  6789. this.type = 'Camera';
  6790. this.matrixWorldInverse = new THREE.Matrix4();
  6791. this.projectionMatrix = new THREE.Matrix4();
  6792. };
  6793. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  6794. THREE.Camera.prototype.constructor = THREE.Camera;
  6795. THREE.Camera.prototype.getWorldDirection = function () {
  6796. var quaternion = new THREE.Quaternion();
  6797. return function ( optionalTarget ) {
  6798. var result = optionalTarget || new THREE.Vector3();
  6799. this.getWorldQuaternion( quaternion );
  6800. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  6801. };
  6802. }();
  6803. THREE.Camera.prototype.lookAt = function () {
  6804. // This routine does not support cameras with rotated and/or translated parent(s)
  6805. var m1 = new THREE.Matrix4();
  6806. return function ( vector ) {
  6807. m1.lookAt( this.position, vector, this.up );
  6808. this.quaternion.setFromRotationMatrix( m1 );
  6809. };
  6810. }();
  6811. THREE.Camera.prototype.clone = function ( camera ) {
  6812. if ( camera === undefined ) camera = new THREE.Camera();
  6813. THREE.Object3D.prototype.clone.call( this, camera );
  6814. camera.matrixWorldInverse.copy( this.matrixWorldInverse );
  6815. camera.projectionMatrix.copy( this.projectionMatrix );
  6816. return camera;
  6817. };
  6818. // File:src/cameras/CubeCamera.js
  6819. /**
  6820. * Camera for rendering cube maps
  6821. * - renders scene into axis-aligned cube
  6822. *
  6823. * @author alteredq / http://alteredqualia.com/
  6824. */
  6825. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  6826. THREE.Object3D.call( this );
  6827. this.type = 'CubeCamera';
  6828. var fov = 90, aspect = 1;
  6829. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6830. cameraPX.up.set( 0, - 1, 0 );
  6831. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  6832. this.add( cameraPX );
  6833. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6834. cameraNX.up.set( 0, - 1, 0 );
  6835. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  6836. this.add( cameraNX );
  6837. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6838. cameraPY.up.set( 0, 0, 1 );
  6839. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  6840. this.add( cameraPY );
  6841. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6842. cameraNY.up.set( 0, 0, - 1 );
  6843. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  6844. this.add( cameraNY );
  6845. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6846. cameraPZ.up.set( 0, - 1, 0 );
  6847. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  6848. this.add( cameraPZ );
  6849. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6850. cameraNZ.up.set( 0, - 1, 0 );
  6851. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  6852. this.add( cameraNZ );
  6853. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  6854. this.updateCubeMap = function ( renderer, scene ) {
  6855. if ( this.parent === undefined ) this.updateMatrixWorld();
  6856. var renderTarget = this.renderTarget;
  6857. var generateMipmaps = renderTarget.generateMipmaps;
  6858. renderTarget.generateMipmaps = false;
  6859. renderTarget.activeCubeFace = 0;
  6860. renderer.render( scene, cameraPX, renderTarget );
  6861. renderTarget.activeCubeFace = 1;
  6862. renderer.render( scene, cameraNX, renderTarget );
  6863. renderTarget.activeCubeFace = 2;
  6864. renderer.render( scene, cameraPY, renderTarget );
  6865. renderTarget.activeCubeFace = 3;
  6866. renderer.render( scene, cameraNY, renderTarget );
  6867. renderTarget.activeCubeFace = 4;
  6868. renderer.render( scene, cameraPZ, renderTarget );
  6869. renderTarget.generateMipmaps = generateMipmaps;
  6870. renderTarget.activeCubeFace = 5;
  6871. renderer.render( scene, cameraNZ, renderTarget );
  6872. renderer.setRenderTarget( null );
  6873. };
  6874. };
  6875. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  6876. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  6877. // File:src/cameras/OrthographicCamera.js
  6878. /**
  6879. * @author alteredq / http://alteredqualia.com/
  6880. */
  6881. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  6882. THREE.Camera.call( this );
  6883. this.type = 'OrthographicCamera';
  6884. this.zoom = 1;
  6885. this.left = left;
  6886. this.right = right;
  6887. this.top = top;
  6888. this.bottom = bottom;
  6889. this.near = ( near !== undefined ) ? near : 0.1;
  6890. this.far = ( far !== undefined ) ? far : 2000;
  6891. this.updateProjectionMatrix();
  6892. };
  6893. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  6894. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  6895. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  6896. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  6897. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  6898. var cx = ( this.right + this.left ) / 2;
  6899. var cy = ( this.top + this.bottom ) / 2;
  6900. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  6901. };
  6902. THREE.OrthographicCamera.prototype.clone = function () {
  6903. var camera = new THREE.OrthographicCamera();
  6904. THREE.Camera.prototype.clone.call( this, camera );
  6905. camera.zoom = this.zoom;
  6906. camera.left = this.left;
  6907. camera.right = this.right;
  6908. camera.top = this.top;
  6909. camera.bottom = this.bottom;
  6910. camera.near = this.near;
  6911. camera.far = this.far;
  6912. return camera;
  6913. };
  6914. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  6915. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  6916. data.object.zoom = this.zoom;
  6917. data.object.left = this.left;
  6918. data.object.right = this.right;
  6919. data.object.top = this.top;
  6920. data.object.bottom = this.bottom;
  6921. data.object.near = this.near;
  6922. data.object.far = this.far;
  6923. return data;
  6924. };
  6925. // File:src/cameras/PerspectiveCamera.js
  6926. /**
  6927. * @author mrdoob / http://mrdoob.com/
  6928. * @author greggman / http://games.greggman.com/
  6929. * @author zz85 / http://www.lab4games.net/zz85/blog
  6930. */
  6931. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  6932. THREE.Camera.call( this );
  6933. this.type = 'PerspectiveCamera';
  6934. this.zoom = 1;
  6935. this.fov = fov !== undefined ? fov : 50;
  6936. this.aspect = aspect !== undefined ? aspect : 1;
  6937. this.near = near !== undefined ? near : 0.1;
  6938. this.far = far !== undefined ? far : 2000;
  6939. this.updateProjectionMatrix();
  6940. };
  6941. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  6942. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  6943. /**
  6944. * Uses Focal Length (in mm) to estimate and set FOV
  6945. * 35mm (full-frame) camera is used if frame size is not specified;
  6946. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  6947. */
  6948. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  6949. if ( frameHeight === undefined ) frameHeight = 24;
  6950. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  6951. this.updateProjectionMatrix();
  6952. };
  6953. /**
  6954. * Sets an offset in a larger frustum. This is useful for multi-window or
  6955. * multi-monitor/multi-machine setups.
  6956. *
  6957. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  6958. * the monitors are in grid like this
  6959. *
  6960. * +---+---+---+
  6961. * | A | B | C |
  6962. * +---+---+---+
  6963. * | D | E | F |
  6964. * +---+---+---+
  6965. *
  6966. * then for each monitor you would call it like this
  6967. *
  6968. * var w = 1920;
  6969. * var h = 1080;
  6970. * var fullWidth = w * 3;
  6971. * var fullHeight = h * 2;
  6972. *
  6973. * --A--
  6974. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  6975. * --B--
  6976. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  6977. * --C--
  6978. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  6979. * --D--
  6980. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  6981. * --E--
  6982. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  6983. * --F--
  6984. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  6985. *
  6986. * Note there is no reason monitors have to be the same size or in a grid.
  6987. */
  6988. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  6989. this.fullWidth = fullWidth;
  6990. this.fullHeight = fullHeight;
  6991. this.x = x;
  6992. this.y = y;
  6993. this.width = width;
  6994. this.height = height;
  6995. this.updateProjectionMatrix();
  6996. };
  6997. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  6998. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  6999. if ( this.fullWidth ) {
  7000. var aspect = this.fullWidth / this.fullHeight;
  7001. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  7002. var bottom = - top;
  7003. var left = aspect * bottom;
  7004. var right = aspect * top;
  7005. var width = Math.abs( right - left );
  7006. var height = Math.abs( top - bottom );
  7007. this.projectionMatrix.makeFrustum(
  7008. left + this.x * width / this.fullWidth,
  7009. left + ( this.x + this.width ) * width / this.fullWidth,
  7010. top - ( this.y + this.height ) * height / this.fullHeight,
  7011. top - this.y * height / this.fullHeight,
  7012. this.near,
  7013. this.far
  7014. );
  7015. } else {
  7016. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  7017. }
  7018. };
  7019. THREE.PerspectiveCamera.prototype.clone = function () {
  7020. var camera = new THREE.PerspectiveCamera();
  7021. THREE.Camera.prototype.clone.call( this, camera );
  7022. camera.zoom = this.zoom;
  7023. camera.fov = this.fov;
  7024. camera.aspect = this.aspect;
  7025. camera.near = this.near;
  7026. camera.far = this.far;
  7027. return camera;
  7028. };
  7029. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  7030. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7031. data.object.zoom = this.zoom;
  7032. data.object.fov = this.fov;
  7033. data.object.aspect = this.aspect;
  7034. data.object.near = this.near;
  7035. data.object.far = this.far;
  7036. return data;
  7037. };
  7038. // File:src/lights/Light.js
  7039. /**
  7040. * @author mrdoob / http://mrdoob.com/
  7041. * @author alteredq / http://alteredqualia.com/
  7042. */
  7043. THREE.Light = function ( color ) {
  7044. THREE.Object3D.call( this );
  7045. this.type = 'Light';
  7046. this.color = new THREE.Color( color );
  7047. };
  7048. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  7049. THREE.Light.prototype.constructor = THREE.Light;
  7050. THREE.Light.prototype.clone = function ( light ) {
  7051. if ( light === undefined ) light = new THREE.Light();
  7052. THREE.Object3D.prototype.clone.call( this, light );
  7053. light.color.copy( this.color );
  7054. return light;
  7055. };
  7056. // File:src/lights/AmbientLight.js
  7057. /**
  7058. * @author mrdoob / http://mrdoob.com/
  7059. */
  7060. THREE.AmbientLight = function ( color ) {
  7061. THREE.Light.call( this, color );
  7062. this.type = 'AmbientLight';
  7063. };
  7064. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  7065. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  7066. THREE.AmbientLight.prototype.clone = function () {
  7067. var light = new THREE.AmbientLight();
  7068. THREE.Light.prototype.clone.call( this, light );
  7069. return light;
  7070. };
  7071. THREE.AmbientLight.prototype.toJSON = function ( meta ) {
  7072. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7073. data.object.color = this.color.getHex();
  7074. return data;
  7075. };
  7076. // File:src/lights/AreaLight.js
  7077. /**
  7078. * @author MPanknin / http://www.redplant.de/
  7079. * @author alteredq / http://alteredqualia.com/
  7080. * @author prafullit
  7081. */
  7082. THREE.AreaLight = function ( color, intensity ) {
  7083. THREE.Light.call( this, color );
  7084. this.type = 'AreaLight';
  7085. this.normal = new THREE.Vector3( 0, - 1, 0 );
  7086. this.right = new THREE.Vector3( 1, 0, 0 );
  7087. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7088. this.width = 1.0;
  7089. this.height = 1.0;
  7090. this.constantAttenuation = 1.5;
  7091. this.linearAttenuation = 0.5;
  7092. this.quadraticAttenuation = 0.1;
  7093. };
  7094. THREE.AreaLight.prototype = Object.create( THREE.Light.prototype );
  7095. THREE.AreaLight.prototype.constructor = THREE.AreaLight;
  7096. THREE.AreaLight.prototype.clone = function () {
  7097. var light = new THREE.AreaLight();
  7098. THREE.Light.prototype.clone.call( this, light );
  7099. light.normal.copy(this.normal);
  7100. light.right.copy(this.right);
  7101. light.intensity = this.intensity;
  7102. light.width = this.width;
  7103. light.height = this.height;
  7104. light.constantAttenuation = this.constantAttenuation;
  7105. light.linearAttenuation = this.linearAttenuation;
  7106. light.quadraticAttenuation = this.quadraticAttenuation
  7107. return light;
  7108. };
  7109. THREE.AreaLight.prototype.toJSON = function ( meta ) {
  7110. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7111. data.object.color = this.color.getHex();
  7112. data.object.intensity = this.intensity;
  7113. return data;
  7114. };
  7115. // File:src/lights/DirectionalLight.js
  7116. /**
  7117. * @author mrdoob / http://mrdoob.com/
  7118. * @author alteredq / http://alteredqualia.com/
  7119. */
  7120. THREE.DirectionalLight = function ( color, intensity ) {
  7121. THREE.Light.call( this, color );
  7122. this.type = 'DirectionalLight';
  7123. this.position.set( 0, 1, 0 );
  7124. this.target = new THREE.Object3D();
  7125. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7126. this.castShadow = false;
  7127. this.onlyShadow = false;
  7128. //
  7129. this.shadowCameraNear = 50;
  7130. this.shadowCameraFar = 5000;
  7131. this.shadowCameraLeft = - 500;
  7132. this.shadowCameraRight = 500;
  7133. this.shadowCameraTop = 500;
  7134. this.shadowCameraBottom = - 500;
  7135. this.shadowCameraVisible = false;
  7136. this.shadowBias = 0;
  7137. this.shadowDarkness = 0.5;
  7138. this.shadowMapWidth = 512;
  7139. this.shadowMapHeight = 512;
  7140. //
  7141. this.shadowCascade = false;
  7142. this.shadowCascadeOffset = new THREE.Vector3( 0, 0, - 1000 );
  7143. this.shadowCascadeCount = 2;
  7144. this.shadowCascadeBias = [ 0, 0, 0 ];
  7145. this.shadowCascadeWidth = [ 512, 512, 512 ];
  7146. this.shadowCascadeHeight = [ 512, 512, 512 ];
  7147. this.shadowCascadeNearZ = [ - 1.000, 0.990, 0.998 ];
  7148. this.shadowCascadeFarZ = [ 0.990, 0.998, 1.000 ];
  7149. this.shadowCascadeArray = [];
  7150. //
  7151. this.shadowMap = null;
  7152. this.shadowMapSize = null;
  7153. this.shadowCamera = null;
  7154. this.shadowMatrix = null;
  7155. };
  7156. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  7157. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  7158. THREE.DirectionalLight.prototype.clone = function () {
  7159. var light = new THREE.DirectionalLight();
  7160. THREE.Light.prototype.clone.call( this, light );
  7161. light.target = this.target.clone();
  7162. light.intensity = this.intensity;
  7163. light.castShadow = this.castShadow;
  7164. light.onlyShadow = this.onlyShadow;
  7165. //
  7166. light.shadowCameraNear = this.shadowCameraNear;
  7167. light.shadowCameraFar = this.shadowCameraFar;
  7168. light.shadowCameraLeft = this.shadowCameraLeft;
  7169. light.shadowCameraRight = this.shadowCameraRight;
  7170. light.shadowCameraTop = this.shadowCameraTop;
  7171. light.shadowCameraBottom = this.shadowCameraBottom;
  7172. light.shadowCameraVisible = this.shadowCameraVisible;
  7173. light.shadowBias = this.shadowBias;
  7174. light.shadowDarkness = this.shadowDarkness;
  7175. light.shadowMapWidth = this.shadowMapWidth;
  7176. light.shadowMapHeight = this.shadowMapHeight;
  7177. //
  7178. light.shadowCascade = this.shadowCascade;
  7179. light.shadowCascadeOffset.copy( this.shadowCascadeOffset );
  7180. light.shadowCascadeCount = this.shadowCascadeCount;
  7181. light.shadowCascadeBias = this.shadowCascadeBias.slice( 0 );
  7182. light.shadowCascadeWidth = this.shadowCascadeWidth.slice( 0 );
  7183. light.shadowCascadeHeight = this.shadowCascadeHeight.slice( 0 );
  7184. light.shadowCascadeNearZ = this.shadowCascadeNearZ.slice( 0 );
  7185. light.shadowCascadeFarZ = this.shadowCascadeFarZ.slice( 0 );
  7186. return light;
  7187. };
  7188. THREE.DirectionalLight.prototype.toJSON = function ( meta ) {
  7189. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7190. data.object.color = this.color.getHex();
  7191. data.object.intensity = this.intensity;
  7192. return data;
  7193. };
  7194. // File:src/lights/HemisphereLight.js
  7195. /**
  7196. * @author alteredq / http://alteredqualia.com/
  7197. */
  7198. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  7199. THREE.Light.call( this, skyColor );
  7200. this.type = 'HemisphereLight';
  7201. this.position.set( 0, 100, 0 );
  7202. this.groundColor = new THREE.Color( groundColor );
  7203. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7204. };
  7205. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  7206. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  7207. THREE.HemisphereLight.prototype.clone = function () {
  7208. var light = new THREE.HemisphereLight();
  7209. THREE.Light.prototype.clone.call( this, light );
  7210. light.groundColor.copy( this.groundColor );
  7211. light.intensity = this.intensity;
  7212. return light;
  7213. };
  7214. THREE.HemisphereLight.prototype.toJSON = function ( meta ) {
  7215. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7216. data.object.color = this.color.getHex();
  7217. data.object.groundColor = this.groundColor.getHex();
  7218. return data;
  7219. };
  7220. // File:src/lights/PointLight.js
  7221. /**
  7222. * @author mrdoob / http://mrdoob.com/
  7223. */
  7224. THREE.PointLight = function ( color, intensity, distance, decay ) {
  7225. THREE.Light.call( this, color );
  7226. this.type = 'PointLight';
  7227. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7228. this.distance = ( distance !== undefined ) ? distance : 0;
  7229. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7230. };
  7231. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  7232. THREE.PointLight.prototype.constructor = THREE.PointLight;
  7233. THREE.PointLight.prototype.clone = function () {
  7234. var light = new THREE.PointLight();
  7235. THREE.Light.prototype.clone.call( this, light );
  7236. light.intensity = this.intensity;
  7237. light.distance = this.distance;
  7238. light.decay = this.decay;
  7239. return light;
  7240. };
  7241. THREE.PointLight.prototype.toJSON = function ( meta ) {
  7242. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7243. data.object.color = this.color.getHex();
  7244. data.object.intensity = this.intensity;
  7245. data.object.distance = this.distance;
  7246. data.object.decay = this.decay;
  7247. return data;
  7248. };
  7249. // File:src/lights/SpotLight.js
  7250. /**
  7251. * @author alteredq / http://alteredqualia.com/
  7252. */
  7253. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  7254. THREE.Light.call( this, color );
  7255. this.type = 'SpotLight';
  7256. this.position.set( 0, 1, 0 );
  7257. this.target = new THREE.Object3D();
  7258. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7259. this.distance = ( distance !== undefined ) ? distance : 0;
  7260. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  7261. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  7262. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7263. this.castShadow = false;
  7264. this.onlyShadow = false;
  7265. //
  7266. this.shadowCameraNear = 50;
  7267. this.shadowCameraFar = 5000;
  7268. this.shadowCameraFov = 50;
  7269. this.shadowCameraVisible = false;
  7270. this.shadowBias = 0;
  7271. this.shadowDarkness = 0.5;
  7272. this.shadowMapWidth = 512;
  7273. this.shadowMapHeight = 512;
  7274. //
  7275. this.shadowMap = null;
  7276. this.shadowMapSize = null;
  7277. this.shadowCamera = null;
  7278. this.shadowMatrix = null;
  7279. };
  7280. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  7281. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  7282. THREE.SpotLight.prototype.clone = function () {
  7283. var light = new THREE.SpotLight();
  7284. THREE.Light.prototype.clone.call( this, light );
  7285. light.target = this.target.clone();
  7286. light.intensity = this.intensity;
  7287. light.distance = this.distance;
  7288. light.angle = this.angle;
  7289. light.exponent = this.exponent;
  7290. light.decay = this.decay;
  7291. light.castShadow = this.castShadow;
  7292. light.onlyShadow = this.onlyShadow;
  7293. //
  7294. light.shadowCameraNear = this.shadowCameraNear;
  7295. light.shadowCameraFar = this.shadowCameraFar;
  7296. light.shadowCameraFov = this.shadowCameraFov;
  7297. light.shadowCameraVisible = this.shadowCameraVisible;
  7298. light.shadowBias = this.shadowBias;
  7299. light.shadowDarkness = this.shadowDarkness;
  7300. light.shadowMapWidth = this.shadowMapWidth;
  7301. light.shadowMapHeight = this.shadowMapHeight;
  7302. return light;
  7303. };
  7304. THREE.SpotLight.prototype.toJSON = function ( meta ) {
  7305. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7306. data.object.color = this.color.getHex();
  7307. data.object.intensity = this.intensity;
  7308. data.object.distance = this.distance;
  7309. data.object.angle = this.angle;
  7310. data.object.exponent = this.exponent;
  7311. data.object.decay = this.decay;
  7312. return data;
  7313. };
  7314. // File:src/loaders/Cache.js
  7315. /**
  7316. * @author mrdoob / http://mrdoob.com/
  7317. */
  7318. THREE.Cache = {
  7319. files: {},
  7320. add: function ( key, file ) {
  7321. // console.log( 'THREE.Cache', 'Adding key:', key );
  7322. this.files[ key ] = file;
  7323. },
  7324. get: function ( key ) {
  7325. // console.log( 'THREE.Cache', 'Checking key:', key );
  7326. return this.files[ key ];
  7327. },
  7328. remove: function ( key ) {
  7329. delete this.files[ key ];
  7330. },
  7331. clear: function () {
  7332. this.files = {};
  7333. }
  7334. };
  7335. // File:src/loaders/Loader.js
  7336. /**
  7337. * @author alteredq / http://alteredqualia.com/
  7338. */
  7339. THREE.Loader = function () {
  7340. this.onLoadStart = function () {};
  7341. this.onLoadProgress = function () {};
  7342. this.onLoadComplete = function () {};
  7343. };
  7344. THREE.Loader.prototype = {
  7345. constructor: THREE.Loader,
  7346. crossOrigin: undefined,
  7347. extractUrlBase: function ( url ) {
  7348. var parts = url.split( '/' );
  7349. if ( parts.length === 1 ) return './';
  7350. parts.pop();
  7351. return parts.join( '/' ) + '/';
  7352. },
  7353. initMaterials: function ( materials, texturePath, crossOrigin ) {
  7354. var array = [];
  7355. for ( var i = 0; i < materials.length; ++ i ) {
  7356. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  7357. }
  7358. return array;
  7359. },
  7360. needsTangents: function ( materials ) {
  7361. for ( var i = 0, il = materials.length; i < il; i ++ ) {
  7362. var m = materials[ i ];
  7363. if ( m instanceof THREE.ShaderMaterial ) return true;
  7364. }
  7365. return false;
  7366. },
  7367. createMaterial: ( function () {
  7368. var imageLoader;
  7369. return function ( m, texturePath, crossOrigin ) {
  7370. var scope = this;
  7371. if ( crossOrigin === undefined && scope.crossOrigin !== undefined ) crossOrigin = scope.crossOrigin;
  7372. if ( imageLoader === undefined ) imageLoader = new THREE.ImageLoader();
  7373. function nearest_pow2( n ) {
  7374. var l = Math.log( n ) / Math.LN2;
  7375. return Math.pow( 2, Math.round( l ) );
  7376. }
  7377. function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
  7378. var fullPath = texturePath + sourceFile;
  7379. var texture;
  7380. var loader = THREE.Loader.Handlers.get( fullPath );
  7381. if ( loader !== null ) {
  7382. texture = loader.load( fullPath );
  7383. } else {
  7384. texture = new THREE.Texture();
  7385. loader = imageLoader;
  7386. loader.setCrossOrigin( crossOrigin );
  7387. loader.load( fullPath, function ( image ) {
  7388. if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
  7389. THREE.Math.isPowerOfTwo( image.height ) === false ) {
  7390. var width = nearest_pow2( image.width );
  7391. var height = nearest_pow2( image.height );
  7392. var canvas = document.createElement( 'canvas' );
  7393. canvas.width = width;
  7394. canvas.height = height;
  7395. var context = canvas.getContext( '2d' );
  7396. context.drawImage( image, 0, 0, width, height );
  7397. texture.image = canvas;
  7398. } else {
  7399. texture.image = image;
  7400. }
  7401. texture.needsUpdate = true;
  7402. } );
  7403. }
  7404. texture.sourceFile = sourceFile;
  7405. if ( repeat ) {
  7406. texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
  7407. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  7408. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  7409. }
  7410. if ( offset ) {
  7411. texture.offset.set( offset[ 0 ], offset[ 1 ] );
  7412. }
  7413. if ( wrap ) {
  7414. var wrapMap = {
  7415. 'repeat': THREE.RepeatWrapping,
  7416. 'mirror': THREE.MirroredRepeatWrapping
  7417. };
  7418. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
  7419. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
  7420. }
  7421. if ( anisotropy ) {
  7422. texture.anisotropy = anisotropy;
  7423. }
  7424. where[ name ] = texture;
  7425. }
  7426. function rgb2hex( rgb ) {
  7427. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  7428. }
  7429. // defaults
  7430. var mtype = 'MeshLambertMaterial';
  7431. var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
  7432. // parameters from model file
  7433. if ( m.shading ) {
  7434. var shading = m.shading.toLowerCase();
  7435. if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
  7436. else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
  7437. }
  7438. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  7439. mpars.blending = THREE[ m.blending ];
  7440. }
  7441. if ( m.transparent !== undefined ) {
  7442. mpars.transparent = m.transparent;
  7443. }
  7444. if ( m.opacity !== undefined && m.opacity < 1.0 ) {
  7445. mpars.transparent = true;
  7446. }
  7447. if ( m.depthTest !== undefined ) {
  7448. mpars.depthTest = m.depthTest;
  7449. }
  7450. if ( m.depthWrite !== undefined ) {
  7451. mpars.depthWrite = m.depthWrite;
  7452. }
  7453. if ( m.visible !== undefined ) {
  7454. mpars.visible = m.visible;
  7455. }
  7456. if ( m.flipSided !== undefined ) {
  7457. mpars.side = THREE.BackSide;
  7458. }
  7459. if ( m.doubleSided !== undefined ) {
  7460. mpars.side = THREE.DoubleSide;
  7461. }
  7462. if ( m.wireframe !== undefined ) {
  7463. mpars.wireframe = m.wireframe;
  7464. }
  7465. if ( m.vertexColors !== undefined ) {
  7466. if ( m.vertexColors === 'face' ) {
  7467. mpars.vertexColors = THREE.FaceColors;
  7468. } else if ( m.vertexColors ) {
  7469. mpars.vertexColors = THREE.VertexColors;
  7470. }
  7471. }
  7472. // colors
  7473. if ( m.colorDiffuse ) {
  7474. mpars.color = rgb2hex( m.colorDiffuse );
  7475. } else if ( m.DbgColor ) {
  7476. mpars.color = m.DbgColor;
  7477. }
  7478. if ( m.colorSpecular ) {
  7479. mpars.specular = rgb2hex( m.colorSpecular );
  7480. }
  7481. if ( m.colorEmissive ) {
  7482. mpars.emissive = rgb2hex( m.colorEmissive );
  7483. }
  7484. // modifiers
  7485. if ( m.transparency !== undefined ) {
  7486. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  7487. m.opacity = m.transparency;
  7488. }
  7489. if ( m.opacity !== undefined ) {
  7490. mpars.opacity = m.opacity;
  7491. }
  7492. if ( m.specularCoef ) {
  7493. mpars.shininess = m.specularCoef;
  7494. }
  7495. // textures
  7496. if ( m.mapDiffuse && texturePath ) {
  7497. create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  7498. }
  7499. if ( m.mapLight && texturePath ) {
  7500. create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  7501. }
  7502. if ( m.mapAO && texturePath ) {
  7503. create_texture( mpars, 'aoMap', m.mapAO, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  7504. }
  7505. if ( m.mapBump && texturePath ) {
  7506. create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  7507. }
  7508. if ( m.mapNormal && texturePath ) {
  7509. create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  7510. }
  7511. if ( m.mapSpecular && texturePath ) {
  7512. create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  7513. }
  7514. if ( m.mapAlpha && texturePath ) {
  7515. create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  7516. }
  7517. //
  7518. if ( m.mapBumpScale ) {
  7519. mpars.bumpScale = m.mapBumpScale;
  7520. }
  7521. if ( m.mapNormalFactor ) {
  7522. mpars.normalScale = new THREE.Vector2( m.mapNormalFactor, m.mapNormalFactor );
  7523. }
  7524. var material = new THREE[ mtype ]( mpars );
  7525. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  7526. return material;
  7527. };
  7528. } )()
  7529. };
  7530. THREE.Loader.Handlers = {
  7531. handlers: [],
  7532. add: function ( regex, loader ) {
  7533. this.handlers.push( regex, loader );
  7534. },
  7535. get: function ( file ) {
  7536. for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
  7537. var regex = this.handlers[ i ];
  7538. var loader = this.handlers[ i + 1 ];
  7539. if ( regex.test( file ) ) {
  7540. return loader;
  7541. }
  7542. }
  7543. return null;
  7544. }
  7545. };
  7546. // File:src/loaders/XHRLoader.js
  7547. /**
  7548. * @author mrdoob / http://mrdoob.com/
  7549. */
  7550. THREE.XHRLoader = function ( manager ) {
  7551. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7552. };
  7553. THREE.XHRLoader.prototype = {
  7554. constructor: THREE.XHRLoader,
  7555. load: function ( url, onLoad, onProgress, onError ) {
  7556. var scope = this;
  7557. var cached = THREE.Cache.get( url );
  7558. if ( cached !== undefined ) {
  7559. if ( onLoad ) {
  7560. setTimeout( function () {
  7561. onLoad( cached );
  7562. }, 0 );
  7563. }
  7564. return cached;
  7565. }
  7566. var request = new XMLHttpRequest();
  7567. request.open( 'GET', url, true );
  7568. request.addEventListener( 'load', function ( event ) {
  7569. THREE.Cache.add( url, this.response );
  7570. if ( onLoad ) onLoad( this.response );
  7571. scope.manager.itemEnd( url );
  7572. }, false );
  7573. if ( onProgress !== undefined ) {
  7574. request.addEventListener( 'progress', function ( event ) {
  7575. onProgress( event );
  7576. }, false );
  7577. }
  7578. if ( onError !== undefined ) {
  7579. request.addEventListener( 'error', function ( event ) {
  7580. onError( event );
  7581. }, false );
  7582. }
  7583. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  7584. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  7585. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  7586. request.send( null );
  7587. scope.manager.itemStart( url );
  7588. return request;
  7589. },
  7590. setResponseType: function ( value ) {
  7591. this.responseType = value;
  7592. },
  7593. setCrossOrigin: function ( value ) {
  7594. this.crossOrigin = value;
  7595. },
  7596. setWithCredentials: function ( value ) {
  7597. this.withCredentials = value;
  7598. }
  7599. };
  7600. // File:src/loaders/ImageLoader.js
  7601. /**
  7602. * @author mrdoob / http://mrdoob.com/
  7603. */
  7604. THREE.ImageLoader = function ( manager ) {
  7605. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7606. };
  7607. THREE.ImageLoader.prototype = {
  7608. constructor: THREE.ImageLoader,
  7609. load: function ( url, onLoad, onProgress, onError ) {
  7610. var scope = this;
  7611. var cached = THREE.Cache.get( url );
  7612. if ( cached !== undefined ) {
  7613. if ( onLoad ) {
  7614. setTimeout( function () {
  7615. onLoad( cached );
  7616. }, 0 );
  7617. }
  7618. return cached;
  7619. }
  7620. var image = document.createElement( 'img' );
  7621. image.addEventListener( 'load', function ( event ) {
  7622. THREE.Cache.add( url, this );
  7623. if ( onLoad ) onLoad( this );
  7624. scope.manager.itemEnd( url );
  7625. }, false );
  7626. if ( onProgress !== undefined ) {
  7627. image.addEventListener( 'progress', function ( event ) {
  7628. onProgress( event );
  7629. }, false );
  7630. }
  7631. if ( onError !== undefined ) {
  7632. image.addEventListener( 'error', function ( event ) {
  7633. onError( event );
  7634. }, false );
  7635. }
  7636. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  7637. scope.manager.itemStart( url );
  7638. image.src = url;
  7639. return image;
  7640. },
  7641. setCrossOrigin: function ( value ) {
  7642. this.crossOrigin = value;
  7643. }
  7644. };
  7645. // File:src/loaders/JSONLoader.js
  7646. /**
  7647. * @author mrdoob / http://mrdoob.com/
  7648. * @author alteredq / http://alteredqualia.com/
  7649. */
  7650. THREE.JSONLoader = function ( manager ) {
  7651. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7652. this.withCredentials = false;
  7653. };
  7654. THREE.JSONLoader.prototype = {
  7655. constructor: THREE.JSONLoader,
  7656. load: function( url, onLoad, onProgress, onError ) {
  7657. var scope = this;
  7658. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  7659. var loader = new THREE.XHRLoader( this.manager );
  7660. loader.setCrossOrigin( this.crossOrigin );
  7661. loader.setWithCredentials( this.withCredentials );
  7662. loader.load( url, function ( text ) {
  7663. var json = JSON.parse( text );
  7664. var metadata = json.metadata;
  7665. if ( metadata !== undefined ) {
  7666. if ( metadata.type === 'object' ) {
  7667. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  7668. return;
  7669. }
  7670. if ( metadata.type === 'scene' ) {
  7671. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  7672. return;
  7673. }
  7674. }
  7675. var object = scope.parse( json, texturePath );
  7676. onLoad( object.geometry, object.materials );
  7677. } );
  7678. },
  7679. setCrossOrigin: function ( value ) {
  7680. this.crossOrigin = value;
  7681. },
  7682. setTexturePath: function ( value ) {
  7683. this.texturePath = value;
  7684. },
  7685. parse: function ( json, texturePath ) {
  7686. var geometry = new THREE.Geometry(),
  7687. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  7688. parseModel( scale );
  7689. parseSkin();
  7690. parseMorphing( scale );
  7691. geometry.computeFaceNormals();
  7692. geometry.computeBoundingSphere();
  7693. function parseModel( scale ) {
  7694. function isBitSet( value, position ) {
  7695. return value & ( 1 << position );
  7696. }
  7697. var i, j, fi,
  7698. offset, zLength,
  7699. colorIndex, normalIndex, uvIndex,
  7700. type,
  7701. isQuad,
  7702. hasMaterial,
  7703. hasFaceVertexUv,
  7704. hasFaceNormal, hasFaceVertexNormal,
  7705. hasFaceColor, hasFaceVertexColor,
  7706. vertex, face, faceA, faceB, hex, normal,
  7707. uvLayer, uv, u, v,
  7708. faces = json.faces,
  7709. vertices = json.vertices,
  7710. normals = json.normals,
  7711. colors = json.colors,
  7712. nUvLayers = 0;
  7713. if ( json.uvs !== undefined ) {
  7714. // disregard empty arrays
  7715. for ( i = 0; i < json.uvs.length; i ++ ) {
  7716. if ( json.uvs[ i ].length ) nUvLayers ++;
  7717. }
  7718. for ( i = 0; i < nUvLayers; i ++ ) {
  7719. geometry.faceVertexUvs[ i ] = [];
  7720. }
  7721. }
  7722. offset = 0;
  7723. zLength = vertices.length;
  7724. while ( offset < zLength ) {
  7725. vertex = new THREE.Vector3();
  7726. vertex.x = vertices[ offset ++ ] * scale;
  7727. vertex.y = vertices[ offset ++ ] * scale;
  7728. vertex.z = vertices[ offset ++ ] * scale;
  7729. geometry.vertices.push( vertex );
  7730. }
  7731. offset = 0;
  7732. zLength = faces.length;
  7733. while ( offset < zLength ) {
  7734. type = faces[ offset ++ ];
  7735. isQuad = isBitSet( type, 0 );
  7736. hasMaterial = isBitSet( type, 1 );
  7737. hasFaceVertexUv = isBitSet( type, 3 );
  7738. hasFaceNormal = isBitSet( type, 4 );
  7739. hasFaceVertexNormal = isBitSet( type, 5 );
  7740. hasFaceColor = isBitSet( type, 6 );
  7741. hasFaceVertexColor = isBitSet( type, 7 );
  7742. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  7743. if ( isQuad ) {
  7744. faceA = new THREE.Face3();
  7745. faceA.a = faces[ offset ];
  7746. faceA.b = faces[ offset + 1 ];
  7747. faceA.c = faces[ offset + 3 ];
  7748. faceB = new THREE.Face3();
  7749. faceB.a = faces[ offset + 1 ];
  7750. faceB.b = faces[ offset + 2 ];
  7751. faceB.c = faces[ offset + 3 ];
  7752. offset += 4;
  7753. if ( hasMaterial ) {
  7754. offset ++;
  7755. }
  7756. // to get face <=> uv index correspondence
  7757. fi = geometry.faces.length;
  7758. if ( hasFaceVertexUv ) {
  7759. for ( i = 0; i < nUvLayers; i ++ ) {
  7760. uvLayer = json.uvs[ i ];
  7761. geometry.faceVertexUvs[ i ][ fi ] = [];
  7762. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  7763. for ( j = 0; j < 4; j ++ ) {
  7764. uvIndex = faces[ offset ++ ];
  7765. u = uvLayer[ uvIndex * 2 ];
  7766. v = uvLayer[ uvIndex * 2 + 1 ];
  7767. uv = new THREE.Vector2( u, v );
  7768. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7769. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  7770. }
  7771. }
  7772. }
  7773. if ( hasFaceNormal ) {
  7774. normalIndex = faces[ offset ++ ] * 3;
  7775. faceA.normal.set(
  7776. normals[ normalIndex ++ ],
  7777. normals[ normalIndex ++ ],
  7778. normals[ normalIndex ]
  7779. );
  7780. faceB.normal.copy( faceA.normal );
  7781. }
  7782. if ( hasFaceVertexNormal ) {
  7783. for ( i = 0; i < 4; i ++ ) {
  7784. normalIndex = faces[ offset ++ ] * 3;
  7785. normal = new THREE.Vector3(
  7786. normals[ normalIndex ++ ],
  7787. normals[ normalIndex ++ ],
  7788. normals[ normalIndex ]
  7789. );
  7790. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  7791. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  7792. }
  7793. }
  7794. if ( hasFaceColor ) {
  7795. colorIndex = faces[ offset ++ ];
  7796. hex = colors[ colorIndex ];
  7797. faceA.color.setHex( hex );
  7798. faceB.color.setHex( hex );
  7799. }
  7800. if ( hasFaceVertexColor ) {
  7801. for ( i = 0; i < 4; i ++ ) {
  7802. colorIndex = faces[ offset ++ ];
  7803. hex = colors[ colorIndex ];
  7804. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  7805. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  7806. }
  7807. }
  7808. geometry.faces.push( faceA );
  7809. geometry.faces.push( faceB );
  7810. } else {
  7811. face = new THREE.Face3();
  7812. face.a = faces[ offset ++ ];
  7813. face.b = faces[ offset ++ ];
  7814. face.c = faces[ offset ++ ];
  7815. if ( hasMaterial ) {
  7816. offset ++;
  7817. }
  7818. // to get face <=> uv index correspondence
  7819. fi = geometry.faces.length;
  7820. if ( hasFaceVertexUv ) {
  7821. for ( i = 0; i < nUvLayers; i ++ ) {
  7822. uvLayer = json.uvs[ i ];
  7823. geometry.faceVertexUvs[ i ][ fi ] = [];
  7824. for ( j = 0; j < 3; j ++ ) {
  7825. uvIndex = faces[ offset ++ ];
  7826. u = uvLayer[ uvIndex * 2 ];
  7827. v = uvLayer[ uvIndex * 2 + 1 ];
  7828. uv = new THREE.Vector2( u, v );
  7829. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7830. }
  7831. }
  7832. }
  7833. if ( hasFaceNormal ) {
  7834. normalIndex = faces[ offset ++ ] * 3;
  7835. face.normal.set(
  7836. normals[ normalIndex ++ ],
  7837. normals[ normalIndex ++ ],
  7838. normals[ normalIndex ]
  7839. );
  7840. }
  7841. if ( hasFaceVertexNormal ) {
  7842. for ( i = 0; i < 3; i ++ ) {
  7843. normalIndex = faces[ offset ++ ] * 3;
  7844. normal = new THREE.Vector3(
  7845. normals[ normalIndex ++ ],
  7846. normals[ normalIndex ++ ],
  7847. normals[ normalIndex ]
  7848. );
  7849. face.vertexNormals.push( normal );
  7850. }
  7851. }
  7852. if ( hasFaceColor ) {
  7853. colorIndex = faces[ offset ++ ];
  7854. face.color.setHex( colors[ colorIndex ] );
  7855. }
  7856. if ( hasFaceVertexColor ) {
  7857. for ( i = 0; i < 3; i ++ ) {
  7858. colorIndex = faces[ offset ++ ];
  7859. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  7860. }
  7861. }
  7862. geometry.faces.push( face );
  7863. }
  7864. }
  7865. };
  7866. function parseSkin() {
  7867. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  7868. if ( json.skinWeights ) {
  7869. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  7870. var x = json.skinWeights[ i ];
  7871. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  7872. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  7873. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  7874. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  7875. }
  7876. }
  7877. if ( json.skinIndices ) {
  7878. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  7879. var a = json.skinIndices[ i ];
  7880. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  7881. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  7882. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  7883. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  7884. }
  7885. }
  7886. geometry.bones = json.bones;
  7887. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  7888. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  7889. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  7890. }
  7891. // could change this to json.animations[0] or remove completely
  7892. geometry.animation = json.animation;
  7893. geometry.animations = json.animations;
  7894. };
  7895. function parseMorphing( scale ) {
  7896. if ( json.morphTargets !== undefined ) {
  7897. var i, l, v, vl, dstVertices, srcVertices;
  7898. for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  7899. geometry.morphTargets[ i ] = {};
  7900. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  7901. geometry.morphTargets[ i ].vertices = [];
  7902. dstVertices = geometry.morphTargets[ i ].vertices;
  7903. srcVertices = json.morphTargets [ i ].vertices;
  7904. for ( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  7905. var vertex = new THREE.Vector3();
  7906. vertex.x = srcVertices[ v ] * scale;
  7907. vertex.y = srcVertices[ v + 1 ] * scale;
  7908. vertex.z = srcVertices[ v + 2 ] * scale;
  7909. dstVertices.push( vertex );
  7910. }
  7911. }
  7912. }
  7913. if ( json.morphColors !== undefined ) {
  7914. var i, l, c, cl, dstColors, srcColors, color;
  7915. for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
  7916. geometry.morphColors[ i ] = {};
  7917. geometry.morphColors[ i ].name = json.morphColors[ i ].name;
  7918. geometry.morphColors[ i ].colors = [];
  7919. dstColors = geometry.morphColors[ i ].colors;
  7920. srcColors = json.morphColors [ i ].colors;
  7921. for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
  7922. color = new THREE.Color( 0xffaa00 );
  7923. color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
  7924. dstColors.push( color );
  7925. }
  7926. }
  7927. }
  7928. };
  7929. if ( json.materials === undefined || json.materials.length === 0 ) {
  7930. return { geometry: geometry };
  7931. } else {
  7932. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  7933. if ( THREE.Loader.prototype.needsTangents( materials ) ) {
  7934. geometry.computeTangents();
  7935. }
  7936. return { geometry: geometry, materials: materials };
  7937. }
  7938. }
  7939. };
  7940. // File:src/loaders/LoadingManager.js
  7941. /**
  7942. * @author mrdoob / http://mrdoob.com/
  7943. */
  7944. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  7945. var scope = this;
  7946. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  7947. this.onLoad = onLoad;
  7948. this.onProgress = onProgress;
  7949. this.onError = onError;
  7950. this.itemStart = function ( url ) {
  7951. itemsTotal ++;
  7952. if ( isLoading === false ) {
  7953. if ( scope.onStart !== undefined ) {
  7954. scope.onStart( url, itemsLoaded, itemsTotal );
  7955. }
  7956. }
  7957. isLoading = true;
  7958. };
  7959. this.itemEnd = function ( url ) {
  7960. itemsLoaded ++;
  7961. if ( scope.onProgress !== undefined ) {
  7962. scope.onProgress( url, itemsLoaded, itemsTotal );
  7963. }
  7964. if ( itemsLoaded === itemsTotal ) {
  7965. isLoading = false;
  7966. if ( scope.onLoad !== undefined ) {
  7967. scope.onLoad();
  7968. }
  7969. }
  7970. };
  7971. };
  7972. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  7973. // File:src/loaders/BufferGeometryLoader.js
  7974. /**
  7975. * @author mrdoob / http://mrdoob.com/
  7976. */
  7977. THREE.BufferGeometryLoader = function ( manager ) {
  7978. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7979. };
  7980. THREE.BufferGeometryLoader.prototype = {
  7981. constructor: THREE.BufferGeometryLoader,
  7982. load: function ( url, onLoad, onProgress, onError ) {
  7983. var scope = this;
  7984. var loader = new THREE.XHRLoader( scope.manager );
  7985. loader.setCrossOrigin( this.crossOrigin );
  7986. loader.load( url, function ( text ) {
  7987. onLoad( scope.parse( JSON.parse( text ) ) );
  7988. }, onProgress, onError );
  7989. },
  7990. setCrossOrigin: function ( value ) {
  7991. this.crossOrigin = value;
  7992. },
  7993. parse: function ( json ) {
  7994. var geometry = new THREE.BufferGeometry();
  7995. var attributes = json.data.attributes;
  7996. for ( var key in attributes ) {
  7997. var attribute = attributes[ key ];
  7998. var typedArray = new self[ attribute.type ]( attribute.array );
  7999. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  8000. }
  8001. var offsets = json.data.offsets;
  8002. if ( offsets !== undefined ) {
  8003. var offsetsArray = JSON.parse( JSON.stringify( offsets ) );
  8004. for ( var i = 0; i < offsetsArray.length; i ++ ) {
  8005. var offset = offsetsArray[i];
  8006. var indexStart = offset.start;
  8007. var indexCount = offset.count;
  8008. var indexOffset = offset.index;
  8009. geometry.addDrawcall( indexStart, indexCount, indexOffset );
  8010. }
  8011. }
  8012. var boundingSphere = json.data.boundingSphere;
  8013. if ( boundingSphere !== undefined ) {
  8014. var center = new THREE.Vector3();
  8015. if ( boundingSphere.center !== undefined ) {
  8016. center.fromArray( boundingSphere.center );
  8017. }
  8018. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  8019. }
  8020. return geometry;
  8021. }
  8022. };
  8023. // File:src/loaders/MaterialLoader.js
  8024. /**
  8025. * @author mrdoob / http://mrdoob.com/
  8026. */
  8027. THREE.MaterialLoader = function ( manager ) {
  8028. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8029. };
  8030. THREE.MaterialLoader.prototype = {
  8031. constructor: THREE.MaterialLoader,
  8032. load: function ( url, onLoad, onProgress, onError ) {
  8033. var scope = this;
  8034. var loader = new THREE.XHRLoader( scope.manager );
  8035. loader.setCrossOrigin( this.crossOrigin );
  8036. loader.load( url, function ( text ) {
  8037. onLoad( scope.parse( JSON.parse( text ) ) );
  8038. }, onProgress, onError );
  8039. },
  8040. setCrossOrigin: function ( value ) {
  8041. this.crossOrigin = value;
  8042. },
  8043. parse: function ( json ) {
  8044. var material = new THREE[ json.type ];
  8045. if ( json.color !== undefined ) material.color.setHex( json.color );
  8046. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  8047. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  8048. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  8049. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  8050. if ( json.attributes !== undefined ) material.attributes = json.attributes;
  8051. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  8052. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  8053. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  8054. if ( json.shading !== undefined ) material.shading = json.shading;
  8055. if ( json.blending !== undefined ) material.blending = json.blending;
  8056. if ( json.side !== undefined ) material.side = json.side;
  8057. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  8058. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  8059. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  8060. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  8061. // for PointCloudMaterial
  8062. if ( json.size !== undefined ) material.size = json.size;
  8063. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  8064. if ( json.materials !== undefined ) {
  8065. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  8066. material.materials.push( this.parse( json.materials[ i ] ) );
  8067. }
  8068. }
  8069. return material;
  8070. }
  8071. };
  8072. // File:src/loaders/ObjectLoader.js
  8073. /**
  8074. * @author mrdoob / http://mrdoob.com/
  8075. */
  8076. THREE.ObjectLoader = function ( manager ) {
  8077. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8078. this.texturePath = '';
  8079. };
  8080. THREE.ObjectLoader.prototype = {
  8081. constructor: THREE.ObjectLoader,
  8082. load: function ( url, onLoad, onProgress, onError ) {
  8083. if ( this.texturePath === '' ) {
  8084. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  8085. }
  8086. var scope = this;
  8087. var loader = new THREE.XHRLoader( scope.manager );
  8088. loader.setCrossOrigin( this.crossOrigin );
  8089. loader.load( url, function ( text ) {
  8090. scope.parse( JSON.parse( text ), onLoad );
  8091. }, onProgress, onError );
  8092. },
  8093. setTexturePath: function ( value ) {
  8094. this.texturePath = value;
  8095. },
  8096. setCrossOrigin: function ( value ) {
  8097. this.crossOrigin = value;
  8098. },
  8099. parse: function ( json, onLoad ) {
  8100. var geometries = this.parseGeometries( json.geometries );
  8101. var images = this.parseImages( json.images, function () {
  8102. if ( onLoad !== undefined ) onLoad( object );
  8103. } );
  8104. var textures = this.parseTextures( json.textures, images );
  8105. var materials = this.parseMaterials( json.materials, textures );
  8106. var object = this.parseObject( json.object, geometries, materials );
  8107. if ( json.images === undefined || json.images.length === 0 ) {
  8108. if ( onLoad !== undefined ) onLoad( object );
  8109. }
  8110. return object;
  8111. },
  8112. parseGeometries: function ( json ) {
  8113. var geometries = {};
  8114. if ( json !== undefined ) {
  8115. var geometryLoader = new THREE.JSONLoader();
  8116. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  8117. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8118. var geometry;
  8119. var data = json[ i ];
  8120. switch ( data.type ) {
  8121. case 'PlaneGeometry':
  8122. case 'PlaneBufferGeometry':
  8123. geometry = new THREE[ data.type ](
  8124. data.width,
  8125. data.height,
  8126. data.widthSegments,
  8127. data.heightSegments
  8128. );
  8129. break;
  8130. case 'BoxGeometry':
  8131. case 'CubeGeometry': // backwards compatible
  8132. geometry = new THREE.BoxGeometry(
  8133. data.width,
  8134. data.height,
  8135. data.depth,
  8136. data.widthSegments,
  8137. data.heightSegments,
  8138. data.depthSegments
  8139. );
  8140. break;
  8141. case 'CircleGeometry':
  8142. geometry = new THREE.CircleGeometry(
  8143. data.radius,
  8144. data.segments
  8145. );
  8146. break;
  8147. case 'CylinderGeometry':
  8148. geometry = new THREE.CylinderGeometry(
  8149. data.radiusTop,
  8150. data.radiusBottom,
  8151. data.height,
  8152. data.radialSegments,
  8153. data.heightSegments,
  8154. data.openEnded
  8155. );
  8156. break;
  8157. case 'SphereGeometry':
  8158. geometry = new THREE.SphereGeometry(
  8159. data.radius,
  8160. data.widthSegments,
  8161. data.heightSegments,
  8162. data.phiStart,
  8163. data.phiLength,
  8164. data.thetaStart,
  8165. data.thetaLength
  8166. );
  8167. break;
  8168. case 'IcosahedronGeometry':
  8169. geometry = new THREE.IcosahedronGeometry(
  8170. data.radius,
  8171. data.detail
  8172. );
  8173. break;
  8174. case 'TorusGeometry':
  8175. geometry = new THREE.TorusGeometry(
  8176. data.radius,
  8177. data.tube,
  8178. data.radialSegments,
  8179. data.tubularSegments,
  8180. data.arc
  8181. );
  8182. break;
  8183. case 'TorusKnotGeometry':
  8184. geometry = new THREE.TorusKnotGeometry(
  8185. data.radius,
  8186. data.tube,
  8187. data.radialSegments,
  8188. data.tubularSegments,
  8189. data.p,
  8190. data.q,
  8191. data.heightScale
  8192. );
  8193. break;
  8194. case 'BufferGeometry':
  8195. geometry = bufferGeometryLoader.parse( data );
  8196. break;
  8197. case 'Geometry':
  8198. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  8199. break;
  8200. case 'TextGeometry':
  8201. geometry = new THREE.TextGeometry(
  8202. data.text,
  8203. data.data
  8204. );
  8205. break;
  8206. }
  8207. geometry.uuid = data.uuid;
  8208. if ( data.name !== undefined ) geometry.name = data.name;
  8209. geometries[ data.uuid ] = geometry;
  8210. }
  8211. }
  8212. return geometries;
  8213. },
  8214. parseMaterials: function ( json, textures ) {
  8215. var materials = {};
  8216. if ( json !== undefined ) {
  8217. var getTexture = function ( name ) {
  8218. if ( textures[ name ] === undefined ) {
  8219. console.warn( 'THREE.ObjectLoader: Undefined texture', name );
  8220. }
  8221. return textures[ name ];
  8222. };
  8223. var loader = new THREE.MaterialLoader();
  8224. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8225. var data = json[ i ];
  8226. var material = loader.parse( data );
  8227. material.uuid = data.uuid;
  8228. if ( data.depthTest !== undefined ) material.depthTest = data.depthTest;
  8229. if ( data.depthWrite !== undefined ) material.depthWrite = data.depthWrite;
  8230. if ( data.name !== undefined ) material.name = data.name;
  8231. if ( data.map !== undefined ) material.map = getTexture( data.map );
  8232. if ( data.alphaMap !== undefined ) {
  8233. material.alphaMap = getTexture( data.alphaMap );
  8234. material.transparent = true;
  8235. }
  8236. if ( data.bumpMap !== undefined ) material.bumpMap = getTexture( data.bumpMap );
  8237. if ( data.bumpScale !== undefined ) material.bumpScale = data.bumpScale;
  8238. if ( data.normalMap !== undefined ) material.normalMap = getTexture( data.normalMap );
  8239. if ( data.normalScale ) material.normalScale = new THREE.Vector2( data.normalScale, data.normalScale );
  8240. if ( data.specularMap !== undefined ) material.specularMap = getTexture( data.specularMap );
  8241. if ( data.envMap !== undefined ) {
  8242. material.envMap = getTexture( data.envMap );
  8243. material.combine = THREE.MultiplyOperation;
  8244. }
  8245. if ( data.reflectivity ) material.reflectivity = data.reflectivity;
  8246. if ( data.lightMap !== undefined ) material.lightMap = getTexture( data.lightMap );
  8247. if ( data.lightMapIntensity !== undefined ) material.lightMapIntensity = data.lightMapIntensity;
  8248. if ( data.aoMap !== undefined ) material.aoMap = getTexture( data.aoMap );
  8249. if ( data.aoMapIntensity !== undefined ) material.aoMapIntensity = data.aoMapIntensity;
  8250. materials[ data.uuid ] = material;
  8251. }
  8252. }
  8253. return materials;
  8254. },
  8255. parseImages: function ( json, onLoad ) {
  8256. var scope = this;
  8257. var images = {};
  8258. if ( json !== undefined && json.length > 0 ) {
  8259. var manager = new THREE.LoadingManager( onLoad );
  8260. var loader = new THREE.ImageLoader( manager );
  8261. loader.setCrossOrigin( this.crossOrigin );
  8262. var loadImage = function ( url ) {
  8263. url = scope.texturePath + url;
  8264. scope.manager.itemStart( url );
  8265. return loader.load( url, function () {
  8266. scope.manager.itemEnd( url );
  8267. } );
  8268. };
  8269. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8270. var image = json[ i ];
  8271. images[ image.uuid ] = loadImage( image.url );
  8272. }
  8273. }
  8274. return images;
  8275. },
  8276. parseTextures: function ( json, images ) {
  8277. function parseConstant( value ) {
  8278. if ( typeof( value ) === 'number' ) return value;
  8279. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  8280. return THREE[ value ];
  8281. }
  8282. var textures = {};
  8283. if ( json !== undefined ) {
  8284. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8285. var data = json[ i ];
  8286. if ( data.image === undefined ) {
  8287. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  8288. }
  8289. if ( images[ data.image ] === undefined ) {
  8290. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  8291. }
  8292. var texture = new THREE.Texture( images[ data.image ] );
  8293. texture.needsUpdate = true;
  8294. texture.uuid = data.uuid;
  8295. if ( data.name !== undefined ) texture.name = data.name;
  8296. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  8297. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  8298. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  8299. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  8300. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  8301. if ( Array.isArray( data.wrap ) ) {
  8302. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  8303. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  8304. }
  8305. textures[ data.uuid ] = texture;
  8306. }
  8307. }
  8308. return textures;
  8309. },
  8310. parseObject: function () {
  8311. var matrix = new THREE.Matrix4();
  8312. return function ( data, geometries, materials ) {
  8313. var object;
  8314. var getGeometry = function ( name ) {
  8315. if ( geometries[ name ] === undefined ) {
  8316. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  8317. }
  8318. return geometries[ name ];
  8319. };
  8320. var getMaterial = function ( name ) {
  8321. if ( materials[ name ] === undefined ) {
  8322. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  8323. }
  8324. return materials[ name ];
  8325. };
  8326. switch ( data.type ) {
  8327. case 'Scene':
  8328. object = new THREE.Scene();
  8329. break;
  8330. case 'PerspectiveCamera':
  8331. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  8332. break;
  8333. case 'OrthographicCamera':
  8334. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  8335. break;
  8336. case 'AmbientLight':
  8337. object = new THREE.AmbientLight( data.color );
  8338. break;
  8339. case 'DirectionalLight':
  8340. object = new THREE.DirectionalLight( data.color, data.intensity );
  8341. break;
  8342. case 'PointLight':
  8343. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  8344. break;
  8345. case 'SpotLight':
  8346. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  8347. break;
  8348. case 'HemisphereLight':
  8349. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  8350. break;
  8351. case 'Mesh':
  8352. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  8353. break;
  8354. case 'Line':
  8355. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  8356. break;
  8357. case 'PointCloud':
  8358. object = new THREE.PointCloud( getGeometry( data.geometry ), getMaterial( data.material ) );
  8359. break;
  8360. case 'Sprite':
  8361. object = new THREE.Sprite( getMaterial( data.material ) );
  8362. break;
  8363. case 'Group':
  8364. object = new THREE.Group();
  8365. break;
  8366. default:
  8367. object = new THREE.Object3D();
  8368. }
  8369. object.uuid = data.uuid;
  8370. if ( data.name !== undefined ) object.name = data.name;
  8371. if ( data.matrix !== undefined ) {
  8372. matrix.fromArray( data.matrix );
  8373. matrix.decompose( object.position, object.quaternion, object.scale );
  8374. } else {
  8375. if ( data.position !== undefined ) object.position.fromArray( data.position );
  8376. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  8377. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  8378. }
  8379. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  8380. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  8381. if ( data.visible !== undefined ) object.visible = data.visible;
  8382. if ( data.userData !== undefined ) object.userData = data.userData;
  8383. if ( data.children !== undefined ) {
  8384. for ( var child in data.children ) {
  8385. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  8386. }
  8387. }
  8388. return object;
  8389. }
  8390. }()
  8391. };
  8392. // File:src/loaders/TextureLoader.js
  8393. /**
  8394. * @author mrdoob / http://mrdoob.com/
  8395. */
  8396. THREE.TextureLoader = function ( manager ) {
  8397. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8398. };
  8399. THREE.TextureLoader.prototype = {
  8400. constructor: THREE.TextureLoader,
  8401. load: function ( url, onLoad, onProgress, onError ) {
  8402. var scope = this;
  8403. var loader = new THREE.ImageLoader( scope.manager );
  8404. loader.setCrossOrigin( this.crossOrigin );
  8405. loader.load( url, function ( image ) {
  8406. var texture = new THREE.Texture( image );
  8407. texture.needsUpdate = true;
  8408. if ( onLoad !== undefined ) {
  8409. onLoad( texture );
  8410. }
  8411. }, onProgress, onError );
  8412. },
  8413. setCrossOrigin: function ( value ) {
  8414. this.crossOrigin = value;
  8415. }
  8416. };
  8417. // File:src/loaders/BinaryTextureLoader.js
  8418. /**
  8419. * @author Nikos M. / https://github.com/foo123/
  8420. *
  8421. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  8422. */
  8423. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  8424. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8425. // override in sub classes
  8426. this._parser = null;
  8427. };
  8428. THREE.BinaryTextureLoader.prototype = {
  8429. constructor: THREE.BinaryTextureLoader,
  8430. load: function ( url, onLoad, onProgress, onError ) {
  8431. var scope = this;
  8432. var texture = new THREE.DataTexture( );
  8433. var loader = new THREE.XHRLoader( this.manager );
  8434. loader.setCrossOrigin( this.crossOrigin );
  8435. loader.setResponseType( 'arraybuffer' );
  8436. loader.load( url, function ( buffer ) {
  8437. var texData = scope._parser( buffer );
  8438. if ( !texData ) return;
  8439. if ( undefined !== texData.image ) {
  8440. texture.image = texData.image;
  8441. } else if ( undefined !== texData.data ) {
  8442. texture.image.width = texData.width;
  8443. texture.image.height = texData.height;
  8444. texture.image.data = texData.data;
  8445. }
  8446. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  8447. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  8448. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  8449. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  8450. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  8451. if ( undefined !== texData.format ) {
  8452. texture.format = texData.format;
  8453. }
  8454. if ( undefined !== texData.type ) {
  8455. texture.type = texData.type;
  8456. }
  8457. if ( undefined !== texData.mipmaps ) {
  8458. texture.mipmaps = texData.mipmaps;
  8459. }
  8460. if ( 1 === texData.mipmapCount ) {
  8461. texture.minFilter = THREE.LinearFilter;
  8462. }
  8463. texture.needsUpdate = true;
  8464. if ( onLoad ) onLoad( texture, texData );
  8465. }, onProgress, onError );
  8466. return texture;
  8467. },
  8468. setCrossOrigin: function ( value ) {
  8469. this.crossOrigin = value;
  8470. }
  8471. };
  8472. // File:src/loaders/CompressedTextureLoader.js
  8473. /**
  8474. * @author mrdoob / http://mrdoob.com/
  8475. *
  8476. * Abstract Base class to block based textures loader (dds, pvr, ...)
  8477. */
  8478. THREE.CompressedTextureLoader = function ( manager ) {
  8479. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8480. // override in sub classes
  8481. this._parser = null;
  8482. };
  8483. THREE.CompressedTextureLoader.prototype = {
  8484. constructor: THREE.CompressedTextureLoader,
  8485. load: function ( url, onLoad, onProgress, onError ) {
  8486. var scope = this;
  8487. var images = [];
  8488. var texture = new THREE.CompressedTexture();
  8489. texture.image = images;
  8490. var loader = new THREE.XHRLoader( this.manager );
  8491. loader.setCrossOrigin( this.crossOrigin );
  8492. loader.setResponseType( 'arraybuffer' );
  8493. if ( Array.isArray( url ) ) {
  8494. var loaded = 0;
  8495. var loadTexture = function ( i ) {
  8496. loader.load( url[ i ], function ( buffer ) {
  8497. var texDatas = scope._parser( buffer, true );
  8498. images[ i ] = {
  8499. width: texDatas.width,
  8500. height: texDatas.height,
  8501. format: texDatas.format,
  8502. mipmaps: texDatas.mipmaps
  8503. };
  8504. loaded += 1;
  8505. if ( loaded === 6 ) {
  8506. if (texDatas.mipmapCount === 1)
  8507. texture.minFilter = THREE.LinearFilter;
  8508. texture.format = texDatas.format;
  8509. texture.needsUpdate = true;
  8510. if ( onLoad ) onLoad( texture );
  8511. }
  8512. }, onProgress, onError );
  8513. };
  8514. for ( var i = 0, il = url.length; i < il; ++ i ) {
  8515. loadTexture( i );
  8516. }
  8517. } else {
  8518. // compressed cubemap texture stored in a single DDS file
  8519. loader.load( url, function ( buffer ) {
  8520. var texDatas = scope._parser( buffer, true );
  8521. if ( texDatas.isCubemap ) {
  8522. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  8523. for ( var f = 0; f < faces; f ++ ) {
  8524. images[ f ] = { mipmaps : [] };
  8525. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  8526. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  8527. images[ f ].format = texDatas.format;
  8528. images[ f ].width = texDatas.width;
  8529. images[ f ].height = texDatas.height;
  8530. }
  8531. }
  8532. } else {
  8533. texture.image.width = texDatas.width;
  8534. texture.image.height = texDatas.height;
  8535. texture.mipmaps = texDatas.mipmaps;
  8536. }
  8537. if ( texDatas.mipmapCount === 1 ) {
  8538. texture.minFilter = THREE.LinearFilter;
  8539. }
  8540. texture.format = texDatas.format;
  8541. texture.needsUpdate = true;
  8542. if ( onLoad ) onLoad( texture );
  8543. }, onProgress, onError );
  8544. }
  8545. return texture;
  8546. },
  8547. setCrossOrigin: function ( value ) {
  8548. this.crossOrigin = value;
  8549. }
  8550. };
  8551. // File:src/materials/Material.js
  8552. /**
  8553. * @author mrdoob / http://mrdoob.com/
  8554. * @author alteredq / http://alteredqualia.com/
  8555. */
  8556. THREE.Material = function () {
  8557. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  8558. this.uuid = THREE.Math.generateUUID();
  8559. this.name = '';
  8560. this.type = 'Material';
  8561. this.side = THREE.FrontSide;
  8562. this.opacity = 1;
  8563. this.transparent = false;
  8564. this.blending = THREE.NormalBlending;
  8565. this.blendSrc = THREE.SrcAlphaFactor;
  8566. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  8567. this.blendEquation = THREE.AddEquation;
  8568. this.blendSrcAlpha = null;
  8569. this.blendDstAlpha = null;
  8570. this.blendEquationAlpha = null;
  8571. this.depthFunc = THREE.LessEqualDepth;
  8572. this.depthTest = true;
  8573. this.depthWrite = true;
  8574. this.colorWrite = true;
  8575. this.polygonOffset = false;
  8576. this.polygonOffsetFactor = 0;
  8577. this.polygonOffsetUnits = 0;
  8578. this.alphaTest = 0;
  8579. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  8580. this.visible = true;
  8581. this._needsUpdate = true;
  8582. };
  8583. THREE.Material.prototype = {
  8584. constructor: THREE.Material,
  8585. get needsUpdate () {
  8586. return this._needsUpdate;
  8587. },
  8588. set needsUpdate ( value ) {
  8589. if ( value === true ) this.update();
  8590. this._needsUpdate = value;
  8591. },
  8592. setValues: function ( values ) {
  8593. if ( values === undefined ) return;
  8594. for ( var key in values ) {
  8595. var newValue = values[ key ];
  8596. if ( newValue === undefined ) {
  8597. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  8598. continue;
  8599. }
  8600. if ( key in this ) {
  8601. var currentValue = this[ key ];
  8602. if ( currentValue instanceof THREE.Color ) {
  8603. currentValue.set( newValue );
  8604. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  8605. currentValue.copy( newValue );
  8606. } else if ( key === 'overdraw' ) {
  8607. // ensure overdraw is backwards-compatible with legacy boolean type
  8608. this[ key ] = Number( newValue );
  8609. } else {
  8610. this[ key ] = newValue;
  8611. }
  8612. }
  8613. }
  8614. },
  8615. toJSON: function ( meta ) {
  8616. var data = {
  8617. metadata: {
  8618. version: 4.4,
  8619. type: 'Material',
  8620. generator: 'Material.toJSON'
  8621. }
  8622. };
  8623. // standard Material serialization
  8624. data.uuid = this.uuid;
  8625. data.type = this.type;
  8626. if ( this.name !== '' ) data.name = this.name;
  8627. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  8628. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  8629. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  8630. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  8631. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  8632. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  8633. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  8634. if ( this.bumpMap instanceof THREE.Texture ) {
  8635. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  8636. data.bumpScale = this.bumpScale;
  8637. }
  8638. if ( this.normalMap instanceof THREE.Texture ) {
  8639. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  8640. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  8641. }
  8642. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  8643. if ( this.envMap instanceof THREE.Texture ) {
  8644. data.envMap = this.envMap.toJSON( meta ).uuid;
  8645. data.reflectivity = this.reflectivity; // Scale behind envMap
  8646. }
  8647. if ( this.size !== undefined ) data.size = this.size;
  8648. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  8649. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  8650. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  8651. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  8652. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  8653. if ( this.opacity < 1 ) data.opacity = this.opacity;
  8654. if ( this.transparent === true ) data.transparent = this.transparent;
  8655. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  8656. return data;
  8657. },
  8658. clone: function ( material ) {
  8659. if ( material === undefined ) material = new THREE.Material();
  8660. material.name = this.name;
  8661. material.side = this.side;
  8662. material.opacity = this.opacity;
  8663. material.transparent = this.transparent;
  8664. material.blending = this.blending;
  8665. material.blendSrc = this.blendSrc;
  8666. material.blendDst = this.blendDst;
  8667. material.blendEquation = this.blendEquation;
  8668. material.blendSrcAlpha = this.blendSrcAlpha;
  8669. material.blendDstAlpha = this.blendDstAlpha;
  8670. material.blendEquationAlpha = this.blendEquationAlpha;
  8671. material.depthFunc = this.depthFunc;
  8672. material.depthTest = this.depthTest;
  8673. material.depthWrite = this.depthWrite;
  8674. material.polygonOffset = this.polygonOffset;
  8675. material.polygonOffsetFactor = this.polygonOffsetFactor;
  8676. material.polygonOffsetUnits = this.polygonOffsetUnits;
  8677. material.alphaTest = this.alphaTest;
  8678. material.overdraw = this.overdraw;
  8679. material.visible = this.visible;
  8680. return material;
  8681. },
  8682. update: function () {
  8683. this.dispatchEvent( { type: 'update' } );
  8684. },
  8685. dispose: function () {
  8686. this.dispatchEvent( { type: 'dispose' } );
  8687. }
  8688. };
  8689. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  8690. THREE.MaterialIdCount = 0;
  8691. // File:src/materials/LineBasicMaterial.js
  8692. /**
  8693. * @author mrdoob / http://mrdoob.com/
  8694. * @author alteredq / http://alteredqualia.com/
  8695. *
  8696. * parameters = {
  8697. * color: <hex>,
  8698. * opacity: <float>,
  8699. *
  8700. * blending: THREE.NormalBlending,
  8701. * depthTest: <bool>,
  8702. * depthWrite: <bool>,
  8703. *
  8704. * linewidth: <float>,
  8705. * linecap: "round",
  8706. * linejoin: "round",
  8707. *
  8708. * vertexColors: <bool>
  8709. *
  8710. * fog: <bool>
  8711. * }
  8712. */
  8713. THREE.LineBasicMaterial = function ( parameters ) {
  8714. THREE.Material.call( this );
  8715. this.type = 'LineBasicMaterial';
  8716. this.color = new THREE.Color( 0xffffff );
  8717. this.linewidth = 1;
  8718. this.linecap = 'round';
  8719. this.linejoin = 'round';
  8720. this.vertexColors = THREE.NoColors;
  8721. this.fog = true;
  8722. this.setValues( parameters );
  8723. };
  8724. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8725. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  8726. THREE.LineBasicMaterial.prototype.clone = function () {
  8727. var material = new THREE.LineBasicMaterial();
  8728. THREE.Material.prototype.clone.call( this, material );
  8729. material.color.copy( this.color );
  8730. material.linewidth = this.linewidth;
  8731. material.linecap = this.linecap;
  8732. material.linejoin = this.linejoin;
  8733. material.vertexColors = this.vertexColors;
  8734. material.fog = this.fog;
  8735. return material;
  8736. };
  8737. // File:src/materials/LineDashedMaterial.js
  8738. /**
  8739. * @author alteredq / http://alteredqualia.com/
  8740. *
  8741. * parameters = {
  8742. * color: <hex>,
  8743. * opacity: <float>,
  8744. *
  8745. * blending: THREE.NormalBlending,
  8746. * depthTest: <bool>,
  8747. * depthWrite: <bool>,
  8748. *
  8749. * linewidth: <float>,
  8750. *
  8751. * scale: <float>,
  8752. * dashSize: <float>,
  8753. * gapSize: <float>,
  8754. *
  8755. * vertexColors: <bool>
  8756. *
  8757. * fog: <bool>
  8758. * }
  8759. */
  8760. THREE.LineDashedMaterial = function ( parameters ) {
  8761. THREE.Material.call( this );
  8762. this.type = 'LineDashedMaterial';
  8763. this.color = new THREE.Color( 0xffffff );
  8764. this.linewidth = 1;
  8765. this.scale = 1;
  8766. this.dashSize = 3;
  8767. this.gapSize = 1;
  8768. this.vertexColors = false;
  8769. this.fog = true;
  8770. this.setValues( parameters );
  8771. };
  8772. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  8773. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  8774. THREE.LineDashedMaterial.prototype.clone = function () {
  8775. var material = new THREE.LineDashedMaterial();
  8776. THREE.Material.prototype.clone.call( this, material );
  8777. material.color.copy( this.color );
  8778. material.linewidth = this.linewidth;
  8779. material.scale = this.scale;
  8780. material.dashSize = this.dashSize;
  8781. material.gapSize = this.gapSize;
  8782. material.vertexColors = this.vertexColors;
  8783. material.fog = this.fog;
  8784. return material;
  8785. };
  8786. // File:src/materials/MeshBasicMaterial.js
  8787. /**
  8788. * @author mrdoob / http://mrdoob.com/
  8789. * @author alteredq / http://alteredqualia.com/
  8790. *
  8791. * parameters = {
  8792. * color: <hex>,
  8793. * opacity: <float>,
  8794. * map: new THREE.Texture( <Image> ),
  8795. *
  8796. * aoMap: new THREE.Texture( <Image> ),
  8797. * aoMapIntensity: <float>
  8798. *
  8799. * specularMap: new THREE.Texture( <Image> ),
  8800. *
  8801. * alphaMap: new THREE.Texture( <Image> ),
  8802. *
  8803. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8804. * combine: THREE.Multiply,
  8805. * reflectivity: <float>,
  8806. * refractionRatio: <float>,
  8807. *
  8808. * shading: THREE.SmoothShading,
  8809. * blending: THREE.NormalBlending,
  8810. * depthTest: <bool>,
  8811. * depthWrite: <bool>,
  8812. *
  8813. * wireframe: <boolean>,
  8814. * wireframeLinewidth: <float>,
  8815. *
  8816. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8817. *
  8818. * skinning: <bool>,
  8819. * morphTargets: <bool>,
  8820. *
  8821. * fog: <bool>
  8822. * }
  8823. */
  8824. THREE.MeshBasicMaterial = function ( parameters ) {
  8825. THREE.Material.call( this );
  8826. this.type = 'MeshBasicMaterial';
  8827. this.color = new THREE.Color( 0xffffff ); // emissive
  8828. this.map = null;
  8829. this.aoMap = null;
  8830. this.aoMapIntensity = 1.0;
  8831. this.specularMap = null;
  8832. this.alphaMap = null;
  8833. this.envMap = null;
  8834. this.combine = THREE.MultiplyOperation;
  8835. this.reflectivity = 1;
  8836. this.refractionRatio = 0.98;
  8837. this.fog = true;
  8838. this.shading = THREE.SmoothShading;
  8839. this.wireframe = false;
  8840. this.wireframeLinewidth = 1;
  8841. this.wireframeLinecap = 'round';
  8842. this.wireframeLinejoin = 'round';
  8843. this.vertexColors = THREE.NoColors;
  8844. this.skinning = false;
  8845. this.morphTargets = false;
  8846. this.setValues( parameters );
  8847. };
  8848. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8849. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  8850. THREE.MeshBasicMaterial.prototype.clone = function () {
  8851. var material = new THREE.MeshBasicMaterial();
  8852. THREE.Material.prototype.clone.call( this, material );
  8853. material.color.copy( this.color );
  8854. material.map = this.map;
  8855. material.aoMap = this.aoMap;
  8856. material.aoMapIntensity = this.aoMapIntensity;
  8857. material.specularMap = this.specularMap;
  8858. material.alphaMap = this.alphaMap;
  8859. material.envMap = this.envMap;
  8860. material.combine = this.combine;
  8861. material.reflectivity = this.reflectivity;
  8862. material.refractionRatio = this.refractionRatio;
  8863. material.fog = this.fog;
  8864. material.shading = this.shading;
  8865. material.wireframe = this.wireframe;
  8866. material.wireframeLinewidth = this.wireframeLinewidth;
  8867. material.wireframeLinecap = this.wireframeLinecap;
  8868. material.wireframeLinejoin = this.wireframeLinejoin;
  8869. material.vertexColors = this.vertexColors;
  8870. material.skinning = this.skinning;
  8871. material.morphTargets = this.morphTargets;
  8872. return material;
  8873. };
  8874. // File:src/materials/MeshLambertMaterial.js
  8875. /**
  8876. * @author mrdoob / http://mrdoob.com/
  8877. * @author alteredq / http://alteredqualia.com/
  8878. *
  8879. * parameters = {
  8880. * color: <hex>,
  8881. * emissive: <hex>,
  8882. * opacity: <float>,
  8883. *
  8884. * map: new THREE.Texture( <Image> ),
  8885. *
  8886. * specularMap: new THREE.Texture( <Image> ),
  8887. *
  8888. * alphaMap: new THREE.Texture( <Image> ),
  8889. *
  8890. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8891. * combine: THREE.Multiply,
  8892. * reflectivity: <float>,
  8893. * refractionRatio: <float>,
  8894. *
  8895. * shading: THREE.SmoothShading,
  8896. * blending: THREE.NormalBlending,
  8897. * depthTest: <bool>,
  8898. * depthWrite: <bool>,
  8899. *
  8900. * wireframe: <boolean>,
  8901. * wireframeLinewidth: <float>,
  8902. *
  8903. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8904. *
  8905. * skinning: <bool>,
  8906. * morphTargets: <bool>,
  8907. * morphNormals: <bool>,
  8908. *
  8909. * fog: <bool>
  8910. * }
  8911. */
  8912. THREE.MeshLambertMaterial = function ( parameters ) {
  8913. THREE.Material.call( this );
  8914. this.type = 'MeshLambertMaterial';
  8915. this.color = new THREE.Color( 0xffffff ); // diffuse
  8916. this.emissive = new THREE.Color( 0x000000 );
  8917. this.map = null;
  8918. this.specularMap = null;
  8919. this.alphaMap = null;
  8920. this.envMap = null;
  8921. this.combine = THREE.MultiplyOperation;
  8922. this.reflectivity = 1;
  8923. this.refractionRatio = 0.98;
  8924. this.fog = true;
  8925. this.shading = THREE.SmoothShading;
  8926. this.wireframe = false;
  8927. this.wireframeLinewidth = 1;
  8928. this.wireframeLinecap = 'round';
  8929. this.wireframeLinejoin = 'round';
  8930. this.vertexColors = THREE.NoColors;
  8931. this.skinning = false;
  8932. this.morphTargets = false;
  8933. this.morphNormals = false;
  8934. this.setValues( parameters );
  8935. };
  8936. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  8937. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  8938. THREE.MeshLambertMaterial.prototype.clone = function () {
  8939. var material = new THREE.MeshLambertMaterial();
  8940. THREE.Material.prototype.clone.call( this, material );
  8941. material.color.copy( this.color );
  8942. material.emissive.copy( this.emissive );
  8943. material.map = this.map;
  8944. material.specularMap = this.specularMap;
  8945. material.alphaMap = this.alphaMap;
  8946. material.envMap = this.envMap;
  8947. material.combine = this.combine;
  8948. material.reflectivity = this.reflectivity;
  8949. material.refractionRatio = this.refractionRatio;
  8950. material.fog = this.fog;
  8951. material.shading = this.shading;
  8952. material.wireframe = this.wireframe;
  8953. material.wireframeLinewidth = this.wireframeLinewidth;
  8954. material.wireframeLinecap = this.wireframeLinecap;
  8955. material.wireframeLinejoin = this.wireframeLinejoin;
  8956. material.vertexColors = this.vertexColors;
  8957. material.skinning = this.skinning;
  8958. material.morphTargets = this.morphTargets;
  8959. material.morphNormals = this.morphNormals;
  8960. return material;
  8961. };
  8962. // File:src/materials/MeshPhongMaterial.js
  8963. /**
  8964. * @author mrdoob / http://mrdoob.com/
  8965. * @author alteredq / http://alteredqualia.com/
  8966. *
  8967. * parameters = {
  8968. * color: <hex>,
  8969. * emissive: <hex>,
  8970. * specular: <hex>,
  8971. * shininess: <float>,
  8972. * opacity: <float>,
  8973. *
  8974. * map: new THREE.Texture( <Image> ),
  8975. *
  8976. * lightMap: new THREE.Texture( <Image> ),
  8977. * lightMapIntensity: <float>
  8978. *
  8979. * aoMap: new THREE.Texture( <Image> ),
  8980. * aoMapIntensity: <float>
  8981. *
  8982. * emissiveMap: new THREE.Texture( <Image> ),
  8983. *
  8984. * bumpMap: new THREE.Texture( <Image> ),
  8985. * bumpScale: <float>,
  8986. *
  8987. * normalMap: new THREE.Texture( <Image> ),
  8988. * normalScale: <Vector2>,
  8989. *
  8990. * specularMap: new THREE.Texture( <Image> ),
  8991. *
  8992. * alphaMap: new THREE.Texture( <Image> ),
  8993. *
  8994. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8995. * combine: THREE.Multiply,
  8996. * reflectivity: <float>,
  8997. * refractionRatio: <float>,
  8998. *
  8999. * shading: THREE.SmoothShading,
  9000. * blending: THREE.NormalBlending,
  9001. * depthTest: <bool>,
  9002. * depthWrite: <bool>,
  9003. *
  9004. * wireframe: <boolean>,
  9005. * wireframeLinewidth: <float>,
  9006. *
  9007. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9008. *
  9009. * skinning: <bool>,
  9010. * morphTargets: <bool>,
  9011. * morphNormals: <bool>,
  9012. *
  9013. * fog: <bool>
  9014. * }
  9015. */
  9016. THREE.MeshPhongMaterial = function ( parameters ) {
  9017. THREE.Material.call( this );
  9018. this.type = 'MeshPhongMaterial';
  9019. this.color = new THREE.Color( 0xffffff ); // diffuse
  9020. this.emissive = new THREE.Color( 0x000000 );
  9021. this.specular = new THREE.Color( 0x111111 );
  9022. this.shininess = 30;
  9023. this.metal = false;
  9024. this.map = null;
  9025. this.lightMap = null;
  9026. this.lightMapIntensity = 1.0;
  9027. this.aoMap = null;
  9028. this.aoMapIntensity = 1.0;
  9029. this.emissiveMap = null;
  9030. this.bumpMap = null;
  9031. this.bumpScale = 1;
  9032. this.normalMap = null;
  9033. this.normalScale = new THREE.Vector2( 1, 1 );
  9034. this.specularMap = null;
  9035. this.alphaMap = null;
  9036. this.envMap = null;
  9037. this.combine = THREE.MultiplyOperation;
  9038. this.reflectivity = 1;
  9039. this.refractionRatio = 0.98;
  9040. this.fog = true;
  9041. this.shading = THREE.SmoothShading;
  9042. this.wireframe = false;
  9043. this.wireframeLinewidth = 1;
  9044. this.wireframeLinecap = 'round';
  9045. this.wireframeLinejoin = 'round';
  9046. this.vertexColors = THREE.NoColors;
  9047. this.skinning = false;
  9048. this.morphTargets = false;
  9049. this.morphNormals = false;
  9050. this.setValues( parameters );
  9051. };
  9052. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  9053. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  9054. THREE.MeshPhongMaterial.prototype.clone = function () {
  9055. var material = new THREE.MeshPhongMaterial();
  9056. THREE.Material.prototype.clone.call( this, material );
  9057. material.color.copy( this.color );
  9058. material.emissive.copy( this.emissive );
  9059. material.specular.copy( this.specular );
  9060. material.shininess = this.shininess;
  9061. material.metal = this.metal;
  9062. material.map = this.map;
  9063. material.lightMap = this.lightMap;
  9064. material.lightMapIntensity = this.lightMapIntensity;
  9065. material.aoMap = this.aoMap;
  9066. material.aoMapIntensity = this.aoMapIntensity;
  9067. material.emissiveMap = this.emissiveMap;
  9068. material.bumpMap = this.bumpMap;
  9069. material.bumpScale = this.bumpScale;
  9070. material.normalMap = this.normalMap;
  9071. material.normalScale.copy( this.normalScale );
  9072. material.specularMap = this.specularMap;
  9073. material.alphaMap = this.alphaMap;
  9074. material.envMap = this.envMap;
  9075. material.combine = this.combine;
  9076. material.reflectivity = this.reflectivity;
  9077. material.refractionRatio = this.refractionRatio;
  9078. material.fog = this.fog;
  9079. material.shading = this.shading;
  9080. material.wireframe = this.wireframe;
  9081. material.wireframeLinewidth = this.wireframeLinewidth;
  9082. material.wireframeLinecap = this.wireframeLinecap;
  9083. material.wireframeLinejoin = this.wireframeLinejoin;
  9084. material.vertexColors = this.vertexColors;
  9085. material.skinning = this.skinning;
  9086. material.morphTargets = this.morphTargets;
  9087. material.morphNormals = this.morphNormals;
  9088. return material;
  9089. };
  9090. // File:src/materials/MeshDepthMaterial.js
  9091. /**
  9092. * @author mrdoob / http://mrdoob.com/
  9093. * @author alteredq / http://alteredqualia.com/
  9094. *
  9095. * parameters = {
  9096. * opacity: <float>,
  9097. *
  9098. * blending: THREE.NormalBlending,
  9099. * depthTest: <bool>,
  9100. * depthWrite: <bool>,
  9101. *
  9102. * wireframe: <boolean>,
  9103. * wireframeLinewidth: <float>
  9104. * }
  9105. */
  9106. THREE.MeshDepthMaterial = function ( parameters ) {
  9107. THREE.Material.call( this );
  9108. this.type = 'MeshDepthMaterial';
  9109. this.morphTargets = false;
  9110. this.wireframe = false;
  9111. this.wireframeLinewidth = 1;
  9112. this.setValues( parameters );
  9113. };
  9114. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  9115. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  9116. THREE.MeshDepthMaterial.prototype.clone = function () {
  9117. var material = new THREE.MeshDepthMaterial();
  9118. THREE.Material.prototype.clone.call( this, material );
  9119. material.wireframe = this.wireframe;
  9120. material.wireframeLinewidth = this.wireframeLinewidth;
  9121. return material;
  9122. };
  9123. // File:src/materials/MeshNormalMaterial.js
  9124. /**
  9125. * @author mrdoob / http://mrdoob.com/
  9126. *
  9127. * parameters = {
  9128. * opacity: <float>,
  9129. *
  9130. * shading: THREE.FlatShading,
  9131. * blending: THREE.NormalBlending,
  9132. * depthTest: <bool>,
  9133. * depthWrite: <bool>,
  9134. *
  9135. * wireframe: <boolean>,
  9136. * wireframeLinewidth: <float>
  9137. * }
  9138. */
  9139. THREE.MeshNormalMaterial = function ( parameters ) {
  9140. THREE.Material.call( this, parameters );
  9141. this.type = 'MeshNormalMaterial';
  9142. this.wireframe = false;
  9143. this.wireframeLinewidth = 1;
  9144. this.morphTargets = false;
  9145. this.setValues( parameters );
  9146. };
  9147. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  9148. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  9149. THREE.MeshNormalMaterial.prototype.clone = function () {
  9150. var material = new THREE.MeshNormalMaterial();
  9151. THREE.Material.prototype.clone.call( this, material );
  9152. material.wireframe = this.wireframe;
  9153. material.wireframeLinewidth = this.wireframeLinewidth;
  9154. return material;
  9155. };
  9156. // File:src/materials/MeshFaceMaterial.js
  9157. /**
  9158. * @author mrdoob / http://mrdoob.com/
  9159. */
  9160. THREE.MeshFaceMaterial = function ( materials ) {
  9161. this.uuid = THREE.Math.generateUUID();
  9162. this.type = 'MeshFaceMaterial';
  9163. this.materials = materials instanceof Array ? materials : [];
  9164. };
  9165. THREE.MeshFaceMaterial.prototype = {
  9166. constructor: THREE.MeshFaceMaterial,
  9167. toJSON: function () {
  9168. var output = {
  9169. metadata: {
  9170. version: 4.2,
  9171. type: 'material',
  9172. generator: 'MaterialExporter'
  9173. },
  9174. uuid: this.uuid,
  9175. type: this.type,
  9176. materials: []
  9177. };
  9178. for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
  9179. output.materials.push( this.materials[ i ].toJSON() );
  9180. }
  9181. return output;
  9182. },
  9183. clone: function () {
  9184. var material = new THREE.MeshFaceMaterial();
  9185. for ( var i = 0; i < this.materials.length; i ++ ) {
  9186. material.materials.push( this.materials[ i ].clone() );
  9187. }
  9188. return material;
  9189. }
  9190. };
  9191. // File:src/materials/PointCloudMaterial.js
  9192. /**
  9193. * @author mrdoob / http://mrdoob.com/
  9194. * @author alteredq / http://alteredqualia.com/
  9195. *
  9196. * parameters = {
  9197. * color: <hex>,
  9198. * opacity: <float>,
  9199. * map: new THREE.Texture( <Image> ),
  9200. *
  9201. * size: <float>,
  9202. * sizeAttenuation: <bool>,
  9203. *
  9204. * blending: THREE.NormalBlending,
  9205. * depthTest: <bool>,
  9206. * depthWrite: <bool>,
  9207. *
  9208. * vertexColors: <bool>,
  9209. *
  9210. * fog: <bool>
  9211. * }
  9212. */
  9213. THREE.PointCloudMaterial = function ( parameters ) {
  9214. THREE.Material.call( this );
  9215. this.type = 'PointCloudMaterial';
  9216. this.color = new THREE.Color( 0xffffff );
  9217. this.map = null;
  9218. this.size = 1;
  9219. this.sizeAttenuation = true;
  9220. this.vertexColors = THREE.NoColors;
  9221. this.fog = true;
  9222. this.setValues( parameters );
  9223. };
  9224. THREE.PointCloudMaterial.prototype = Object.create( THREE.Material.prototype );
  9225. THREE.PointCloudMaterial.prototype.constructor = THREE.PointCloudMaterial;
  9226. THREE.PointCloudMaterial.prototype.clone = function () {
  9227. var material = new THREE.PointCloudMaterial();
  9228. THREE.Material.prototype.clone.call( this, material );
  9229. material.color.copy( this.color );
  9230. material.map = this.map;
  9231. material.size = this.size;
  9232. material.sizeAttenuation = this.sizeAttenuation;
  9233. material.vertexColors = this.vertexColors;
  9234. material.fog = this.fog;
  9235. return material;
  9236. };
  9237. // backwards compatibility
  9238. THREE.ParticleBasicMaterial = function ( parameters ) {
  9239. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointCloudMaterial.' );
  9240. return new THREE.PointCloudMaterial( parameters );
  9241. };
  9242. THREE.ParticleSystemMaterial = function ( parameters ) {
  9243. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointCloudMaterial.' );
  9244. return new THREE.PointCloudMaterial( parameters );
  9245. };
  9246. // File:src/materials/ShaderMaterial.js
  9247. /**
  9248. * @author alteredq / http://alteredqualia.com/
  9249. *
  9250. * parameters = {
  9251. * defines: { "label" : "value" },
  9252. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  9253. *
  9254. * fragmentShader: <string>,
  9255. * vertexShader: <string>,
  9256. *
  9257. * shading: THREE.SmoothShading,
  9258. * blending: THREE.NormalBlending,
  9259. * depthTest: <bool>,
  9260. * depthWrite: <bool>,
  9261. *
  9262. * wireframe: <boolean>,
  9263. * wireframeLinewidth: <float>,
  9264. *
  9265. * lights: <bool>,
  9266. *
  9267. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9268. *
  9269. * skinning: <bool>,
  9270. * morphTargets: <bool>,
  9271. * morphNormals: <bool>,
  9272. *
  9273. * fog: <bool>
  9274. * }
  9275. */
  9276. THREE.ShaderMaterial = function ( parameters ) {
  9277. THREE.Material.call( this );
  9278. this.type = 'ShaderMaterial';
  9279. this.defines = {};
  9280. this.uniforms = {};
  9281. this.attributes = [];
  9282. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  9283. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  9284. this.shading = THREE.SmoothShading;
  9285. this.linewidth = 1;
  9286. this.wireframe = false;
  9287. this.wireframeLinewidth = 1;
  9288. this.fog = false; // set to use scene fog
  9289. this.lights = false; // set to use scene lights
  9290. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  9291. this.skinning = false; // set to use skinning attribute streams
  9292. this.morphTargets = false; // set to use morph targets
  9293. this.morphNormals = false; // set to use morph normals
  9294. this.derivatives = false; // set to use derivatives
  9295. // When rendered geometry doesn't include these attributes but the material does,
  9296. // use these default values in WebGL. This avoids errors when buffer data is missing.
  9297. this.defaultAttributeValues = {
  9298. 'color': [ 1, 1, 1 ],
  9299. 'uv': [ 0, 0 ],
  9300. 'uv2': [ 0, 0 ]
  9301. };
  9302. this.index0AttributeName = undefined;
  9303. if ( parameters !== undefined ) {
  9304. if ( parameters.attributes !== undefined && Array.isArray( parameters.attributes ) === false ) {
  9305. console.warn( 'THREE.ShaderMaterial: attributes should now be an array of attribute names.' );
  9306. parameters.attributes = Object.keys( parameters.attributes );
  9307. }
  9308. this.setValues( parameters );
  9309. }
  9310. };
  9311. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  9312. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  9313. THREE.ShaderMaterial.prototype.clone = function ( material ) {
  9314. if ( material === undefined ) material = new THREE.ShaderMaterial();
  9315. THREE.Material.prototype.clone.call( this, material );
  9316. material.fragmentShader = this.fragmentShader;
  9317. material.vertexShader = this.vertexShader;
  9318. material.uniforms = THREE.UniformsUtils.clone( this.uniforms );
  9319. material.attributes = this.attributes;
  9320. material.defines = this.defines;
  9321. material.shading = this.shading;
  9322. material.wireframe = this.wireframe;
  9323. material.wireframeLinewidth = this.wireframeLinewidth;
  9324. material.fog = this.fog;
  9325. material.lights = this.lights;
  9326. material.vertexColors = this.vertexColors;
  9327. material.skinning = this.skinning;
  9328. material.morphTargets = this.morphTargets;
  9329. material.morphNormals = this.morphNormals;
  9330. return material;
  9331. };
  9332. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  9333. var data = THREE.Material.prototype.toJSON.call( this, meta );
  9334. data.uniforms = this.uniforms;
  9335. data.attributes = this.attributes;
  9336. data.vertexShader = this.vertexShader;
  9337. data.fragmentShader = this.fragmentShader;
  9338. return data;
  9339. };
  9340. // File:src/materials/RawShaderMaterial.js
  9341. /**
  9342. * @author mrdoob / http://mrdoob.com/
  9343. */
  9344. THREE.RawShaderMaterial = function ( parameters ) {
  9345. THREE.ShaderMaterial.call( this, parameters );
  9346. this.type = 'RawShaderMaterial';
  9347. };
  9348. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  9349. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  9350. THREE.RawShaderMaterial.prototype.clone = function () {
  9351. var material = new THREE.RawShaderMaterial();
  9352. THREE.ShaderMaterial.prototype.clone.call( this, material );
  9353. return material;
  9354. };
  9355. // File:src/materials/SpriteMaterial.js
  9356. /**
  9357. * @author alteredq / http://alteredqualia.com/
  9358. *
  9359. * parameters = {
  9360. * color: <hex>,
  9361. * opacity: <float>,
  9362. * map: new THREE.Texture( <Image> ),
  9363. *
  9364. * blending: THREE.NormalBlending,
  9365. * depthTest: <bool>,
  9366. * depthWrite: <bool>,
  9367. *
  9368. * uvOffset: new THREE.Vector2(),
  9369. * uvScale: new THREE.Vector2(),
  9370. *
  9371. * fog: <bool>
  9372. * }
  9373. */
  9374. THREE.SpriteMaterial = function ( parameters ) {
  9375. THREE.Material.call( this );
  9376. this.type = 'SpriteMaterial';
  9377. this.color = new THREE.Color( 0xffffff );
  9378. this.map = null;
  9379. this.rotation = 0;
  9380. this.fog = false;
  9381. // set parameters
  9382. this.setValues( parameters );
  9383. };
  9384. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  9385. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  9386. THREE.SpriteMaterial.prototype.clone = function () {
  9387. var material = new THREE.SpriteMaterial();
  9388. THREE.Material.prototype.clone.call( this, material );
  9389. material.color.copy( this.color );
  9390. material.map = this.map;
  9391. material.rotation = this.rotation;
  9392. material.fog = this.fog;
  9393. return material;
  9394. };
  9395. // File:src/textures/Texture.js
  9396. /**
  9397. * @author mrdoob / http://mrdoob.com/
  9398. * @author alteredq / http://alteredqualia.com/
  9399. * @author szimek / https://github.com/szimek/
  9400. */
  9401. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9402. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  9403. this.uuid = THREE.Math.generateUUID();
  9404. this.name = '';
  9405. this.sourceFile = '';
  9406. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  9407. this.mipmaps = [];
  9408. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  9409. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  9410. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  9411. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  9412. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  9413. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  9414. this.format = format !== undefined ? format : THREE.RGBAFormat;
  9415. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  9416. this.offset = new THREE.Vector2( 0, 0 );
  9417. this.repeat = new THREE.Vector2( 1, 1 );
  9418. this.generateMipmaps = true;
  9419. this.premultiplyAlpha = false;
  9420. this.flipY = true;
  9421. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  9422. this._needsUpdate = false;
  9423. this.onUpdate = null;
  9424. };
  9425. THREE.Texture.DEFAULT_IMAGE = undefined;
  9426. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  9427. THREE.Texture.prototype = {
  9428. constructor: THREE.Texture,
  9429. get needsUpdate () {
  9430. return this._needsUpdate;
  9431. },
  9432. set needsUpdate ( value ) {
  9433. if ( value === true ) this.update();
  9434. this._needsUpdate = value;
  9435. },
  9436. clone: function ( texture ) {
  9437. if ( texture === undefined ) texture = new THREE.Texture();
  9438. texture.image = this.image;
  9439. texture.mipmaps = this.mipmaps.slice( 0 );
  9440. texture.mapping = this.mapping;
  9441. texture.wrapS = this.wrapS;
  9442. texture.wrapT = this.wrapT;
  9443. texture.magFilter = this.magFilter;
  9444. texture.minFilter = this.minFilter;
  9445. texture.anisotropy = this.anisotropy;
  9446. texture.format = this.format;
  9447. texture.type = this.type;
  9448. texture.offset.copy( this.offset );
  9449. texture.repeat.copy( this.repeat );
  9450. texture.generateMipmaps = this.generateMipmaps;
  9451. texture.premultiplyAlpha = this.premultiplyAlpha;
  9452. texture.flipY = this.flipY;
  9453. texture.unpackAlignment = this.unpackAlignment;
  9454. return texture;
  9455. },
  9456. toJSON: function ( meta ) {
  9457. if ( meta.textures[ this.uuid ] !== undefined ) {
  9458. return meta.textures[ this.uuid ];
  9459. }
  9460. function getDataURL( image ) {
  9461. var canvas;
  9462. if ( image.toDataURL !== undefined ) {
  9463. canvas = image;
  9464. } else {
  9465. canvas = document.createElement( 'canvas' );
  9466. canvas.width = image.width;
  9467. canvas.height = image.height;
  9468. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  9469. }
  9470. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  9471. return canvas.toDataURL( 'image/jpeg', 0.6 );
  9472. } else {
  9473. return canvas.toDataURL( 'image/png' );
  9474. }
  9475. }
  9476. var output = {
  9477. metadata: {
  9478. version: 4.4,
  9479. type: 'Texture',
  9480. generator: 'Texture.toJSON'
  9481. },
  9482. uuid: this.uuid,
  9483. name: this.name,
  9484. mapping: this.mapping,
  9485. repeat: [ this.repeat.x, this.repeat.y ],
  9486. offset: [ this.offset.x, this.offset.y ],
  9487. wrap: [ this.wrapS, this.wrapT ],
  9488. minFilter: this.minFilter,
  9489. magFilter: this.magFilter,
  9490. anisotropy: this.anisotropy
  9491. };
  9492. if ( this.image !== undefined ) {
  9493. // TODO: Move to THREE.Image
  9494. var image = this.image;
  9495. if ( image.uuid === undefined ) {
  9496. image.uuid = THREE.Math.generateUUID(); // UGH
  9497. }
  9498. if ( meta.images[ image.uuid ] === undefined ) {
  9499. meta.images[ image.uuid ] = {
  9500. uuid: image.uuid,
  9501. url: getDataURL( image )
  9502. };
  9503. }
  9504. output.image = image.uuid;
  9505. }
  9506. meta.textures[ this.uuid ] = output;
  9507. return output;
  9508. },
  9509. update: function () {
  9510. this.dispatchEvent( { type: 'update' } );
  9511. },
  9512. dispose: function () {
  9513. this.dispatchEvent( { type: 'dispose' } );
  9514. }
  9515. };
  9516. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  9517. THREE.TextureIdCount = 0;
  9518. // File:src/textures/CubeTexture.js
  9519. /**
  9520. * @author mrdoob / http://mrdoob.com/
  9521. */
  9522. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9523. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  9524. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9525. this.images = images;
  9526. this.flipY = false;
  9527. };
  9528. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  9529. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  9530. THREE.CubeTexture.clone = function ( texture ) {
  9531. if ( texture === undefined ) texture = new THREE.CubeTexture();
  9532. THREE.Texture.prototype.clone.call( this, texture );
  9533. texture.images = this.images;
  9534. return texture;
  9535. };
  9536. // File:src/textures/CompressedTexture.js
  9537. /**
  9538. * @author alteredq / http://alteredqualia.com/
  9539. */
  9540. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9541. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9542. this.image = { width: width, height: height };
  9543. this.mipmaps = mipmaps;
  9544. // no flipping for cube textures
  9545. // (also flipping doesn't work for compressed textures )
  9546. this.flipY = false;
  9547. // can't generate mipmaps for compressed textures
  9548. // mips must be embedded in DDS files
  9549. this.generateMipmaps = false;
  9550. };
  9551. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  9552. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  9553. THREE.CompressedTexture.prototype.clone = function () {
  9554. var texture = new THREE.CompressedTexture();
  9555. THREE.Texture.prototype.clone.call( this, texture );
  9556. return texture;
  9557. };
  9558. // File:src/textures/DataTexture.js
  9559. /**
  9560. * @author alteredq / http://alteredqualia.com/
  9561. */
  9562. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9563. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9564. this.image = { data: data, width: width, height: height };
  9565. };
  9566. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  9567. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  9568. THREE.DataTexture.prototype.clone = function () {
  9569. var texture = new THREE.DataTexture();
  9570. THREE.Texture.prototype.clone.call( this, texture );
  9571. return texture;
  9572. };
  9573. // File:src/textures/VideoTexture.js
  9574. /**
  9575. * @author mrdoob / http://mrdoob.com/
  9576. */
  9577. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9578. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9579. this.generateMipmaps = false;
  9580. var scope = this;
  9581. var update = function () {
  9582. requestAnimationFrame( update );
  9583. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  9584. scope.needsUpdate = true;
  9585. }
  9586. };
  9587. update();
  9588. };
  9589. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  9590. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  9591. // File:src/objects/Group.js
  9592. /**
  9593. * @author mrdoob / http://mrdoob.com/
  9594. */
  9595. THREE.Group = function () {
  9596. THREE.Object3D.call( this );
  9597. this.type = 'Group';
  9598. };
  9599. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  9600. THREE.Group.prototype.constructor = THREE.Group;
  9601. THREE.Group.prototype.clone = function ( object ) {
  9602. if ( object === undefined ) object = new THREE.Group();
  9603. THREE.Object3D.prototype.clone.call( this, object );
  9604. return object;
  9605. };
  9606. // File:src/objects/PointCloud.js
  9607. /**
  9608. * @author alteredq / http://alteredqualia.com/
  9609. */
  9610. THREE.PointCloud = function ( geometry, material ) {
  9611. THREE.Object3D.call( this );
  9612. this.type = 'PointCloud';
  9613. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9614. this.material = material !== undefined ? material : new THREE.PointCloudMaterial( { color: Math.random() * 0xffffff } );
  9615. };
  9616. THREE.PointCloud.prototype = Object.create( THREE.Object3D.prototype );
  9617. THREE.PointCloud.prototype.constructor = THREE.PointCloud;
  9618. THREE.PointCloud.prototype.raycast = ( function () {
  9619. var inverseMatrix = new THREE.Matrix4();
  9620. var ray = new THREE.Ray();
  9621. return function ( raycaster, intersects ) {
  9622. var object = this;
  9623. var geometry = object.geometry;
  9624. var threshold = raycaster.params.PointCloud.threshold;
  9625. inverseMatrix.getInverse( this.matrixWorld );
  9626. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9627. if ( geometry.boundingBox !== null ) {
  9628. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  9629. return;
  9630. }
  9631. }
  9632. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  9633. var localThresholdSq = localThreshold * localThreshold;
  9634. var position = new THREE.Vector3();
  9635. var testPoint = function ( point, index ) {
  9636. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  9637. if ( rayPointDistanceSq < localThresholdSq ) {
  9638. var intersectPoint = ray.closestPointToPoint( point );
  9639. intersectPoint.applyMatrix4( object.matrixWorld );
  9640. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  9641. if ( distance < raycaster.near || distance > raycaster.far ) return;
  9642. intersects.push( {
  9643. distance: distance,
  9644. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  9645. point: intersectPoint.clone(),
  9646. index: index,
  9647. face: null,
  9648. object: object
  9649. } );
  9650. }
  9651. };
  9652. if ( geometry instanceof THREE.BufferGeometry ) {
  9653. var attributes = geometry.attributes;
  9654. var positions = attributes.position.array;
  9655. if ( attributes.index !== undefined ) {
  9656. var indices = attributes.index.array;
  9657. var offsets = geometry.drawcalls;
  9658. if ( offsets.length === 0 ) {
  9659. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9660. }
  9661. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  9662. var offset = offsets[ oi ];
  9663. var start = offset.start;
  9664. var count = offset.count;
  9665. var index = offset.index;
  9666. for ( var i = start, il = start + count; i < il; i ++ ) {
  9667. var a = index + indices[ i ];
  9668. position.fromArray( positions, a * 3 );
  9669. testPoint( position, a );
  9670. }
  9671. }
  9672. } else {
  9673. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  9674. position.fromArray( positions, i * 3 );
  9675. testPoint( position, i );
  9676. }
  9677. }
  9678. } else {
  9679. var vertices = geometry.vertices;
  9680. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  9681. testPoint( vertices[ i ], i );
  9682. }
  9683. }
  9684. };
  9685. }() );
  9686. THREE.PointCloud.prototype.clone = function ( object ) {
  9687. if ( object === undefined ) object = new THREE.PointCloud( this.geometry, this.material );
  9688. THREE.Object3D.prototype.clone.call( this, object );
  9689. return object;
  9690. };
  9691. THREE.PointCloud.prototype.toJSON = function ( meta ) {
  9692. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9693. // only serialize if not in meta geometries cache
  9694. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9695. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9696. }
  9697. // only serialize if not in meta materials cache
  9698. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9699. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9700. }
  9701. data.object.geometry = this.geometry.uuid;
  9702. data.object.material = this.material.uuid;
  9703. return data;
  9704. };
  9705. // Backwards compatibility
  9706. THREE.ParticleSystem = function ( geometry, material ) {
  9707. console.warn( 'THREE.ParticleSystem has been renamed to THREE.PointCloud.' );
  9708. return new THREE.PointCloud( geometry, material );
  9709. };
  9710. // File:src/objects/Line.js
  9711. /**
  9712. * @author mrdoob / http://mrdoob.com/
  9713. */
  9714. THREE.Line = function ( geometry, material, mode ) {
  9715. if ( mode === 1 ) {
  9716. console.error( 'THREE.Line: THREE.LinePieces mode has been removed. Use THREE.LineSegments instead.' );
  9717. }
  9718. THREE.Object3D.call( this );
  9719. this.type = 'Line';
  9720. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9721. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  9722. };
  9723. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  9724. THREE.Line.prototype.constructor = THREE.Line;
  9725. THREE.Line.prototype.raycast = ( function () {
  9726. var inverseMatrix = new THREE.Matrix4();
  9727. var ray = new THREE.Ray();
  9728. var sphere = new THREE.Sphere();
  9729. return function ( raycaster, intersects ) {
  9730. var precision = raycaster.linePrecision;
  9731. var precisionSq = precision * precision;
  9732. var geometry = this.geometry;
  9733. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9734. // Checking boundingSphere distance to ray
  9735. sphere.copy( geometry.boundingSphere );
  9736. sphere.applyMatrix4( this.matrixWorld );
  9737. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  9738. return;
  9739. }
  9740. inverseMatrix.getInverse( this.matrixWorld );
  9741. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9742. var vStart = new THREE.Vector3();
  9743. var vEnd = new THREE.Vector3();
  9744. var interSegment = new THREE.Vector3();
  9745. var interRay = new THREE.Vector3();
  9746. var step = this instanceof THREE.LineSegments ? 2 : 1;
  9747. if ( geometry instanceof THREE.BufferGeometry ) {
  9748. var attributes = geometry.attributes;
  9749. if ( attributes.index !== undefined ) {
  9750. var indices = attributes.index.array;
  9751. var positions = attributes.position.array;
  9752. var offsets = geometry.drawcalls;
  9753. if ( offsets.length === 0 ) {
  9754. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9755. }
  9756. for ( var oi = 0; oi < offsets.length; oi ++) {
  9757. var start = offsets[ oi ].start;
  9758. var count = offsets[ oi ].count;
  9759. var index = offsets[ oi ].index;
  9760. for ( var i = start; i < start + count - 1; i += step ) {
  9761. var a = index + indices[ i ];
  9762. var b = index + indices[ i + 1 ];
  9763. vStart.fromArray( positions, a * 3 );
  9764. vEnd.fromArray( positions, b * 3 );
  9765. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9766. if ( distSq > precisionSq ) continue;
  9767. var distance = ray.origin.distanceTo( interRay );
  9768. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9769. intersects.push( {
  9770. distance: distance,
  9771. // What do we want? intersection point on the ray or on the segment??
  9772. // point: raycaster.ray.at( distance ),
  9773. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9774. index: i,
  9775. offsetIndex: oi,
  9776. face: null,
  9777. faceIndex: null,
  9778. object: this
  9779. } );
  9780. }
  9781. }
  9782. } else {
  9783. var positions = attributes.position.array;
  9784. for ( var i = 0; i < positions.length / 3 - 1; i += step ) {
  9785. vStart.fromArray( positions, 3 * i );
  9786. vEnd.fromArray( positions, 3 * i + 3 );
  9787. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9788. if ( distSq > precisionSq ) continue;
  9789. var distance = ray.origin.distanceTo( interRay );
  9790. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9791. intersects.push( {
  9792. distance: distance,
  9793. // What do we want? intersection point on the ray or on the segment??
  9794. // point: raycaster.ray.at( distance ),
  9795. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9796. index: i,
  9797. face: null,
  9798. faceIndex: null,
  9799. object: this
  9800. } );
  9801. }
  9802. }
  9803. } else if ( geometry instanceof THREE.Geometry ) {
  9804. var vertices = geometry.vertices;
  9805. var nbVertices = vertices.length;
  9806. for ( var i = 0; i < nbVertices - 1; i += step ) {
  9807. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  9808. if ( distSq > precisionSq ) continue;
  9809. var distance = ray.origin.distanceTo( interRay );
  9810. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9811. intersects.push( {
  9812. distance: distance,
  9813. // What do we want? intersection point on the ray or on the segment??
  9814. // point: raycaster.ray.at( distance ),
  9815. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9816. index: i,
  9817. face: null,
  9818. faceIndex: null,
  9819. object: this
  9820. } );
  9821. }
  9822. }
  9823. };
  9824. }() );
  9825. THREE.Line.prototype.clone = function ( object ) {
  9826. if ( object === undefined ) object = new THREE[ this.type ]( this.geometry, this.material );
  9827. THREE.Object3D.prototype.clone.call( this, object );
  9828. return object;
  9829. };
  9830. THREE.Line.prototype.toJSON = function ( meta ) {
  9831. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9832. // only serialize if not in meta geometries cache
  9833. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9834. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9835. }
  9836. // only serialize if not in meta materials cache
  9837. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9838. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9839. }
  9840. data.object.geometry = this.geometry.uuid;
  9841. data.object.material = this.material.uuid;
  9842. return data;
  9843. };
  9844. // DEPRECATED
  9845. THREE.LineStrip = 0;
  9846. THREE.LinePieces = 1;
  9847. // File:src/objects/LineSegments.js
  9848. /**
  9849. * @author mrdoob / http://mrdoob.com/
  9850. */
  9851. THREE.LineSegments = function ( geometry, material ) {
  9852. THREE.Line.call( this, geometry, material );
  9853. this.type = 'LineSegments';
  9854. };
  9855. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  9856. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  9857. THREE.LineSegments.prototype.clone = function ( object ) {
  9858. if ( object === undefined ) object = new THREE.LineSegments( this.geometry, this.material );
  9859. THREE.Line.prototype.clone.call( this, object );
  9860. return object;
  9861. };
  9862. // File:src/objects/Mesh.js
  9863. /**
  9864. * @author mrdoob / http://mrdoob.com/
  9865. * @author alteredq / http://alteredqualia.com/
  9866. * @author mikael emtinger / http://gomo.se/
  9867. * @author jonobr1 / http://jonobr1.com/
  9868. */
  9869. THREE.Mesh = function ( geometry, material ) {
  9870. THREE.Object3D.call( this );
  9871. this.type = 'Mesh';
  9872. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9873. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  9874. this.updateMorphTargets();
  9875. };
  9876. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  9877. THREE.Mesh.prototype.constructor = THREE.Mesh;
  9878. THREE.Mesh.prototype.updateMorphTargets = function () {
  9879. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  9880. this.morphTargetBase = - 1;
  9881. this.morphTargetForcedOrder = [];
  9882. this.morphTargetInfluences = [];
  9883. this.morphTargetDictionary = {};
  9884. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  9885. this.morphTargetInfluences.push( 0 );
  9886. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  9887. }
  9888. }
  9889. };
  9890. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  9891. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  9892. return this.morphTargetDictionary[ name ];
  9893. }
  9894. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  9895. return 0;
  9896. };
  9897. THREE.Mesh.prototype.raycast = ( function () {
  9898. var inverseMatrix = new THREE.Matrix4();
  9899. var ray = new THREE.Ray();
  9900. var sphere = new THREE.Sphere();
  9901. var vA = new THREE.Vector3();
  9902. var vB = new THREE.Vector3();
  9903. var vC = new THREE.Vector3();
  9904. var tempA = new THREE.Vector3();
  9905. var tempB = new THREE.Vector3();
  9906. var tempC = new THREE.Vector3();
  9907. return function ( raycaster, intersects ) {
  9908. var geometry = this.geometry;
  9909. var material = this.material;
  9910. if ( material === undefined ) return;
  9911. // Checking boundingSphere distance to ray
  9912. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9913. sphere.copy( geometry.boundingSphere );
  9914. sphere.applyMatrix4( this.matrixWorld );
  9915. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  9916. return;
  9917. }
  9918. // Check boundingBox before continuing
  9919. inverseMatrix.getInverse( this.matrixWorld );
  9920. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9921. if ( geometry.boundingBox !== null ) {
  9922. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  9923. return;
  9924. }
  9925. }
  9926. var a, b, c;
  9927. if ( geometry instanceof THREE.BufferGeometry ) {
  9928. var attributes = geometry.attributes;
  9929. if ( attributes.index !== undefined ) {
  9930. var indices = attributes.index.array;
  9931. var positions = attributes.position.array;
  9932. var offsets = geometry.drawcalls;
  9933. if ( offsets.length === 0 ) {
  9934. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9935. }
  9936. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  9937. var start = offsets[ oi ].start;
  9938. var count = offsets[ oi ].count;
  9939. var index = offsets[ oi ].index;
  9940. for ( var i = start, il = start + count; i < il; i += 3 ) {
  9941. a = index + indices[ i ];
  9942. b = index + indices[ i + 1 ];
  9943. c = index + indices[ i + 2 ];
  9944. vA.fromArray( positions, a * 3 );
  9945. vB.fromArray( positions, b * 3 );
  9946. vC.fromArray( positions, c * 3 );
  9947. if ( material.side === THREE.BackSide ) {
  9948. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  9949. } else {
  9950. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  9951. }
  9952. if ( intersectionPoint === null ) continue;
  9953. intersectionPoint.applyMatrix4( this.matrixWorld );
  9954. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  9955. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9956. intersects.push( {
  9957. distance: distance,
  9958. point: intersectionPoint,
  9959. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  9960. faceIndex: Math.floor( i / 3 ), // triangle number in indices buffer semantics
  9961. object: this
  9962. } );
  9963. }
  9964. }
  9965. } else {
  9966. var positions = attributes.position.array;
  9967. for ( var i = 0, j = 0, il = positions.length; i < il; i += 3, j += 9 ) {
  9968. a = i;
  9969. b = i + 1;
  9970. c = i + 2;
  9971. vA.fromArray( positions, j );
  9972. vB.fromArray( positions, j + 3 );
  9973. vC.fromArray( positions, j + 6 );
  9974. if ( material.side === THREE.BackSide ) {
  9975. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  9976. } else {
  9977. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  9978. }
  9979. if ( intersectionPoint === null ) continue;
  9980. intersectionPoint.applyMatrix4( this.matrixWorld );
  9981. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  9982. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9983. intersects.push( {
  9984. distance: distance,
  9985. point: intersectionPoint,
  9986. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  9987. index: Math.floor(i/3), // triangle number in positions buffer semantics
  9988. object: this
  9989. } );
  9990. }
  9991. }
  9992. } else if ( geometry instanceof THREE.Geometry ) {
  9993. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  9994. var materials = isFaceMaterial === true ? material.materials : null;
  9995. var vertices = geometry.vertices;
  9996. var faces = geometry.faces;
  9997. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  9998. var face = faces[ f ];
  9999. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  10000. if ( faceMaterial === undefined ) continue;
  10001. a = vertices[ face.a ];
  10002. b = vertices[ face.b ];
  10003. c = vertices[ face.c ];
  10004. if ( faceMaterial.morphTargets === true ) {
  10005. var morphTargets = geometry.morphTargets;
  10006. var morphInfluences = this.morphTargetInfluences;
  10007. vA.set( 0, 0, 0 );
  10008. vB.set( 0, 0, 0 );
  10009. vC.set( 0, 0, 0 );
  10010. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  10011. var influence = morphInfluences[ t ];
  10012. if ( influence === 0 ) continue;
  10013. var targets = morphTargets[ t ].vertices;
  10014. vA.addScaledVector( tempA.subVectors( targets[ face.a ], a ), influence );
  10015. vB.addScaledVector( tempB.subVectors( targets[ face.b ], b ), influence );
  10016. vC.addScaledVector( tempC.subVectors( targets[ face.c ], c ), influence );
  10017. }
  10018. vA.add( a );
  10019. vB.add( b );
  10020. vC.add( c );
  10021. a = vA;
  10022. b = vB;
  10023. c = vC;
  10024. }
  10025. if ( faceMaterial.side === THREE.BackSide ) {
  10026. var intersectionPoint = ray.intersectTriangle( c, b, a, true );
  10027. } else {
  10028. var intersectionPoint = ray.intersectTriangle( a, b, c, faceMaterial.side !== THREE.DoubleSide );
  10029. }
  10030. if ( intersectionPoint === null ) continue;
  10031. intersectionPoint.applyMatrix4( this.matrixWorld );
  10032. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10033. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10034. intersects.push( {
  10035. distance: distance,
  10036. point: intersectionPoint,
  10037. face: face,
  10038. faceIndex: f,
  10039. object: this
  10040. } );
  10041. }
  10042. }
  10043. };
  10044. }() );
  10045. THREE.Mesh.prototype.clone = function ( object, recursive ) {
  10046. if ( object === undefined ) object = new THREE.Mesh( this.geometry, this.material );
  10047. THREE.Object3D.prototype.clone.call( this, object, recursive );
  10048. return object;
  10049. };
  10050. THREE.Mesh.prototype.toJSON = function ( meta ) {
  10051. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10052. // only serialize if not in meta geometries cache
  10053. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  10054. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  10055. }
  10056. // only serialize if not in meta materials cache
  10057. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10058. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  10059. }
  10060. data.object.geometry = this.geometry.uuid;
  10061. data.object.material = this.material.uuid;
  10062. return data;
  10063. };
  10064. // File:src/objects/Bone.js
  10065. /**
  10066. * @author mikael emtinger / http://gomo.se/
  10067. * @author alteredq / http://alteredqualia.com/
  10068. * @author ikerr / http://verold.com
  10069. */
  10070. THREE.Bone = function ( skin ) {
  10071. THREE.Object3D.call( this );
  10072. this.type = 'Bone';
  10073. this.skin = skin;
  10074. };
  10075. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  10076. THREE.Bone.prototype.constructor = THREE.Bone;
  10077. THREE.Bone.prototype.clone = function ( object ) {
  10078. if ( object === undefined ) object = new THREE.Bone( this.skin );
  10079. THREE.Object3D.prototype.clone.call( this, object );
  10080. object.skin = this.skin;
  10081. return object;
  10082. };
  10083. // File:src/objects/Skeleton.js
  10084. /**
  10085. * @author mikael emtinger / http://gomo.se/
  10086. * @author alteredq / http://alteredqualia.com/
  10087. * @author michael guerrero / http://realitymeltdown.com
  10088. * @author ikerr / http://verold.com
  10089. */
  10090. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  10091. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  10092. this.identityMatrix = new THREE.Matrix4();
  10093. // copy the bone array
  10094. bones = bones || [];
  10095. this.bones = bones.slice( 0 );
  10096. // create a bone texture or an array of floats
  10097. if ( this.useVertexTexture ) {
  10098. // layout (1 matrix = 4 pixels)
  10099. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  10100. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  10101. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  10102. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  10103. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  10104. var size = THREE.Math.nextPowerOfTwo( Math.sqrt( this.bones.length * 4 ) ); // 4 pixels needed for 1 matrix
  10105. this.boneTextureWidth = size;
  10106. this.boneTextureHeight = size;
  10107. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  10108. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  10109. this.boneTexture.minFilter = THREE.NearestFilter;
  10110. this.boneTexture.magFilter = THREE.NearestFilter;
  10111. this.boneTexture.generateMipmaps = false;
  10112. this.boneTexture.flipY = false;
  10113. } else {
  10114. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  10115. }
  10116. // use the supplied bone inverses or calculate the inverses
  10117. if ( boneInverses === undefined ) {
  10118. this.calculateInverses();
  10119. } else {
  10120. if ( this.bones.length === boneInverses.length ) {
  10121. this.boneInverses = boneInverses.slice( 0 );
  10122. } else {
  10123. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  10124. this.boneInverses = [];
  10125. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10126. this.boneInverses.push( new THREE.Matrix4() );
  10127. }
  10128. }
  10129. }
  10130. };
  10131. THREE.Skeleton.prototype.calculateInverses = function () {
  10132. this.boneInverses = [];
  10133. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10134. var inverse = new THREE.Matrix4();
  10135. if ( this.bones[ b ] ) {
  10136. inverse.getInverse( this.bones[ b ].matrixWorld );
  10137. }
  10138. this.boneInverses.push( inverse );
  10139. }
  10140. };
  10141. THREE.Skeleton.prototype.pose = function () {
  10142. var bone;
  10143. // recover the bind-time world matrices
  10144. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10145. bone = this.bones[ b ];
  10146. if ( bone ) {
  10147. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  10148. }
  10149. }
  10150. // compute the local matrices, positions, rotations and scales
  10151. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10152. bone = this.bones[ b ];
  10153. if ( bone ) {
  10154. if ( bone.parent ) {
  10155. bone.matrix.getInverse( bone.parent.matrixWorld );
  10156. bone.matrix.multiply( bone.matrixWorld );
  10157. } else {
  10158. bone.matrix.copy( bone.matrixWorld );
  10159. }
  10160. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  10161. }
  10162. }
  10163. };
  10164. THREE.Skeleton.prototype.update = ( function () {
  10165. var offsetMatrix = new THREE.Matrix4();
  10166. return function () {
  10167. // flatten bone matrices to array
  10168. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10169. // compute the offset between the current and the original transform
  10170. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  10171. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  10172. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  10173. }
  10174. if ( this.useVertexTexture ) {
  10175. this.boneTexture.needsUpdate = true;
  10176. }
  10177. };
  10178. } )();
  10179. THREE.Skeleton.prototype.clone = function () {
  10180. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  10181. };
  10182. // File:src/objects/SkinnedMesh.js
  10183. /**
  10184. * @author mikael emtinger / http://gomo.se/
  10185. * @author alteredq / http://alteredqualia.com/
  10186. * @author ikerr / http://verold.com
  10187. */
  10188. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  10189. THREE.Mesh.call( this, geometry, material );
  10190. this.type = 'SkinnedMesh';
  10191. this.bindMode = "attached";
  10192. this.bindMatrix = new THREE.Matrix4();
  10193. this.bindMatrixInverse = new THREE.Matrix4();
  10194. // init bones
  10195. // TODO: remove bone creation as there is no reason (other than
  10196. // convenience) for THREE.SkinnedMesh to do this.
  10197. var bones = [];
  10198. if ( this.geometry && this.geometry.bones !== undefined ) {
  10199. var bone, gbone, p, q, s;
  10200. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10201. gbone = this.geometry.bones[ b ];
  10202. p = gbone.pos;
  10203. q = gbone.rotq;
  10204. s = gbone.scl;
  10205. bone = new THREE.Bone( this );
  10206. bones.push( bone );
  10207. bone.name = gbone.name;
  10208. bone.position.set( p[ 0 ], p[ 1 ], p[ 2 ] );
  10209. bone.quaternion.set( q[ 0 ], q[ 1 ], q[ 2 ], q[ 3 ] );
  10210. if ( s !== undefined ) {
  10211. bone.scale.set( s[ 0 ], s[ 1 ], s[ 2 ] );
  10212. } else {
  10213. bone.scale.set( 1, 1, 1 );
  10214. }
  10215. }
  10216. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10217. gbone = this.geometry.bones[ b ];
  10218. if ( gbone.parent !== - 1 ) {
  10219. bones[ gbone.parent ].add( bones[ b ] );
  10220. } else {
  10221. this.add( bones[ b ] );
  10222. }
  10223. }
  10224. }
  10225. this.normalizeSkinWeights();
  10226. this.updateMatrixWorld( true );
  10227. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ) );
  10228. };
  10229. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  10230. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  10231. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  10232. this.skeleton = skeleton;
  10233. if ( bindMatrix === undefined ) {
  10234. this.updateMatrixWorld( true );
  10235. bindMatrix = this.matrixWorld;
  10236. }
  10237. this.bindMatrix.copy( bindMatrix );
  10238. this.bindMatrixInverse.getInverse( bindMatrix );
  10239. };
  10240. THREE.SkinnedMesh.prototype.pose = function () {
  10241. this.skeleton.pose();
  10242. };
  10243. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  10244. if ( this.geometry instanceof THREE.Geometry ) {
  10245. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  10246. var sw = this.geometry.skinWeights[ i ];
  10247. var scale = 1.0 / sw.lengthManhattan();
  10248. if ( scale !== Infinity ) {
  10249. sw.multiplyScalar( scale );
  10250. } else {
  10251. sw.set( 1 ); // this will be normalized by the shader anyway
  10252. }
  10253. }
  10254. } else {
  10255. // skinning weights assumed to be normalized for THREE.BufferGeometry
  10256. }
  10257. };
  10258. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  10259. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  10260. if ( this.bindMode === "attached" ) {
  10261. this.bindMatrixInverse.getInverse( this.matrixWorld );
  10262. } else if ( this.bindMode === "detached" ) {
  10263. this.bindMatrixInverse.getInverse( this.bindMatrix );
  10264. } else {
  10265. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  10266. }
  10267. };
  10268. THREE.SkinnedMesh.prototype.clone = function( object ) {
  10269. if ( object === undefined ) {
  10270. object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
  10271. }
  10272. THREE.Mesh.prototype.clone.call( this, object );
  10273. return object;
  10274. };
  10275. // File:src/objects/MorphAnimMesh.js
  10276. /**
  10277. * @author alteredq / http://alteredqualia.com/
  10278. */
  10279. THREE.MorphAnimMesh = function ( geometry, material ) {
  10280. THREE.Mesh.call( this, geometry, material );
  10281. this.type = 'MorphAnimMesh';
  10282. // API
  10283. this.duration = 1000; // milliseconds
  10284. this.mirroredLoop = false;
  10285. this.time = 0;
  10286. // internals
  10287. this.lastKeyframe = 0;
  10288. this.currentKeyframe = 0;
  10289. this.direction = 1;
  10290. this.directionBackwards = false;
  10291. this.setFrameRange( 0, this.geometry.morphTargets.length - 1 );
  10292. };
  10293. THREE.MorphAnimMesh.prototype = Object.create( THREE.Mesh.prototype );
  10294. THREE.MorphAnimMesh.prototype.constructor = THREE.MorphAnimMesh;
  10295. THREE.MorphAnimMesh.prototype.setFrameRange = function ( start, end ) {
  10296. this.startKeyframe = start;
  10297. this.endKeyframe = end;
  10298. this.length = this.endKeyframe - this.startKeyframe + 1;
  10299. };
  10300. THREE.MorphAnimMesh.prototype.setDirectionForward = function () {
  10301. this.direction = 1;
  10302. this.directionBackwards = false;
  10303. };
  10304. THREE.MorphAnimMesh.prototype.setDirectionBackward = function () {
  10305. this.direction = - 1;
  10306. this.directionBackwards = true;
  10307. };
  10308. THREE.MorphAnimMesh.prototype.parseAnimations = function () {
  10309. var geometry = this.geometry;
  10310. if ( ! geometry.animations ) geometry.animations = {};
  10311. var firstAnimation, animations = geometry.animations;
  10312. var pattern = /([a-z]+)_?(\d+)/;
  10313. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  10314. var morph = geometry.morphTargets[ i ];
  10315. var parts = morph.name.match( pattern );
  10316. if ( parts && parts.length > 1 ) {
  10317. var label = parts[ 1 ];
  10318. if ( ! animations[ label ] ) animations[ label ] = { start: Infinity, end: - Infinity };
  10319. var animation = animations[ label ];
  10320. if ( i < animation.start ) animation.start = i;
  10321. if ( i > animation.end ) animation.end = i;
  10322. if ( ! firstAnimation ) firstAnimation = label;
  10323. }
  10324. }
  10325. geometry.firstAnimation = firstAnimation;
  10326. };
  10327. THREE.MorphAnimMesh.prototype.setAnimationLabel = function ( label, start, end ) {
  10328. if ( ! this.geometry.animations ) this.geometry.animations = {};
  10329. this.geometry.animations[ label ] = { start: start, end: end };
  10330. };
  10331. THREE.MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {
  10332. var animation = this.geometry.animations[ label ];
  10333. if ( animation ) {
  10334. this.setFrameRange( animation.start, animation.end );
  10335. this.duration = 1000 * ( ( animation.end - animation.start ) / fps );
  10336. this.time = 0;
  10337. } else {
  10338. console.warn( 'THREE.MorphAnimMesh: animation[' + label + '] undefined in .playAnimation()' );
  10339. }
  10340. };
  10341. THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
  10342. var frameTime = this.duration / this.length;
  10343. this.time += this.direction * delta;
  10344. if ( this.mirroredLoop ) {
  10345. if ( this.time > this.duration || this.time < 0 ) {
  10346. this.direction *= - 1;
  10347. if ( this.time > this.duration ) {
  10348. this.time = this.duration;
  10349. this.directionBackwards = true;
  10350. }
  10351. if ( this.time < 0 ) {
  10352. this.time = 0;
  10353. this.directionBackwards = false;
  10354. }
  10355. }
  10356. } else {
  10357. this.time = this.time % this.duration;
  10358. if ( this.time < 0 ) this.time += this.duration;
  10359. }
  10360. var keyframe = this.startKeyframe + THREE.Math.clamp( Math.floor( this.time / frameTime ), 0, this.length - 1 );
  10361. if ( keyframe !== this.currentKeyframe ) {
  10362. this.morphTargetInfluences[ this.lastKeyframe ] = 0;
  10363. this.morphTargetInfluences[ this.currentKeyframe ] = 1;
  10364. this.morphTargetInfluences[ keyframe ] = 0;
  10365. this.lastKeyframe = this.currentKeyframe;
  10366. this.currentKeyframe = keyframe;
  10367. }
  10368. var mix = ( this.time % frameTime ) / frameTime;
  10369. if ( this.directionBackwards ) {
  10370. mix = 1 - mix;
  10371. }
  10372. this.morphTargetInfluences[ this.currentKeyframe ] = mix;
  10373. this.morphTargetInfluences[ this.lastKeyframe ] = 1 - mix;
  10374. };
  10375. THREE.MorphAnimMesh.prototype.interpolateTargets = function ( a, b, t ) {
  10376. var influences = this.morphTargetInfluences;
  10377. for ( var i = 0, l = influences.length; i < l; i ++ ) {
  10378. influences[ i ] = 0;
  10379. }
  10380. if ( a > -1 ) influences[ a ] = 1 - t;
  10381. if ( b > -1 ) influences[ b ] = t;
  10382. };
  10383. THREE.MorphAnimMesh.prototype.clone = function ( object ) {
  10384. if ( object === undefined ) object = new THREE.MorphAnimMesh( this.geometry, this.material );
  10385. object.duration = this.duration;
  10386. object.mirroredLoop = this.mirroredLoop;
  10387. object.time = this.time;
  10388. object.lastKeyframe = this.lastKeyframe;
  10389. object.currentKeyframe = this.currentKeyframe;
  10390. object.direction = this.direction;
  10391. object.directionBackwards = this.directionBackwards;
  10392. THREE.Mesh.prototype.clone.call( this, object );
  10393. return object;
  10394. };
  10395. // File:src/objects/LOD.js
  10396. /**
  10397. * @author mikael emtinger / http://gomo.se/
  10398. * @author alteredq / http://alteredqualia.com/
  10399. * @author mrdoob / http://mrdoob.com/
  10400. */
  10401. THREE.LOD = function () {
  10402. THREE.Object3D.call( this );
  10403. Object.defineProperties( this, {
  10404. levels: {
  10405. enumerable: true,
  10406. value: []
  10407. },
  10408. objects: {
  10409. get: function () {
  10410. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  10411. return this.levels;
  10412. }
  10413. }
  10414. } );
  10415. };
  10416. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  10417. THREE.LOD.prototype.constructor = THREE.LOD;
  10418. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  10419. if ( distance === undefined ) distance = 0;
  10420. distance = Math.abs( distance );
  10421. var levels = this.levels;
  10422. for ( var l = 0; l < levels.length; l ++ ) {
  10423. if ( distance < levels[ l ].distance ) {
  10424. break;
  10425. }
  10426. }
  10427. levels.splice( l, 0, { distance: distance, object: object } );
  10428. this.add( object );
  10429. };
  10430. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  10431. var levels = this.levels;
  10432. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10433. if ( distance < levels[ i ].distance ) {
  10434. break;
  10435. }
  10436. }
  10437. return levels[ i - 1 ].object;
  10438. };
  10439. THREE.LOD.prototype.raycast = ( function () {
  10440. var matrixPosition = new THREE.Vector3();
  10441. return function ( raycaster, intersects ) {
  10442. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10443. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  10444. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  10445. };
  10446. }() );
  10447. THREE.LOD.prototype.update = function () {
  10448. var v1 = new THREE.Vector3();
  10449. var v2 = new THREE.Vector3();
  10450. return function ( camera ) {
  10451. var levels = this.levels;
  10452. if ( levels.length > 1 ) {
  10453. v1.setFromMatrixPosition( camera.matrixWorld );
  10454. v2.setFromMatrixPosition( this.matrixWorld );
  10455. var distance = v1.distanceTo( v2 );
  10456. levels[ 0 ].object.visible = true;
  10457. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10458. if ( distance >= levels[ i ].distance ) {
  10459. levels[ i - 1 ].object.visible = false;
  10460. levels[ i ].object.visible = true;
  10461. } else {
  10462. break;
  10463. }
  10464. }
  10465. for ( ; i < l; i ++ ) {
  10466. levels[ i ].object.visible = false;
  10467. }
  10468. }
  10469. };
  10470. }();
  10471. THREE.LOD.prototype.clone = function ( object ) {
  10472. if ( object === undefined ) object = new THREE.LOD();
  10473. THREE.Object3D.prototype.clone.call( this, object, false );
  10474. var levels = this.levels;
  10475. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  10476. var level = levels[ i ];
  10477. object.addLevel( level.object.clone(), level.distance );
  10478. }
  10479. return object;
  10480. };
  10481. // File:src/objects/Sprite.js
  10482. /**
  10483. * @author mikael emtinger / http://gomo.se/
  10484. * @author alteredq / http://alteredqualia.com/
  10485. */
  10486. THREE.Sprite = ( function () {
  10487. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  10488. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  10489. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  10490. var geometry = new THREE.BufferGeometry();
  10491. geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  10492. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  10493. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  10494. return function ( material ) {
  10495. THREE.Object3D.call( this );
  10496. this.type = 'Sprite';
  10497. this.geometry = geometry;
  10498. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  10499. };
  10500. } )();
  10501. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  10502. THREE.Sprite.prototype.constructor = THREE.Sprite;
  10503. THREE.Sprite.prototype.raycast = ( function () {
  10504. var matrixPosition = new THREE.Vector3();
  10505. return function ( raycaster, intersects ) {
  10506. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10507. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  10508. var guessSizeSq = this.scale.x * this.scale.y;
  10509. if ( distanceSq > guessSizeSq ) {
  10510. return;
  10511. }
  10512. intersects.push( {
  10513. distance: Math.sqrt( distanceSq ),
  10514. point: this.position,
  10515. face: null,
  10516. object: this
  10517. } );
  10518. };
  10519. }() );
  10520. THREE.Sprite.prototype.clone = function ( object ) {
  10521. if ( object === undefined ) object = new THREE.Sprite( this.material );
  10522. THREE.Object3D.prototype.clone.call( this, object );
  10523. return object;
  10524. };
  10525. THREE.Sprite.prototype.toJSON = function ( meta ) {
  10526. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10527. // only serialize if not in meta materials cache
  10528. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10529. meta.materials[ this.material.uuid ] = this.material.toJSON();
  10530. }
  10531. data.object.material = this.material.uuid;
  10532. return data;
  10533. };
  10534. // Backwards compatibility
  10535. THREE.Particle = THREE.Sprite;
  10536. // File:src/objects/LensFlare.js
  10537. /**
  10538. * @author mikael emtinger / http://gomo.se/
  10539. * @author alteredq / http://alteredqualia.com/
  10540. */
  10541. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  10542. THREE.Object3D.call( this );
  10543. this.lensFlares = [];
  10544. this.positionScreen = new THREE.Vector3();
  10545. this.customUpdateCallback = undefined;
  10546. if ( texture !== undefined ) {
  10547. this.add( texture, size, distance, blending, color );
  10548. }
  10549. };
  10550. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  10551. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  10552. /*
  10553. * Add: adds another flare
  10554. */
  10555. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  10556. if ( size === undefined ) size = - 1;
  10557. if ( distance === undefined ) distance = 0;
  10558. if ( opacity === undefined ) opacity = 1;
  10559. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  10560. if ( blending === undefined ) blending = THREE.NormalBlending;
  10561. distance = Math.min( distance, Math.max( 0, distance ) );
  10562. this.lensFlares.push( {
  10563. texture: texture, // THREE.Texture
  10564. size: size, // size in pixels (-1 = use texture.width)
  10565. distance: distance, // distance (0-1) from light source (0=at light source)
  10566. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  10567. scale: 1, // scale
  10568. rotation: 0, // rotation
  10569. opacity: opacity, // opacity
  10570. color: color, // color
  10571. blending: blending // blending
  10572. } );
  10573. };
  10574. /*
  10575. * Update lens flares update positions on all flares based on the screen position
  10576. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  10577. */
  10578. THREE.LensFlare.prototype.updateLensFlares = function () {
  10579. var f, fl = this.lensFlares.length;
  10580. var flare;
  10581. var vecX = - this.positionScreen.x * 2;
  10582. var vecY = - this.positionScreen.y * 2;
  10583. for ( f = 0; f < fl; f ++ ) {
  10584. flare = this.lensFlares[ f ];
  10585. flare.x = this.positionScreen.x + vecX * flare.distance;
  10586. flare.y = this.positionScreen.y + vecY * flare.distance;
  10587. flare.wantedRotation = flare.x * Math.PI * 0.25;
  10588. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  10589. }
  10590. };
  10591. THREE.LensFlare.prototype.clone = function ( object ) {
  10592. if ( object === undefined ) object = new THREE.LensFlare();
  10593. THREE.Object3D.prototype.clone.call( this, object );
  10594. object.positionScreen.copy( this.positionScreen );
  10595. object.customUpdateCallback = this.customUpdateCallback;
  10596. for ( var i = 0, l = this.lensFlares.length; i < l; i ++ ) {
  10597. object.lensFlares.push( this.lensFlares[ i ] );
  10598. }
  10599. return object;
  10600. };
  10601. // File:src/scenes/Scene.js
  10602. /**
  10603. * @author mrdoob / http://mrdoob.com/
  10604. */
  10605. THREE.Scene = function () {
  10606. THREE.Object3D.call( this );
  10607. this.type = 'Scene';
  10608. this.fog = null;
  10609. this.overrideMaterial = null;
  10610. this.autoUpdate = true; // checked by the renderer
  10611. };
  10612. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  10613. THREE.Scene.prototype.constructor = THREE.Scene;
  10614. THREE.Scene.prototype.clone = function ( object ) {
  10615. if ( object === undefined ) object = new THREE.Scene();
  10616. THREE.Object3D.prototype.clone.call( this, object );
  10617. if ( this.fog !== null ) object.fog = this.fog.clone();
  10618. if ( this.overrideMaterial !== null ) object.overrideMaterial = this.overrideMaterial.clone();
  10619. object.autoUpdate = this.autoUpdate;
  10620. object.matrixAutoUpdate = this.matrixAutoUpdate;
  10621. return object;
  10622. };
  10623. // File:src/scenes/Fog.js
  10624. /**
  10625. * @author mrdoob / http://mrdoob.com/
  10626. * @author alteredq / http://alteredqualia.com/
  10627. */
  10628. THREE.Fog = function ( color, near, far ) {
  10629. this.name = '';
  10630. this.color = new THREE.Color( color );
  10631. this.near = ( near !== undefined ) ? near : 1;
  10632. this.far = ( far !== undefined ) ? far : 1000;
  10633. };
  10634. THREE.Fog.prototype.clone = function () {
  10635. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  10636. };
  10637. // File:src/scenes/FogExp2.js
  10638. /**
  10639. * @author mrdoob / http://mrdoob.com/
  10640. * @author alteredq / http://alteredqualia.com/
  10641. */
  10642. THREE.FogExp2 = function ( color, density ) {
  10643. this.name = '';
  10644. this.color = new THREE.Color( color );
  10645. this.density = ( density !== undefined ) ? density : 0.00025;
  10646. };
  10647. THREE.FogExp2.prototype.clone = function () {
  10648. return new THREE.FogExp2( this.color.getHex(), this.density );
  10649. };
  10650. // File:src/renderers/shaders/ShaderChunk.js
  10651. THREE.ShaderChunk = {};
  10652. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  10653. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  10654. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  10655. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  10656. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  10657. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  10658. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  10659. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  10660. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  10661. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  10662. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  10663. THREE.ShaderChunk[ 'bumpmap_pars_fragment'] = "#ifdef USE_BUMPMAP\n\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n\n // Derivative maps - bump mapping unparametrized surfaces by Morten Mikkelsen\n // http://mmikkelsen3d.blogspot.sk/2011/07/derivative-maps.html\n\n // Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)\n\n vec2 dHdxy_fwd() {\n\n vec2 dSTdx = dFdx( vUv );\n vec2 dSTdy = dFdy( vUv );\n\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\n return vec2( dBx, dBy );\n\n }\n\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\n vec3 vSigmaX = dFdx( surf_pos );\n vec3 vSigmaY = dFdy( surf_pos );\n vec3 vN = surf_norm; // normalized\n\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n\n float fDet = dot( vSigmaX, R1 );\n\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n\n }\n\n#endif\n";
  10664. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  10665. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  10666. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  10667. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  10668. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  10669. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  10670. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  10671. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = color.xyz;\n\n#endif";
  10672. // File:src/renderers/shaders/ShaderChunk/common.glsl
  10673. THREE.ShaderChunk[ 'common'] = "#define PI 3.14159\n#define PI2 6.28318\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\n\nvec3 transformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );\n\n}\n\n// http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations\nvec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );\n\n}\n\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n float distance = dot( planeNormal, point - pointOnPlane );\n\n return - distance * planeNormal + point;\n\n}\n\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return sign( dot( point - pointOnPlane, planeNormal ) );\n\n}\n\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n\n}\n\nfloat calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {\n\n if ( decayExponent > 0.0 ) {\n\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\n }\n\n return 1.0;\n\n}\n\nvec3 F_Schlick( in vec3 specularColor, in float dotLH ) {\n\n return ( 1.0 - specularColor ) * pow( 1.0 - dotLH, 5.0 ) + specularColor;\n\n}\n\nfloat G_BlinnPhong_Implicit( /* in float dotNL, in float dotNV */ ) {\n\n // geometry term is (n⋅l)(n⋅v) / 4(n⋅l)(n⋅v)\n\n return 0.25;\n\n}\n\nfloat D_BlinnPhong( in float shininess, in float dotNH ) {\n\n // factor of 1/PI in distribution term omitted\n\n return ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n\n}\n\nvec3 BRDF_BlinnPhong( in vec3 specularColor, in float shininess, in vec3 normal, in vec3 lightDir, in vec3 viewDir ) {\n\n vec3 halfDir = normalize( lightDir + viewDir );\n\n //float dotNL = saturate( dot( normal, lightDir ) );\n //float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotLH = saturate( dot( lightDir, halfDir ) );\n\n vec3 F = F_Schlick( specularColor, dotLH );\n\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\n float D = D_BlinnPhong( shininess, dotNH );\n\n return F * G * D;\n\n}\n\nvec3 inputToLinear( in vec3 a ) {\n\n #ifdef GAMMA_INPUT\n\n return pow( a, vec3( float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n\nvec3 linearToOutput( in vec3 a ) {\n\n #ifdef GAMMA_OUTPUT\n\n return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n";
  10674. // File:src/renderers/shaders/ShaderChunk/default_vertex.glsl
  10675. THREE.ShaderChunk[ 'default_vertex'] = "#ifdef USE_SKINNING\n\n vec4 mvPosition = modelViewMatrix * skinned;\n\n#elif defined( USE_MORPHTARGETS )\n\n vec4 mvPosition = modelViewMatrix * vec4( morphed, 1.0 );\n\n#else\n\n vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\n#endif\n\ngl_Position = projectionMatrix * mvPosition;\n";
  10676. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  10677. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef USE_SKINNING\n\n vec3 objectNormal = skinnedNormal.xyz;\n\n#elif defined( USE_MORPHNORMALS )\n\n vec3 objectNormal = morphedNormal;\n\n#else\n\n vec3 objectNormal = normal;\n\n#endif\n\n#ifdef FLIP_SIDED\n\n objectNormal = -objectNormal;\n\n#endif\n\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  10678. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  10679. THREE.ShaderChunk[ 'emissivemap_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n vec4 emissiveColor = texture2D( emissiveMap, vUv );\n\n emissiveColor.rgb = inputToLinear( emissiveColor.rgb );\n\n totalEmissiveLight *= emissiveColor.rgb;\n\n#endif\n";
  10680. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  10681. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n";
  10682. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  10683. THREE.ShaderChunk[ 'envmap_fragment'] = "#ifdef USE_ENVMAP\n\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\n vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\n // Transforming Normal Vectors with the Inverse Transformation\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\n #ifdef ENVMAP_MODE_REFLECTION\n\n vec3 reflectVec = reflect( cameraToVertex, worldNormal );\n\n #else\n\n vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n\n #endif\n\n #else\n\n vec3 reflectVec = vReflect;\n\n #endif\n\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n\n #ifdef ENVMAP_TYPE_CUBE\n vec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\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\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\n envColor.xyz = inputToLinear( envColor.xyz );\n\n #ifdef ENVMAP_BLENDING_MULTIPLY\n\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\n #elif defined( ENVMAP_BLENDING_MIX )\n\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\n #elif defined( ENVMAP_BLENDING_ADD )\n\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n\n #endif\n\n#endif\n";
  10684. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  10685. THREE.ShaderChunk[ 'envmap_pars_fragment'] = "#ifdef USE_ENVMAP\n\n uniform float reflectivity;\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n uniform float flipEnvMap;\n\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\n uniform float refractionRatio;\n\n #else\n\n varying vec3 vReflect;\n\n #endif\n\n#endif\n";
  10686. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  10687. THREE.ShaderChunk[ 'envmap_pars_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n varying vec3 vReflect;\n\n uniform float refractionRatio;\n\n#endif\n";
  10688. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  10689. THREE.ShaderChunk[ 'envmap_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n vec3 worldNormal = transformDirection( objectNormal, modelMatrix );\n\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\n #ifdef ENVMAP_MODE_REFLECTION\n\n vReflect = reflect( cameraToVertex, worldNormal );\n\n #else\n\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\n #endif\n\n#endif\n";
  10690. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  10691. THREE.ShaderChunk[ 'fog_fragment'] = "#ifdef USE_FOG\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n float depth = gl_FragDepthEXT / gl_FragCoord.w;\n\n #else\n\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n\n #endif\n\n #ifdef FOG_EXP2\n\n float fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );\n\n #else\n\n float fogFactor = smoothstep( fogNear, fogFar, depth );\n\n #endif\n \n outgoingLight = mix( outgoingLight, fogColor, fogFactor );\n\n#endif";
  10692. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  10693. THREE.ShaderChunk[ 'fog_pars_fragment'] = "#ifdef USE_FOG\n\n uniform vec3 fogColor;\n\n #ifdef FOG_EXP2\n\n uniform float fogDensity;\n\n #else\n\n uniform float fogNear;\n uniform float fogFar;\n #endif\n\n#endif";
  10694. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  10695. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  10696. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  10697. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  10698. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  10699. THREE.ShaderChunk[ 'lights_lambert_pars_vertex'] = "uniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n uniform float pointLightDecay[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];\n\n#endif\n";
  10700. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  10701. THREE.ShaderChunk[ 'lights_lambert_vertex'] = "vLightFront = vec3( 0.0 );\n\n#ifdef DOUBLE_SIDED\n\n vLightBack = vec3( 0.0 );\n\n#endif\n\nvec3 normal = normalize( transformedNormal );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\n vec3 lVector = lPosition.xyz - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], normalize( lightPosition - worldPosition.xyz ) );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = transformDirection( directionalLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = transformDirection( hemisphereLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n #ifdef DOUBLE_SIDED\n\n float hemiDiffuseWeightBack = - 0.5 * dotProduct + 0.5;\n\n vLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );\n\n #endif\n\n }\n\n#endif\n\nvLightFront += ambientLightColor;\n\n#ifdef DOUBLE_SIDED\n\n vLightBack += ambientLightColor;\n\n#endif\n";
  10702. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  10703. THREE.ShaderChunk[ 'lights_phong_fragment'] = "#ifndef FLAT_SHADED\n\n vec3 normal = normalize( vNormal );\n\n #ifdef DOUBLE_SIDED\n\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n\n #endif\n\n#else\n\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\n\n#endif\n\n#ifdef USE_NORMALMAP\n\n normal = perturbNormal2Arb( -vViewPosition, normal );\n\n#elif defined( USE_BUMPMAP )\n\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n\n#endif\n\nvec3 viewDir = normalize( vViewPosition );\n\nvec3 totalDiffuseLight = vec3( 0.0 );\nvec3 totalSpecularLight = vec3( 0.0 );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec3 lightPosition = pointLightPosition[ i ];\n vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], normalize( lightPosition - vWorldPosition ) );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = transformDirection( directionalLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * cosineTerm;\n\n }\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = transformDirection( hemisphereLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vec3 lightColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n totalDiffuseLight += lightColor;\n\n // specular (sky term only)\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * max( dotProduct, 0.0 );\n\n }\n\n#endif\n\n#ifdef METAL\n\n outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + totalEmissiveLight;\n\n#else\n\n outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + totalEmissiveLight;\n\n#endif\n";
  10704. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  10705. THREE.ShaderChunk[ 'lights_phong_pars_fragment'] = "uniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n uniform float pointLightDecay[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n\nvarying vec3 vViewPosition;\n\n#ifndef FLAT_SHADED\n\n varying vec3 vNormal;\n\n#endif\n";
  10706. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  10707. THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n";
  10708. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  10709. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif";
  10710. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  10711. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  10712. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  10713. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  10714. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  10715. THREE.ShaderChunk[ 'logdepthbuf_pars_fragment'] = "#ifdef USE_LOGDEPTHBUF\n\n uniform float logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n #extension GL_EXT_frag_depth : enable\n varying float vFragDepth;\n\n #endif\n\n#endif";
  10716. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  10717. THREE.ShaderChunk[ 'logdepthbuf_pars_vertex'] = "#ifdef USE_LOGDEPTHBUF\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n varying float vFragDepth;\n\n #endif\n\n uniform float logDepthBufFC;\n\n#endif";
  10718. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  10719. THREE.ShaderChunk[ 'logdepthbuf_vertex'] = "#ifdef USE_LOGDEPTHBUF\n\n gl_Position.z = log2(max( EPSILON, gl_Position.w + 1.0 )) * logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n vFragDepth = 1.0 + gl_Position.w;\n\n#else\n\n gl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;\n\n #endif\n\n#endif";
  10720. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  10721. THREE.ShaderChunk[ 'map_fragment'] = "#ifdef USE_MAP\n\n vec4 texelColor = texture2D( map, vUv );\n\n texelColor.xyz = inputToLinear( texelColor.xyz );\n\n diffuseColor *= texelColor;\n\n#endif\n";
  10722. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  10723. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  10724. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  10725. THREE.ShaderChunk[ 'map_particle_fragment'] = "#ifdef USE_MAP\n\n diffuseColor *= texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\n\n#endif\n";
  10726. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  10727. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  10728. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  10729. THREE.ShaderChunk[ 'morphnormal_vertex'] = "#ifdef USE_MORPHNORMALS\n\n vec3 morphedNormal = vec3( 0.0 );\n\n morphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n morphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n morphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n morphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n\n morphedNormal += normal;\n\n#endif";
  10730. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  10731. THREE.ShaderChunk[ 'morphtarget_pars_vertex'] = "#ifdef USE_MORPHTARGETS\n\n #ifndef USE_MORPHNORMALS\n\n uniform float morphTargetInfluences[ 8 ];\n\n #else\n\n uniform float morphTargetInfluences[ 4 ];\n\n #endif\n\n#endif";
  10732. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  10733. THREE.ShaderChunk[ 'morphtarget_vertex'] = "#ifdef USE_MORPHTARGETS\n\n vec3 morphed = vec3( 0.0 );\n morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\n #ifndef USE_MORPHNORMALS\n\n morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\n #endif\n\n morphed += position;\n\n#endif";
  10734. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  10735. THREE.ShaderChunk[ 'normalmap_pars_fragment'] = "#ifdef USE_NORMALMAP\n\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n\n // Per-Pixel Tangent Space Normal Mapping\n // http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html\n\n vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\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\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\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 }\n\n#endif\n";
  10736. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  10737. THREE.ShaderChunk[ 'shadowmap_fragment'] = "#ifdef USE_SHADOWMAP\n\n #ifdef SHADOWMAP_DEBUG\n\n vec3 frustumColors[3];\n frustumColors[0] = vec3( 1.0, 0.5, 0.0 );\n frustumColors[1] = vec3( 0.0, 1.0, 0.8 );\n frustumColors[2] = vec3( 0.0, 0.5, 1.0 );\n\n #endif\n\n #ifdef SHADOWMAP_CASCADE\n\n int inFrustumCount = 0;\n\n #endif\n\n float fDepth;\n vec3 shadowColor = vec3( 1.0 );\n\n for( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\n\n // if ( something && something ) breaks ATI OpenGL shader compiler\n // if ( all( something, something ) ) using this instead\n\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\n // don't shadow pixels outside of light frustum\n // use just first frustum (for cascades)\n // don't shadow pixels behind far plane of light frustum\n\n #ifdef SHADOWMAP_CASCADE\n\n inFrustumCount += int( inFrustum );\n bvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );\n\n #else\n\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\n #endif\n\n bool frustumTest = all( frustumTestVec );\n\n if ( frustumTest ) {\n\n shadowCoord.z += shadowBias[ i ];\n\n #if defined( SHADOWMAP_TYPE_PCF )\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n float shadow = 0.0;\n\n /*\n // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL\n // must enroll loop manually\n\n for ( float y = -1.25; y <= 1.25; y += 1.25 )\n for ( float x = -1.25; x <= 1.25; x += 1.25 ) {\n\n vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\n\n // doesn't seem to produce any noticeable visual difference compared to simple texture2D lookup\n //vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );\n\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n shadow += 1.0;\n\n }\n\n shadow /= 9.0;\n\n */\n\n const float shadowDelta = 1.0 / 9.0;\n\n float xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n float yPixelOffset = 1.0 / shadowMapSize[ i ].y;\n\n float dx0 = -1.25 * xPixelOffset;\n float dy0 = -1.25 * yPixelOffset;\n float dx1 = 1.25 * xPixelOffset;\n float dy1 = 1.25 * yPixelOffset;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n float shadow = 0.0;\n\n float xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n float yPixelOffset = 1.0 / shadowMapSize[ i ].y;\n\n float dx0 = -1.0 * xPixelOffset;\n float dy0 = -1.0 * yPixelOffset;\n float dx1 = 1.0 * xPixelOffset;\n float dy1 = 1.0 * yPixelOffset;\n\n mat3 shadowKernel;\n mat3 depthKernel;\n\n depthKernel[0][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n depthKernel[0][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n depthKernel[0][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n depthKernel[1][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n depthKernel[1][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n depthKernel[1][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n depthKernel[2][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n depthKernel[2][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n depthKernel[2][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n\n vec3 shadowZ = vec3( shadowCoord.z );\n shadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));\n shadowKernel[0] *= vec3(0.25);\n\n shadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));\n shadowKernel[1] *= vec3(0.25);\n\n shadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));\n shadowKernel[2] *= vec3(0.25);\n\n vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );\n\n shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );\n shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );\n\n vec4 shadowValues;\n shadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );\n shadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );\n shadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );\n shadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );\n\n shadow = dot( shadowValues, vec4( 1.0 ) );\n\n shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n #else\n\n vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n\n // spot with multiple shadows is darker\n\n shadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );\n\n // spot with multiple shadows has the same color as single shadow spot\n\n // shadowColor = min( shadowColor, vec3( shadowDarkness[ i ] ) );\n\n #endif\n\n }\n\n\n #ifdef SHADOWMAP_DEBUG\n\n #ifdef SHADOWMAP_CASCADE\n\n if ( inFrustum && inFrustumCount == 1 ) outgoingLight *= frustumColors[ i ];\n\n #else\n\n if ( inFrustum ) outgoingLight *= frustumColors[ i ];\n\n #endif\n\n #endif\n\n }\n\n outgoingLight = outgoingLight * shadowColor;\n\n#endif\n";
  10738. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  10739. THREE.ShaderChunk[ 'shadowmap_pars_fragment'] = "#ifdef USE_SHADOWMAP\n\n uniform sampler2D shadowMap[ MAX_SHADOWS ];\n uniform vec2 shadowMapSize[ MAX_SHADOWS ];\n\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform float shadowBias[ MAX_SHADOWS ];\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n float unpackDepth( const in vec4 rgba_depth ) {\n\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 float depth = dot( rgba_depth, bit_shift );\n return depth;\n\n }\n\n#endif";
  10740. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  10741. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n\n#endif";
  10742. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  10743. THREE.ShaderChunk[ 'shadowmap_vertex'] = "#ifdef USE_SHADOWMAP\n\n for( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n\n }\n\n#endif";
  10744. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  10745. THREE.ShaderChunk[ 'skinbase_vertex'] = "#ifdef USE_SKINNING\n\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\n#endif";
  10746. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  10747. THREE.ShaderChunk[ 'skinning_pars_vertex'] = "#ifdef USE_SKINNING\n\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n\n #ifdef BONE_TEXTURE\n\n uniform sampler2D boneTexture;\n uniform int boneTextureWidth;\n uniform int boneTextureHeight;\n\n mat4 getBoneMatrix( const in float i ) {\n\n float j = i * 4.0;\n float x = mod( j, float( boneTextureWidth ) );\n float y = floor( j / float( boneTextureWidth ) );\n\n float dx = 1.0 / float( boneTextureWidth );\n float dy = 1.0 / float( boneTextureHeight );\n\n y = dy * ( y + 0.5 );\n\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\n mat4 bone = mat4( v1, v2, v3, v4 );\n\n return bone;\n\n }\n\n #else\n\n uniform mat4 boneGlobalMatrices[ MAX_BONES ];\n\n mat4 getBoneMatrix( const in float i ) {\n\n mat4 bone = boneGlobalMatrices[ int(i) ];\n return bone;\n\n }\n\n #endif\n\n#endif\n";
  10748. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  10749. THREE.ShaderChunk[ 'skinning_vertex'] = "#ifdef USE_SKINNING\n\n #ifdef USE_MORPHTARGETS\n\n vec4 skinVertex = bindMatrix * vec4( morphed, 1.0 );\n\n #else\n\n vec4 skinVertex = bindMatrix * vec4( position, 1.0 );\n\n #endif\n\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\n#endif\n";
  10750. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  10751. THREE.ShaderChunk[ 'skinnormal_vertex'] = "#ifdef USE_SKINNING\n\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\n #ifdef USE_MORPHNORMALS\n\n vec4 skinnedNormal = skinMatrix * vec4( morphedNormal, 0.0 );\n\n #else\n\n vec4 skinnedNormal = skinMatrix * vec4( normal, 0.0 );\n\n #endif\n\n#endif\n";
  10752. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  10753. THREE.ShaderChunk[ 'specularmap_fragment'] = "float specularStrength;\n\n#ifdef USE_SPECULARMAP\n\n vec4 texelSpecular = texture2D( specularMap, vUv );\n specularStrength = texelSpecular.r;\n\n#else\n\n specularStrength = 1.0;\n\n#endif";
  10754. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  10755. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  10756. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  10757. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  10758. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  10759. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  10760. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  10761. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  10762. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  10763. THREE.ShaderChunk[ 'uv_pars_fragment'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP )\n\n varying vec2 vUv;\n\n#endif";
  10764. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  10765. THREE.ShaderChunk[ 'uv_pars_vertex'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP )\n\n varying vec2 vUv;\n uniform vec4 offsetRepeat;\n\n#endif\n";
  10766. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  10767. THREE.ShaderChunk[ 'uv_vertex'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP )\n\n vUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n\n#endif";
  10768. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  10769. THREE.ShaderChunk[ 'worldpos_vertex'] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n\n #ifdef USE_SKINNING\n\n vec4 worldPosition = modelMatrix * skinned;\n\n #elif defined( USE_MORPHTARGETS )\n\n vec4 worldPosition = modelMatrix * vec4( morphed, 1.0 );\n\n #else\n\n vec4 worldPosition = modelMatrix * vec4( position, 1.0 );\n\n #endif\n\n#endif\n";
  10770. // File:src/renderers/shaders/UniformsUtils.js
  10771. /**
  10772. * Uniform Utilities
  10773. */
  10774. THREE.UniformsUtils = {
  10775. merge: function ( uniforms ) {
  10776. var merged = {};
  10777. for ( var u = 0; u < uniforms.length; u ++ ) {
  10778. var tmp = this.clone( uniforms[ u ] );
  10779. for ( var p in tmp ) {
  10780. merged[ p ] = tmp[ p ];
  10781. }
  10782. }
  10783. return merged;
  10784. },
  10785. clone: function ( uniforms_src ) {
  10786. var uniforms_dst = {};
  10787. for ( var u in uniforms_src ) {
  10788. uniforms_dst[ u ] = {};
  10789. for ( var p in uniforms_src[ u ] ) {
  10790. var parameter_src = uniforms_src[ u ][ p ];
  10791. if ( parameter_src instanceof THREE.Color ||
  10792. parameter_src instanceof THREE.Vector2 ||
  10793. parameter_src instanceof THREE.Vector3 ||
  10794. parameter_src instanceof THREE.Vector4 ||
  10795. parameter_src instanceof THREE.Matrix3 ||
  10796. parameter_src instanceof THREE.Matrix4 ||
  10797. parameter_src instanceof THREE.Texture ) {
  10798. uniforms_dst[ u ][ p ] = parameter_src.clone();
  10799. } else if ( Array.isArray( parameter_src ) ) {
  10800. uniforms_dst[ u ][ p ] = parameter_src.slice();
  10801. } else {
  10802. uniforms_dst[ u ][ p ] = parameter_src;
  10803. }
  10804. }
  10805. }
  10806. return uniforms_dst;
  10807. }
  10808. };
  10809. // File:src/renderers/shaders/UniformsLib.js
  10810. /**
  10811. * Uniforms library for shared webgl shaders
  10812. */
  10813. THREE.UniformsLib = {
  10814. common: {
  10815. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  10816. "opacity" : { type: "f", value: 1.0 },
  10817. "map" : { type: "t", value: null },
  10818. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  10819. "specularMap" : { type: "t", value: null },
  10820. "alphaMap" : { type: "t", value: null },
  10821. "envMap" : { type: "t", value: null },
  10822. "flipEnvMap" : { type: "f", value: - 1 },
  10823. "reflectivity" : { type: "f", value: 1.0 },
  10824. "refractionRatio" : { type: "f", value: 0.98 }
  10825. },
  10826. aomap: {
  10827. "aoMap" : { type: "t", value: null },
  10828. "aoMapIntensity" : { type: "f", value: 1 },
  10829. },
  10830. lightmap: {
  10831. "lightMap" : { type: "t", value: null },
  10832. "lightMapIntensity" : { type: "f", value: 1 },
  10833. },
  10834. emissivemap: {
  10835. "emissiveMap" : { type: "t", value: null },
  10836. },
  10837. bump: {
  10838. "bumpMap" : { type: "t", value: null },
  10839. "bumpScale" : { type: "f", value: 1 }
  10840. },
  10841. normalmap: {
  10842. "normalMap" : { type: "t", value: null },
  10843. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  10844. },
  10845. fog : {
  10846. "fogDensity" : { type: "f", value: 0.00025 },
  10847. "fogNear" : { type: "f", value: 1 },
  10848. "fogFar" : { type: "f", value: 2000 },
  10849. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  10850. },
  10851. lights: {
  10852. "ambientLightColor" : { type: "fv", value: [] },
  10853. "directionalLightDirection" : { type: "fv", value: [] },
  10854. "directionalLightColor" : { type: "fv", value: [] },
  10855. "hemisphereLightDirection" : { type: "fv", value: [] },
  10856. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  10857. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  10858. "pointLightColor" : { type: "fv", value: [] },
  10859. "pointLightPosition" : { type: "fv", value: [] },
  10860. "pointLightDistance" : { type: "fv1", value: [] },
  10861. "pointLightDecay" : { type: "fv1", value: [] },
  10862. "spotLightColor" : { type: "fv", value: [] },
  10863. "spotLightPosition" : { type: "fv", value: [] },
  10864. "spotLightDirection" : { type: "fv", value: [] },
  10865. "spotLightDistance" : { type: "fv1", value: [] },
  10866. "spotLightAngleCos" : { type: "fv1", value: [] },
  10867. "spotLightExponent" : { type: "fv1", value: [] },
  10868. "spotLightDecay" : { type: "fv1", value: [] }
  10869. },
  10870. particle: {
  10871. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  10872. "opacity" : { type: "f", value: 1.0 },
  10873. "size" : { type: "f", value: 1.0 },
  10874. "scale" : { type: "f", value: 1.0 },
  10875. "map" : { type: "t", value: null },
  10876. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  10877. "fogDensity" : { type: "f", value: 0.00025 },
  10878. "fogNear" : { type: "f", value: 1 },
  10879. "fogFar" : { type: "f", value: 2000 },
  10880. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  10881. },
  10882. shadowmap: {
  10883. "shadowMap": { type: "tv", value: [] },
  10884. "shadowMapSize": { type: "v2v", value: [] },
  10885. "shadowBias" : { type: "fv1", value: [] },
  10886. "shadowDarkness": { type: "fv1", value: [] },
  10887. "shadowMatrix" : { type: "m4v", value: [] }
  10888. }
  10889. };
  10890. // File:src/renderers/shaders/ShaderLib.js
  10891. /**
  10892. * Webgl Shader Library for three.js
  10893. *
  10894. * @author alteredq / http://alteredqualia.com/
  10895. * @author mrdoob / http://mrdoob.com/
  10896. * @author mikael emtinger / http://gomo.se/
  10897. */
  10898. THREE.ShaderLib = {
  10899. 'basic': {
  10900. uniforms: THREE.UniformsUtils.merge( [
  10901. THREE.UniformsLib[ "common" ],
  10902. THREE.UniformsLib[ "aomap" ],
  10903. THREE.UniformsLib[ "fog" ],
  10904. THREE.UniformsLib[ "shadowmap" ]
  10905. ] ),
  10906. vertexShader: [
  10907. THREE.ShaderChunk[ "common" ],
  10908. THREE.ShaderChunk[ "uv_pars_vertex" ],
  10909. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  10910. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  10911. THREE.ShaderChunk[ "color_pars_vertex" ],
  10912. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  10913. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  10914. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  10915. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  10916. "void main() {",
  10917. THREE.ShaderChunk[ "uv_vertex" ],
  10918. THREE.ShaderChunk[ "uv2_vertex" ],
  10919. THREE.ShaderChunk[ "color_vertex" ],
  10920. THREE.ShaderChunk[ "skinbase_vertex" ],
  10921. " #ifdef USE_ENVMAP",
  10922. THREE.ShaderChunk[ "morphnormal_vertex" ],
  10923. THREE.ShaderChunk[ "skinnormal_vertex" ],
  10924. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  10925. " #endif",
  10926. THREE.ShaderChunk[ "morphtarget_vertex" ],
  10927. THREE.ShaderChunk[ "skinning_vertex" ],
  10928. THREE.ShaderChunk[ "default_vertex" ],
  10929. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  10930. THREE.ShaderChunk[ "worldpos_vertex" ],
  10931. THREE.ShaderChunk[ "envmap_vertex" ],
  10932. THREE.ShaderChunk[ "shadowmap_vertex" ],
  10933. "}"
  10934. ].join("\n"),
  10935. fragmentShader: [
  10936. "uniform vec3 diffuse;",
  10937. "uniform float opacity;",
  10938. THREE.ShaderChunk[ "common" ],
  10939. THREE.ShaderChunk[ "color_pars_fragment" ],
  10940. THREE.ShaderChunk[ "uv_pars_fragment" ],
  10941. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  10942. THREE.ShaderChunk[ "map_pars_fragment" ],
  10943. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  10944. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  10945. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  10946. THREE.ShaderChunk[ "fog_pars_fragment" ],
  10947. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  10948. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  10949. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  10950. "void main() {",
  10951. " vec3 outgoingLight = vec3( 0.0 );",
  10952. " vec4 diffuseColor = vec4( diffuse, opacity );",
  10953. " vec3 totalAmbientLight = vec3( 1.0 );", // hardwired
  10954. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  10955. THREE.ShaderChunk[ "map_fragment" ],
  10956. THREE.ShaderChunk[ "color_fragment" ],
  10957. THREE.ShaderChunk[ "alphamap_fragment" ],
  10958. THREE.ShaderChunk[ "alphatest_fragment" ],
  10959. THREE.ShaderChunk[ "specularmap_fragment" ],
  10960. THREE.ShaderChunk[ "aomap_fragment" ],
  10961. " outgoingLight = diffuseColor.rgb * totalAmbientLight;", // simple shader
  10962. THREE.ShaderChunk[ "envmap_fragment" ],
  10963. THREE.ShaderChunk[ "shadowmap_fragment" ], // TODO: Shadows on an otherwise unlit surface doesn't make sense.
  10964. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  10965. THREE.ShaderChunk[ "fog_fragment" ],
  10966. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  10967. "}"
  10968. ].join("\n")
  10969. },
  10970. 'lambert': {
  10971. uniforms: THREE.UniformsUtils.merge( [
  10972. THREE.UniformsLib[ "common" ],
  10973. THREE.UniformsLib[ "fog" ],
  10974. THREE.UniformsLib[ "lights" ],
  10975. THREE.UniformsLib[ "shadowmap" ],
  10976. {
  10977. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  10978. }
  10979. ] ),
  10980. vertexShader: [
  10981. "#define LAMBERT",
  10982. "varying vec3 vLightFront;",
  10983. "#ifdef DOUBLE_SIDED",
  10984. " varying vec3 vLightBack;",
  10985. "#endif",
  10986. THREE.ShaderChunk[ "common" ],
  10987. THREE.ShaderChunk[ "uv_pars_vertex" ],
  10988. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  10989. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  10990. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  10991. THREE.ShaderChunk[ "color_pars_vertex" ],
  10992. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  10993. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  10994. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  10995. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  10996. "void main() {",
  10997. THREE.ShaderChunk[ "uv_vertex" ],
  10998. THREE.ShaderChunk[ "uv2_vertex" ],
  10999. THREE.ShaderChunk[ "color_vertex" ],
  11000. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11001. THREE.ShaderChunk[ "skinbase_vertex" ],
  11002. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11003. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11004. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11005. THREE.ShaderChunk[ "skinning_vertex" ],
  11006. THREE.ShaderChunk[ "default_vertex" ],
  11007. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11008. THREE.ShaderChunk[ "worldpos_vertex" ],
  11009. THREE.ShaderChunk[ "envmap_vertex" ],
  11010. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  11011. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11012. "}"
  11013. ].join("\n"),
  11014. fragmentShader: [
  11015. "uniform vec3 diffuse;",
  11016. "uniform vec3 emissive;",
  11017. "uniform float opacity;",
  11018. "varying vec3 vLightFront;",
  11019. "#ifdef DOUBLE_SIDED",
  11020. " varying vec3 vLightBack;",
  11021. "#endif",
  11022. THREE.ShaderChunk[ "common" ],
  11023. THREE.ShaderChunk[ "color_pars_fragment" ],
  11024. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11025. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11026. THREE.ShaderChunk[ "map_pars_fragment" ],
  11027. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11028. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11029. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11030. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11031. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11032. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11033. "void main() {",
  11034. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  11035. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11036. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11037. THREE.ShaderChunk[ "map_fragment" ],
  11038. THREE.ShaderChunk[ "color_fragment" ],
  11039. THREE.ShaderChunk[ "alphamap_fragment" ],
  11040. THREE.ShaderChunk[ "alphatest_fragment" ],
  11041. THREE.ShaderChunk[ "specularmap_fragment" ],
  11042. " #ifdef DOUBLE_SIDED",
  11043. " if ( gl_FrontFacing )",
  11044. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11045. " else",
  11046. " outgoingLight += diffuseColor.rgb * vLightBack + emissive;",
  11047. " #else",
  11048. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11049. " #endif",
  11050. THREE.ShaderChunk[ "envmap_fragment" ],
  11051. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11052. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11053. THREE.ShaderChunk[ "fog_fragment" ],
  11054. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11055. "}"
  11056. ].join("\n")
  11057. },
  11058. 'phong': {
  11059. uniforms: THREE.UniformsUtils.merge( [
  11060. THREE.UniformsLib[ "common" ],
  11061. THREE.UniformsLib[ "aomap" ],
  11062. THREE.UniformsLib[ "lightmap" ],
  11063. THREE.UniformsLib[ "emissivemap" ],
  11064. THREE.UniformsLib[ "bump" ],
  11065. THREE.UniformsLib[ "normalmap" ],
  11066. THREE.UniformsLib[ "fog" ],
  11067. THREE.UniformsLib[ "lights" ],
  11068. THREE.UniformsLib[ "shadowmap" ],
  11069. {
  11070. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  11071. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  11072. "shininess": { type: "f", value: 30 }
  11073. }
  11074. ] ),
  11075. vertexShader: [
  11076. "#define PHONG",
  11077. "varying vec3 vViewPosition;",
  11078. "#ifndef FLAT_SHADED",
  11079. " varying vec3 vNormal;",
  11080. "#endif",
  11081. THREE.ShaderChunk[ "common" ],
  11082. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11083. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11084. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11085. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  11086. THREE.ShaderChunk[ "color_pars_vertex" ],
  11087. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11088. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11089. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11090. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11091. "void main() {",
  11092. THREE.ShaderChunk[ "uv_vertex" ],
  11093. THREE.ShaderChunk[ "uv2_vertex" ],
  11094. THREE.ShaderChunk[ "color_vertex" ],
  11095. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11096. THREE.ShaderChunk[ "skinbase_vertex" ],
  11097. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11098. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11099. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  11100. " vNormal = normalize( transformedNormal );",
  11101. "#endif",
  11102. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11103. THREE.ShaderChunk[ "skinning_vertex" ],
  11104. THREE.ShaderChunk[ "default_vertex" ],
  11105. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11106. " vViewPosition = - mvPosition.xyz;",
  11107. THREE.ShaderChunk[ "worldpos_vertex" ],
  11108. THREE.ShaderChunk[ "envmap_vertex" ],
  11109. THREE.ShaderChunk[ "lights_phong_vertex" ],
  11110. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11111. "}"
  11112. ].join("\n"),
  11113. fragmentShader: [
  11114. "#define PHONG",
  11115. "uniform vec3 diffuse;",
  11116. "uniform vec3 emissive;",
  11117. "uniform vec3 specular;",
  11118. "uniform float shininess;",
  11119. "uniform float opacity;",
  11120. THREE.ShaderChunk[ "common" ],
  11121. THREE.ShaderChunk[ "color_pars_fragment" ],
  11122. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11123. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11124. THREE.ShaderChunk[ "map_pars_fragment" ],
  11125. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11126. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  11127. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  11128. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  11129. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11130. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11131. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  11132. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11133. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  11134. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  11135. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11136. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11137. "void main() {",
  11138. " vec3 outgoingLight = vec3( 0.0 );",
  11139. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11140. " vec3 totalAmbientLight = ambientLightColor;",
  11141. " vec3 totalEmissiveLight = emissive;",
  11142. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11143. THREE.ShaderChunk[ "map_fragment" ],
  11144. THREE.ShaderChunk[ "color_fragment" ],
  11145. THREE.ShaderChunk[ "alphamap_fragment" ],
  11146. THREE.ShaderChunk[ "alphatest_fragment" ],
  11147. THREE.ShaderChunk[ "specularmap_fragment" ],
  11148. THREE.ShaderChunk[ "lightmap_fragment" ],
  11149. THREE.ShaderChunk[ "aomap_fragment" ],
  11150. THREE.ShaderChunk[ "emissivemap_fragment" ],
  11151. THREE.ShaderChunk[ "lights_phong_fragment" ],
  11152. THREE.ShaderChunk[ "envmap_fragment" ],
  11153. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11154. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11155. THREE.ShaderChunk[ "fog_fragment" ],
  11156. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11157. "}"
  11158. ].join("\n")
  11159. },
  11160. 'particle_basic': {
  11161. uniforms: THREE.UniformsUtils.merge( [
  11162. THREE.UniformsLib[ "particle" ],
  11163. THREE.UniformsLib[ "shadowmap" ]
  11164. ] ),
  11165. vertexShader: [
  11166. "uniform float size;",
  11167. "uniform float scale;",
  11168. THREE.ShaderChunk[ "common" ],
  11169. THREE.ShaderChunk[ "color_pars_vertex" ],
  11170. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11171. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11172. "void main() {",
  11173. THREE.ShaderChunk[ "color_vertex" ],
  11174. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11175. " #ifdef USE_SIZEATTENUATION",
  11176. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  11177. " #else",
  11178. " gl_PointSize = size;",
  11179. " #endif",
  11180. " gl_Position = projectionMatrix * mvPosition;",
  11181. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11182. THREE.ShaderChunk[ "worldpos_vertex" ],
  11183. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11184. "}"
  11185. ].join("\n"),
  11186. fragmentShader: [
  11187. "uniform vec3 psColor;",
  11188. "uniform float opacity;",
  11189. THREE.ShaderChunk[ "common" ],
  11190. THREE.ShaderChunk[ "color_pars_fragment" ],
  11191. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  11192. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11193. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11194. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11195. "void main() {",
  11196. " vec3 outgoingLight = vec3( 0.0 );",
  11197. " vec4 diffuseColor = vec4( psColor, opacity );",
  11198. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11199. THREE.ShaderChunk[ "map_particle_fragment" ],
  11200. THREE.ShaderChunk[ "color_fragment" ],
  11201. THREE.ShaderChunk[ "alphatest_fragment" ],
  11202. " outgoingLight = diffuseColor.rgb;", // simple shader
  11203. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11204. THREE.ShaderChunk[ "fog_fragment" ],
  11205. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11206. "}"
  11207. ].join("\n")
  11208. },
  11209. 'dashed': {
  11210. uniforms: THREE.UniformsUtils.merge( [
  11211. THREE.UniformsLib[ "common" ],
  11212. THREE.UniformsLib[ "fog" ],
  11213. {
  11214. "scale" : { type: "f", value: 1 },
  11215. "dashSize" : { type: "f", value: 1 },
  11216. "totalSize": { type: "f", value: 2 }
  11217. }
  11218. ] ),
  11219. vertexShader: [
  11220. "uniform float scale;",
  11221. "attribute float lineDistance;",
  11222. "varying float vLineDistance;",
  11223. THREE.ShaderChunk[ "common" ],
  11224. THREE.ShaderChunk[ "color_pars_vertex" ],
  11225. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11226. "void main() {",
  11227. THREE.ShaderChunk[ "color_vertex" ],
  11228. " vLineDistance = scale * lineDistance;",
  11229. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11230. " gl_Position = projectionMatrix * mvPosition;",
  11231. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11232. "}"
  11233. ].join("\n"),
  11234. fragmentShader: [
  11235. "uniform vec3 diffuse;",
  11236. "uniform float opacity;",
  11237. "uniform float dashSize;",
  11238. "uniform float totalSize;",
  11239. "varying float vLineDistance;",
  11240. THREE.ShaderChunk[ "common" ],
  11241. THREE.ShaderChunk[ "color_pars_fragment" ],
  11242. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11243. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11244. "void main() {",
  11245. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  11246. " discard;",
  11247. " }",
  11248. " vec3 outgoingLight = vec3( 0.0 );",
  11249. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11250. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11251. THREE.ShaderChunk[ "color_fragment" ],
  11252. " outgoingLight = diffuseColor.rgb;", // simple shader
  11253. THREE.ShaderChunk[ "fog_fragment" ],
  11254. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11255. "}"
  11256. ].join("\n")
  11257. },
  11258. 'depth': {
  11259. uniforms: {
  11260. "mNear": { type: "f", value: 1.0 },
  11261. "mFar" : { type: "f", value: 2000.0 },
  11262. "opacity" : { type: "f", value: 1.0 }
  11263. },
  11264. vertexShader: [
  11265. THREE.ShaderChunk[ "common" ],
  11266. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11267. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11268. "void main() {",
  11269. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11270. THREE.ShaderChunk[ "default_vertex" ],
  11271. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11272. "}"
  11273. ].join("\n"),
  11274. fragmentShader: [
  11275. "uniform float mNear;",
  11276. "uniform float mFar;",
  11277. "uniform float opacity;",
  11278. THREE.ShaderChunk[ "common" ],
  11279. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11280. "void main() {",
  11281. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11282. " #ifdef USE_LOGDEPTHBUF_EXT",
  11283. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  11284. " #else",
  11285. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  11286. " #endif",
  11287. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  11288. " gl_FragColor = vec4( vec3( color ), opacity );",
  11289. "}"
  11290. ].join("\n")
  11291. },
  11292. 'normal': {
  11293. uniforms: {
  11294. "opacity" : { type: "f", value: 1.0 }
  11295. },
  11296. vertexShader: [
  11297. "varying vec3 vNormal;",
  11298. THREE.ShaderChunk[ "common" ],
  11299. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11300. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11301. "void main() {",
  11302. " vNormal = normalize( normalMatrix * normal );",
  11303. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11304. THREE.ShaderChunk[ "default_vertex" ],
  11305. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11306. "}"
  11307. ].join("\n"),
  11308. fragmentShader: [
  11309. "uniform float opacity;",
  11310. "varying vec3 vNormal;",
  11311. THREE.ShaderChunk[ "common" ],
  11312. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11313. "void main() {",
  11314. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  11315. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11316. "}"
  11317. ].join("\n")
  11318. },
  11319. /* -------------------------------------------------------------------------
  11320. // Cube map shader
  11321. ------------------------------------------------------------------------- */
  11322. 'cube': {
  11323. uniforms: { "tCube": { type: "t", value: null },
  11324. "tFlip": { type: "f", value: - 1 } },
  11325. vertexShader: [
  11326. "varying vec3 vWorldPosition;",
  11327. THREE.ShaderChunk[ "common" ],
  11328. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11329. "void main() {",
  11330. " vWorldPosition = transformDirection( position, modelMatrix );",
  11331. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11332. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11333. "}"
  11334. ].join("\n"),
  11335. fragmentShader: [
  11336. "uniform samplerCube tCube;",
  11337. "uniform float tFlip;",
  11338. "varying vec3 vWorldPosition;",
  11339. THREE.ShaderChunk[ "common" ],
  11340. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11341. "void main() {",
  11342. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11343. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11344. "}"
  11345. ].join("\n")
  11346. },
  11347. /* -------------------------------------------------------------------------
  11348. // Cube map shader
  11349. ------------------------------------------------------------------------- */
  11350. 'equirect': {
  11351. uniforms: { "tEquirect": { type: "t", value: null },
  11352. "tFlip": { type: "f", value: - 1 } },
  11353. vertexShader: [
  11354. "varying vec3 vWorldPosition;",
  11355. THREE.ShaderChunk[ "common" ],
  11356. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11357. "void main() {",
  11358. " vWorldPosition = transformDirection( position, modelMatrix );",
  11359. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11360. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11361. "}"
  11362. ].join("\n"),
  11363. fragmentShader: [
  11364. "uniform sampler2D tEquirect;",
  11365. "uniform float tFlip;",
  11366. "varying vec3 vWorldPosition;",
  11367. THREE.ShaderChunk[ "common" ],
  11368. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11369. "void main() {",
  11370. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11371. "vec3 direction = normalize( vWorldPosition );",
  11372. "vec2 sampleUV;",
  11373. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  11374. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  11375. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  11376. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11377. "}"
  11378. ].join("\n")
  11379. },
  11380. /* Depth encoding into RGBA texture
  11381. *
  11382. * based on SpiderGL shadow map example
  11383. * http://spidergl.org/example.php?id=6
  11384. *
  11385. * originally from
  11386. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  11387. *
  11388. * see also
  11389. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  11390. */
  11391. 'depthRGBA': {
  11392. uniforms: {},
  11393. vertexShader: [
  11394. THREE.ShaderChunk[ "common" ],
  11395. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11396. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11397. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11398. "void main() {",
  11399. THREE.ShaderChunk[ "skinbase_vertex" ],
  11400. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11401. THREE.ShaderChunk[ "skinning_vertex" ],
  11402. THREE.ShaderChunk[ "default_vertex" ],
  11403. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11404. "}"
  11405. ].join("\n"),
  11406. fragmentShader: [
  11407. THREE.ShaderChunk[ "common" ],
  11408. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11409. "vec4 pack_depth( const in float depth ) {",
  11410. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  11411. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  11412. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  11413. " res -= res.xxyz * bit_mask;",
  11414. " return res;",
  11415. "}",
  11416. "void main() {",
  11417. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11418. " #ifdef USE_LOGDEPTHBUF_EXT",
  11419. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  11420. " #else",
  11421. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  11422. " #endif",
  11423. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  11424. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  11425. //"gl_FragData[ 0 ] = pack_depth( z );",
  11426. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  11427. "}"
  11428. ].join("\n")
  11429. }
  11430. };
  11431. // File:src/renderers/WebGLRenderer.js
  11432. /**
  11433. * @author supereggbert / http://www.paulbrunt.co.uk/
  11434. * @author mrdoob / http://mrdoob.com/
  11435. * @author alteredq / http://alteredqualia.com/
  11436. * @author szimek / https://github.com/szimek/
  11437. */
  11438. THREE.WebGLRenderer = function ( parameters ) {
  11439. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  11440. parameters = parameters || {};
  11441. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  11442. _context = parameters.context !== undefined ? parameters.context : null,
  11443. _width = _canvas.width,
  11444. _height = _canvas.height,
  11445. pixelRatio = 1,
  11446. _precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  11447. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  11448. _depth = parameters.depth !== undefined ? parameters.depth : true,
  11449. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  11450. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  11451. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  11452. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  11453. _logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false,
  11454. _clearColor = new THREE.Color( 0x000000 ),
  11455. _clearAlpha = 0;
  11456. var lights = [];
  11457. var opaqueObjects = [];
  11458. var transparentObjects = [];
  11459. var opaqueImmediateObjects = [];
  11460. var transparentImmediateObjects = [];
  11461. var sprites = [];
  11462. var lensFlares = [];
  11463. // public properties
  11464. this.domElement = _canvas;
  11465. this.context = null;
  11466. // clearing
  11467. this.autoClear = true;
  11468. this.autoClearColor = true;
  11469. this.autoClearDepth = true;
  11470. this.autoClearStencil = true;
  11471. // scene graph
  11472. this.sortObjects = true;
  11473. // physically based shading
  11474. this.gammaFactor = 2.0; // for backwards compatibility
  11475. this.gammaInput = false;
  11476. this.gammaOutput = false;
  11477. // morphs
  11478. this.maxMorphTargets = 8;
  11479. this.maxMorphNormals = 4;
  11480. // flags
  11481. this.autoScaleCubemaps = true;
  11482. // internal properties
  11483. var _this = this,
  11484. _programs = [],
  11485. // internal state cache
  11486. _currentProgram = null,
  11487. _currentFramebuffer = null,
  11488. _currentMaterialId = - 1,
  11489. _currentGeometryProgram = '',
  11490. _currentCamera = null,
  11491. _usedTextureUnits = 0,
  11492. _viewportX = 0,
  11493. _viewportY = 0,
  11494. _viewportWidth = _canvas.width,
  11495. _viewportHeight = _canvas.height,
  11496. _currentWidth = 0,
  11497. _currentHeight = 0,
  11498. // frustum
  11499. _frustum = new THREE.Frustum(),
  11500. // camera matrices cache
  11501. _projScreenMatrix = new THREE.Matrix4(),
  11502. _vector3 = new THREE.Vector3(),
  11503. // light arrays cache
  11504. _direction = new THREE.Vector3(),
  11505. _lightsNeedUpdate = true,
  11506. _lights = {
  11507. ambient: [ 0, 0, 0 ],
  11508. directional: { length: 0, colors:[], positions: [] },
  11509. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  11510. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  11511. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  11512. },
  11513. // info
  11514. _infoMemory = {
  11515. programs: 0,
  11516. geometries: 0,
  11517. textures: 0
  11518. },
  11519. _infoRender = {
  11520. calls: 0,
  11521. vertices: 0,
  11522. faces: 0,
  11523. points: 0
  11524. };
  11525. this.info = {
  11526. render: _infoRender,
  11527. memory: _infoMemory,
  11528. programs: _programs
  11529. };
  11530. // initialize
  11531. var _gl;
  11532. try {
  11533. var attributes = {
  11534. alpha: _alpha,
  11535. depth: _depth,
  11536. stencil: _stencil,
  11537. antialias: _antialias,
  11538. premultipliedAlpha: _premultipliedAlpha,
  11539. preserveDrawingBuffer: _preserveDrawingBuffer
  11540. };
  11541. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  11542. if ( _gl === null ) {
  11543. if ( _canvas.getContext( 'webgl') !== null ) {
  11544. throw 'Error creating WebGL context with your selected attributes.';
  11545. } else {
  11546. throw 'Error creating WebGL context.';
  11547. }
  11548. }
  11549. _canvas.addEventListener( 'webglcontextlost', function ( event ) {
  11550. event.preventDefault();
  11551. resetGLState();
  11552. setDefaultGLState();
  11553. objects.clear();
  11554. properties.clear();
  11555. }, false );
  11556. } catch ( error ) {
  11557. console.error( 'THREE.WebGLRenderer: ' + error );
  11558. }
  11559. var state = new THREE.WebGLState( _gl, paramThreeToGL );
  11560. if ( _gl.getShaderPrecisionFormat === undefined ) {
  11561. _gl.getShaderPrecisionFormat = function () {
  11562. return {
  11563. 'rangeMin': 1,
  11564. 'rangeMax': 1,
  11565. 'precision': 1
  11566. };
  11567. }
  11568. }
  11569. var properties = new THREE.WebGLProperties();
  11570. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  11571. var extensions = new THREE.WebGLExtensions( _gl );
  11572. extensions.get( 'OES_texture_float' );
  11573. extensions.get( 'OES_texture_float_linear' );
  11574. extensions.get( 'OES_texture_half_float' );
  11575. extensions.get( 'OES_texture_half_float_linear' );
  11576. extensions.get( 'OES_standard_derivatives' );
  11577. extensions.get( 'ANGLE_instanced_arrays' );
  11578. if ( extensions.get( 'OES_element_index_uint' ) ) {
  11579. THREE.BufferGeometry.MaxIndex = 4294967296;
  11580. }
  11581. if ( _logarithmicDepthBuffer ) {
  11582. extensions.get( 'EXT_frag_depth' );
  11583. }
  11584. //
  11585. function glClearColor( r, g, b, a ) {
  11586. if ( _premultipliedAlpha === true ) {
  11587. r *= a; g *= a; b *= a;
  11588. }
  11589. _gl.clearColor( r, g, b, a );
  11590. }
  11591. function setDefaultGLState() {
  11592. state.init();
  11593. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11594. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11595. }
  11596. function resetGLState() {
  11597. _currentProgram = null;
  11598. _currentCamera = null;
  11599. _currentGeometryProgram = '';
  11600. _currentMaterialId = - 1;
  11601. _lightsNeedUpdate = true;
  11602. state.reset();
  11603. }
  11604. setDefaultGLState();
  11605. this.context = _gl;
  11606. this.extensions = extensions;
  11607. this.state = state;
  11608. // shadow map
  11609. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  11610. this.shadowMap = shadowMap;
  11611. // GPU capabilities
  11612. var _maxTextures = _gl.getParameter( _gl.MAX_TEXTURE_IMAGE_UNITS );
  11613. var _maxVertexTextures = _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  11614. var _maxTextureSize = _gl.getParameter( _gl.MAX_TEXTURE_SIZE );
  11615. var _maxCubemapSize = _gl.getParameter( _gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  11616. var _supportsVertexTextures = _maxVertexTextures > 0;
  11617. var _supportsBoneTextures = _supportsVertexTextures && extensions.get( 'OES_texture_float' );
  11618. var _supportsInstancedArrays = extensions.get( 'ANGLE_instanced_arrays' );
  11619. //
  11620. var _vertexShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.HIGH_FLOAT );
  11621. var _vertexShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.MEDIUM_FLOAT );
  11622. var _fragmentShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.HIGH_FLOAT );
  11623. var _fragmentShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.MEDIUM_FLOAT );
  11624. var getCompressedTextureFormats = ( function () {
  11625. var array;
  11626. return function () {
  11627. if ( array !== undefined ) {
  11628. return array;
  11629. }
  11630. array = [];
  11631. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) || extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  11632. var formats = _gl.getParameter( _gl.COMPRESSED_TEXTURE_FORMATS );
  11633. for ( var i = 0; i < formats.length; i ++ ) {
  11634. array.push( formats[ i ] );
  11635. }
  11636. }
  11637. return array;
  11638. };
  11639. } )();
  11640. // clamp precision to maximum available
  11641. var highpAvailable = _vertexShaderPrecisionHighpFloat.precision > 0 && _fragmentShaderPrecisionHighpFloat.precision > 0;
  11642. var mediumpAvailable = _vertexShaderPrecisionMediumpFloat.precision > 0 && _fragmentShaderPrecisionMediumpFloat.precision > 0;
  11643. if ( _precision === 'highp' && ! highpAvailable ) {
  11644. if ( mediumpAvailable ) {
  11645. _precision = 'mediump';
  11646. console.warn( 'THREE.WebGLRenderer: highp not supported, using mediump.' );
  11647. } else {
  11648. _precision = 'lowp';
  11649. console.warn( 'THREE.WebGLRenderer: highp and mediump not supported, using lowp.' );
  11650. }
  11651. }
  11652. if ( _precision === 'mediump' && ! mediumpAvailable ) {
  11653. _precision = 'lowp';
  11654. console.warn( 'THREE.WebGLRenderer: mediump not supported, using lowp.' );
  11655. }
  11656. // Plugins
  11657. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  11658. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  11659. // API
  11660. this.getContext = function () {
  11661. return _gl;
  11662. };
  11663. this.forceContextLoss = function () {
  11664. extensions.get( 'WEBGL_lose_context' ).loseContext();
  11665. };
  11666. this.supportsVertexTextures = function () {
  11667. return _supportsVertexTextures;
  11668. };
  11669. this.supportsInstancedArrays = function () {
  11670. return _supportsInstancedArrays;
  11671. };
  11672. this.supportsFloatTextures = function () {
  11673. return extensions.get( 'OES_texture_float' );
  11674. };
  11675. this.supportsHalfFloatTextures = function () {
  11676. return extensions.get( 'OES_texture_half_float' );
  11677. };
  11678. this.supportsStandardDerivatives = function () {
  11679. return extensions.get( 'OES_standard_derivatives' );
  11680. };
  11681. this.supportsCompressedTextureS3TC = function () {
  11682. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  11683. };
  11684. this.supportsCompressedTexturePVRTC = function () {
  11685. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  11686. };
  11687. this.supportsBlendMinMax = function () {
  11688. return extensions.get( 'EXT_blend_minmax' );
  11689. };
  11690. this.getMaxAnisotropy = ( function () {
  11691. var value;
  11692. return function () {
  11693. if ( value !== undefined ) return value;
  11694. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  11695. if ( extension !== null ) {
  11696. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  11697. } else {
  11698. value = 0;
  11699. }
  11700. return value;
  11701. }
  11702. } )();
  11703. this.getPrecision = function () {
  11704. return _precision;
  11705. };
  11706. this.getPixelRatio = function () {
  11707. return pixelRatio;
  11708. };
  11709. this.setPixelRatio = function ( value ) {
  11710. if ( value !== undefined ) pixelRatio = value;
  11711. };
  11712. this.getSize = function () {
  11713. return {
  11714. width: _width,
  11715. height: _height
  11716. };
  11717. };
  11718. this.setSize = function ( width, height, updateStyle ) {
  11719. _width = width;
  11720. _height = height;
  11721. _canvas.width = width * pixelRatio;
  11722. _canvas.height = height * pixelRatio;
  11723. if ( updateStyle !== false ) {
  11724. _canvas.style.width = width + 'px';
  11725. _canvas.style.height = height + 'px';
  11726. }
  11727. this.setViewport( 0, 0, width, height );
  11728. };
  11729. this.setViewport = function ( x, y, width, height ) {
  11730. _viewportX = x * pixelRatio;
  11731. _viewportY = y * pixelRatio;
  11732. _viewportWidth = width * pixelRatio;
  11733. _viewportHeight = height * pixelRatio;
  11734. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11735. };
  11736. this.setScissor = function ( x, y, width, height ) {
  11737. _gl.scissor(
  11738. x * pixelRatio,
  11739. y * pixelRatio,
  11740. width * pixelRatio,
  11741. height * pixelRatio
  11742. );
  11743. };
  11744. this.enableScissorTest = function ( boolean ) {
  11745. state.setScissorTest( boolean );
  11746. };
  11747. // Clearing
  11748. this.getClearColor = function () {
  11749. return _clearColor;
  11750. };
  11751. this.setClearColor = function ( color, alpha ) {
  11752. _clearColor.set( color );
  11753. _clearAlpha = alpha !== undefined ? alpha : 1;
  11754. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11755. };
  11756. this.getClearAlpha = function () {
  11757. return _clearAlpha;
  11758. };
  11759. this.setClearAlpha = function ( alpha ) {
  11760. _clearAlpha = alpha;
  11761. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11762. };
  11763. this.clear = function ( color, depth, stencil ) {
  11764. var bits = 0;
  11765. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  11766. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  11767. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  11768. _gl.clear( bits );
  11769. };
  11770. this.clearColor = function () {
  11771. _gl.clear( _gl.COLOR_BUFFER_BIT );
  11772. };
  11773. this.clearDepth = function () {
  11774. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  11775. };
  11776. this.clearStencil = function () {
  11777. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  11778. };
  11779. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  11780. this.setRenderTarget( renderTarget );
  11781. this.clear( color, depth, stencil );
  11782. };
  11783. // Reset
  11784. this.resetGLState = resetGLState;
  11785. // Events
  11786. function onTextureDispose( event ) {
  11787. var texture = event.target;
  11788. texture.removeEventListener( 'dispose', onTextureDispose );
  11789. deallocateTexture( texture );
  11790. _infoMemory.textures --;
  11791. }
  11792. function onRenderTargetDispose( event ) {
  11793. var renderTarget = event.target;
  11794. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  11795. deallocateRenderTarget( renderTarget );
  11796. _infoMemory.textures --;
  11797. }
  11798. function onMaterialDispose( event ) {
  11799. var material = event.target;
  11800. material.removeEventListener( 'dispose', onMaterialDispose );
  11801. deallocateMaterial( material );
  11802. }
  11803. // Buffer deallocation
  11804. function deallocateTexture( texture ) {
  11805. var textureProperties = properties.get( texture );
  11806. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  11807. // cube texture
  11808. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  11809. } else {
  11810. // 2D texture
  11811. if ( textureProperties.__webglInit === undefined ) return;
  11812. _gl.deleteTexture( textureProperties.__webglTexture );
  11813. }
  11814. // remove all webgl properties
  11815. properties.delete( texture );
  11816. }
  11817. function deallocateRenderTarget( renderTarget ) {
  11818. var renderTargetProperties = properties.get( renderTarget );
  11819. if ( ! renderTarget || renderTargetProperties.__webglTexture === undefined ) return;
  11820. _gl.deleteTexture( renderTargetProperties.__webglTexture );
  11821. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  11822. for ( var i = 0; i < 6; i ++ ) {
  11823. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  11824. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  11825. }
  11826. } else {
  11827. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  11828. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  11829. }
  11830. properties.delete( renderTargetProperties );
  11831. }
  11832. function deallocateMaterial( material ) {
  11833. releaseMaterialProgramReference( material );
  11834. properties.delete( material );
  11835. }
  11836. function releaseMaterialProgramReference( material ) {
  11837. var program = properties.get( material ).program.program;
  11838. if ( program === undefined ) return;
  11839. material.program = undefined;
  11840. for ( var i = 0, n = _programs.length; i !== n; ++ i ) {
  11841. var programInfo = _programs[ i ];
  11842. if ( programInfo.program === program ) {
  11843. var newReferenceCount = -- programInfo.usedTimes;
  11844. if ( newReferenceCount === 0 ) {
  11845. // the last meterial that has been using the program let
  11846. // go of it, so remove it from the (unordered) _programs
  11847. // set and deallocate the GL resource
  11848. var newLength = n - 1;
  11849. _programs[ i ] = _programs[ newLength ];
  11850. _programs.pop();
  11851. _gl.deleteProgram( program );
  11852. _infoMemory.programs = newLength;
  11853. }
  11854. break;
  11855. }
  11856. }
  11857. }
  11858. // Buffer rendering
  11859. this.renderBufferImmediate = function ( object, program, material ) {
  11860. state.initAttributes();
  11861. var objectProperties = properties.get( object );
  11862. if ( object.hasPositions && ! objectProperties.__webglVertexBuffer ) objectProperties.__webglVertexBuffer = _gl.createBuffer();
  11863. if ( object.hasNormals && ! objectProperties.__webglNormalBuffer ) objectProperties.__webglNormalBuffer = _gl.createBuffer();
  11864. if ( object.hasUvs && ! objectProperties.__webglUvBuffer ) objectProperties.__webglUvBuffer = _gl.createBuffer();
  11865. if ( object.hasColors && ! objectProperties.__webglColorBuffer ) objectProperties.__webglColorBuffer = _gl.createBuffer();
  11866. var attributes = program.getAttributes();
  11867. if ( object.hasPositions ) {
  11868. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglVertexBuffer );
  11869. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  11870. state.enableAttribute( attributes.position );
  11871. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  11872. }
  11873. if ( object.hasNormals ) {
  11874. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglNormalBuffer );
  11875. if ( material instanceof THREE.MeshPhongMaterial === false && material.shading === THREE.FlatShading ) {
  11876. var nx, ny, nz,
  11877. nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
  11878. normalArray,
  11879. i, il = object.count * 3;
  11880. for ( i = 0; i < il; i += 9 ) {
  11881. normalArray = object.normalArray;
  11882. nax = normalArray[ i ];
  11883. nay = normalArray[ i + 1 ];
  11884. naz = normalArray[ i + 2 ];
  11885. nbx = normalArray[ i + 3 ];
  11886. nby = normalArray[ i + 4 ];
  11887. nbz = normalArray[ i + 5 ];
  11888. ncx = normalArray[ i + 6 ];
  11889. ncy = normalArray[ i + 7 ];
  11890. ncz = normalArray[ i + 8 ];
  11891. nx = ( nax + nbx + ncx ) / 3;
  11892. ny = ( nay + nby + ncy ) / 3;
  11893. nz = ( naz + nbz + ncz ) / 3;
  11894. normalArray[ i ] = nx;
  11895. normalArray[ i + 1 ] = ny;
  11896. normalArray[ i + 2 ] = nz;
  11897. normalArray[ i + 3 ] = nx;
  11898. normalArray[ i + 4 ] = ny;
  11899. normalArray[ i + 5 ] = nz;
  11900. normalArray[ i + 6 ] = nx;
  11901. normalArray[ i + 7 ] = ny;
  11902. normalArray[ i + 8 ] = nz;
  11903. }
  11904. }
  11905. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  11906. state.enableAttribute( attributes.normal );
  11907. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  11908. }
  11909. if ( object.hasUvs && material.map ) {
  11910. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglUvBuffer );
  11911. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  11912. state.enableAttribute( attributes.uv );
  11913. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  11914. }
  11915. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  11916. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglColorBuffer );
  11917. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  11918. state.enableAttribute( attributes.color );
  11919. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  11920. }
  11921. state.disableUnusedAttributes();
  11922. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  11923. object.count = 0;
  11924. };
  11925. function setupVertexAttributes( material, program, geometry, startIndex ) {
  11926. var extension;
  11927. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  11928. extension = extensions.get( 'ANGLE_instanced_arrays' );
  11929. if ( extension === null ) {
  11930. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  11931. return;
  11932. }
  11933. }
  11934. var geometryAttributes = geometry.attributes;
  11935. var programAttributes = program.getAttributes();
  11936. var materialDefaultAttributeValues = material.defaultAttributeValues;
  11937. for ( var name in programAttributes ) {
  11938. var programAttribute = programAttributes[ name ];
  11939. if ( programAttribute >= 0 ) {
  11940. var geometryAttribute = geometryAttributes[ name ];
  11941. if ( geometryAttribute !== undefined ) {
  11942. var size = geometryAttribute.itemSize;
  11943. state.enableAttribute( programAttribute );
  11944. var buffer = objects.getAttributeBuffer(geometryAttribute);
  11945. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  11946. var data = geometryAttribute.data;
  11947. var stride = data.stride;
  11948. var offset = geometryAttribute.offset;
  11949. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  11950. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  11951. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  11952. if ( extension === null ) {
  11953. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  11954. return;
  11955. }
  11956. extension.vertexAttribDivisorANGLE( programAttribute, data.meshPerAttribute );
  11957. if ( geometry.maxInstancedCount === undefined ) {
  11958. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  11959. }
  11960. }
  11961. } else {
  11962. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  11963. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  11964. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  11965. if ( extension === null ) {
  11966. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  11967. return;
  11968. }
  11969. extension.vertexAttribDivisorANGLE( programAttribute, geometryAttribute.meshPerAttribute );
  11970. if ( geometry.maxInstancedCount === undefined ) {
  11971. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  11972. }
  11973. }
  11974. }
  11975. } else if ( materialDefaultAttributeValues !== undefined ) {
  11976. var value = materialDefaultAttributeValues[ name ];
  11977. if ( value !== undefined ) {
  11978. switch ( value.length ) {
  11979. case 2:
  11980. _gl.vertexAttrib2fv( programAttribute, value );
  11981. break;
  11982. case 3:
  11983. _gl.vertexAttrib3fv( programAttribute, value );
  11984. break;
  11985. case 4:
  11986. _gl.vertexAttrib4fv( programAttribute, value );
  11987. break;
  11988. default:
  11989. _gl.vertexAttrib1fv( programAttribute, value );
  11990. }
  11991. }
  11992. }
  11993. }
  11994. }
  11995. state.disableUnusedAttributes();
  11996. }
  11997. this.renderBufferDirect = function ( camera, lights, fog, material, object ) {
  11998. if ( material.visible === false ) return;
  11999. setMaterial( material );
  12000. var geometry = objects.geometries.get( object );
  12001. var program = setProgram( camera, lights, fog, material, object );
  12002. var updateBuffers = false,
  12003. wireframeBit = material.wireframe ? 1 : 0,
  12004. geometryProgram = geometry.id + '_' + program.id + '_' + wireframeBit;
  12005. if ( geometryProgram !== _currentGeometryProgram ) {
  12006. _currentGeometryProgram = geometryProgram;
  12007. updateBuffers = true;
  12008. }
  12009. if ( updateBuffers ) {
  12010. state.initAttributes();
  12011. }
  12012. if ( object instanceof THREE.Mesh ) {
  12013. renderMesh( material, geometry, object, program, updateBuffers );
  12014. } else if ( object instanceof THREE.Line ) {
  12015. renderLine( material, geometry, object, program, updateBuffers );
  12016. } else if ( object instanceof THREE.PointCloud ) {
  12017. renderPointCloud( material, geometry, object, program, updateBuffers );
  12018. }
  12019. };
  12020. function renderMesh( material, geometry, object, program, updateBuffers ) {
  12021. var mode = _gl.TRIANGLES;
  12022. if ( material.wireframe === true ) {
  12023. mode = _gl.LINES;
  12024. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  12025. }
  12026. var index = geometry.attributes.index;
  12027. if ( index ) {
  12028. // indexed triangles
  12029. var type, size;
  12030. var indexBuffer = objects.getAttributeBuffer(index);
  12031. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12032. type = _gl.UNSIGNED_INT;
  12033. size = 4;
  12034. } else {
  12035. type = _gl.UNSIGNED_SHORT;
  12036. size = 2;
  12037. }
  12038. var offsets = geometry.drawcalls;
  12039. if ( offsets.length === 0 ) {
  12040. if ( updateBuffers ) {
  12041. setupVertexAttributes( material, program, geometry, 0 );
  12042. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12043. }
  12044. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12045. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12046. if ( extension === null ) {
  12047. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12048. return;
  12049. }
  12050. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount ); // Draw the instanced meshes
  12051. } else {
  12052. _gl.drawElements( mode, index.array.length, type, 0 );
  12053. }
  12054. _infoRender.calls ++;
  12055. _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
  12056. _infoRender.faces += index.array.length / 3;
  12057. } else {
  12058. // if there is more than 1 chunk
  12059. // must set attribute pointers to use new offsets for each chunk
  12060. // even if geometry and materials didn't change
  12061. updateBuffers = true;
  12062. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12063. var startIndex = offsets[ i ].index;
  12064. if ( updateBuffers ) {
  12065. setupVertexAttributes( material, program, geometry, startIndex );
  12066. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12067. }
  12068. // render indexed triangles
  12069. if ( geometry instanceof THREE.InstancedBufferGeometry && offsets[i].instances > 0 ) {
  12070. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12071. if ( extension === null ) {
  12072. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12073. return;
  12074. }
  12075. extension.drawElementsInstancedANGLE( mode, offsets[i].count, type, offsets[i].start * size, offsets[i].count, type, offsets[i].instances ); // Draw the instanced meshes
  12076. } else {
  12077. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12078. }
  12079. _infoRender.calls ++;
  12080. _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12081. _infoRender.faces += offsets[ i ].count / 3;
  12082. }
  12083. }
  12084. } else {
  12085. // non-indexed triangles
  12086. var offsets = geometry.drawcalls;
  12087. if ( offsets.length === 0 ) {
  12088. if ( updateBuffers ) {
  12089. setupVertexAttributes( material, program, geometry, 0 );
  12090. }
  12091. var position = geometry.attributes.position;
  12092. // render non-indexed triangles
  12093. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12094. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12095. if ( extension === null ) {
  12096. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12097. return;
  12098. }
  12099. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12100. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount ); // Draw the instanced meshes
  12101. } else {
  12102. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount ); // Draw the instanced meshes
  12103. }
  12104. } else {
  12105. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12106. _gl.drawArrays( mode, 0, position.data.count );
  12107. } else {
  12108. _gl.drawArrays( mode, 0, position.count );
  12109. }
  12110. }
  12111. _infoRender.calls++;
  12112. _infoRender.vertices += position.count;
  12113. _infoRender.faces += position.array.length / 3;
  12114. } else {
  12115. // if there is more than 1 chunk
  12116. // must set attribute pointers to use new offsets for each chunk
  12117. // even if geometry and materials didn't change
  12118. if ( updateBuffers ) {
  12119. setupVertexAttributes( material, program, geometry, 0 );
  12120. }
  12121. for ( var i = 0, il = offsets.length; i < il; i++ ) {
  12122. // render non-indexed triangles
  12123. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  12124. console.error( 'THREE.WebGLRenderer.renderMesh: cannot use drawCalls with THREE.InstancedBufferGeometry.' );
  12125. return;
  12126. } else {
  12127. _gl.drawArrays( mode, offsets[ i ].start, offsets[ i ].count );
  12128. }
  12129. _infoRender.calls++;
  12130. _infoRender.vertices += offsets[ i ].count;
  12131. _infoRender.faces += ( offsets[ i ].count ) / 3;
  12132. }
  12133. }
  12134. }
  12135. }
  12136. function renderLine( material, geometry, object, program, updateBuffers ) {
  12137. var mode = object instanceof THREE.LineSegments ? _gl.LINES : _gl.LINE_STRIP;
  12138. // In case user is not using Line*Material by mistake
  12139. var lineWidth = material.linewidth !== undefined ? material.linewidth : 1;
  12140. state.setLineWidth( lineWidth * pixelRatio );
  12141. var index = geometry.attributes.index;
  12142. if ( index ) {
  12143. // indexed lines
  12144. var type, size;
  12145. var indexBuffer = objects.getAttributeBuffer(index);
  12146. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12147. type = _gl.UNSIGNED_INT;
  12148. size = 4;
  12149. } else {
  12150. type = _gl.UNSIGNED_SHORT;
  12151. size = 2;
  12152. }
  12153. var offsets = geometry.drawcalls;
  12154. if ( offsets.length === 0 ) {
  12155. if ( updateBuffers ) {
  12156. setupVertexAttributes( material, program, geometry, 0 );
  12157. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12158. }
  12159. _gl.drawElements( mode, index.array.length, type, 0 ); // 2 bytes per Uint16Array
  12160. _infoRender.calls ++;
  12161. _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
  12162. } else {
  12163. // if there is more than 1 chunk
  12164. // must set attribute pointers to use new offsets for each chunk
  12165. // even if geometry and materials didn't change
  12166. if ( offsets.length > 1 ) updateBuffers = true;
  12167. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12168. var startIndex = offsets[ i ].index;
  12169. if ( updateBuffers ) {
  12170. setupVertexAttributes( material, program, geometry, startIndex );
  12171. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12172. }
  12173. // render indexed lines
  12174. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size ); // 2 bytes per Uint16Array
  12175. _infoRender.calls ++;
  12176. _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12177. }
  12178. }
  12179. } else {
  12180. // non-indexed lines
  12181. if ( updateBuffers ) {
  12182. setupVertexAttributes( material, program, geometry, 0 );
  12183. }
  12184. var position = geometry.attributes.position;
  12185. var offsets = geometry.drawcalls;
  12186. if ( offsets.length === 0 ) {
  12187. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12188. _infoRender.calls ++;
  12189. _infoRender.vertices += position.array.length / 3;
  12190. } else {
  12191. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12192. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12193. _infoRender.calls ++;
  12194. _infoRender.vertices += offsets[ i ].count;
  12195. }
  12196. }
  12197. }
  12198. }
  12199. function renderPointCloud( material, geometry, object, program, updateBuffers ) {
  12200. var mode = _gl.POINTS;
  12201. var index = geometry.attributes.index;
  12202. if ( index ) {
  12203. // indexed points
  12204. var type, size;
  12205. var indexBuffer = objects.getAttributeBuffer( index );
  12206. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12207. type = _gl.UNSIGNED_INT;
  12208. size = 4;
  12209. } else {
  12210. type = _gl.UNSIGNED_SHORT;
  12211. size = 2;
  12212. }
  12213. var offsets = geometry.drawcalls;
  12214. if ( offsets.length === 0 ) {
  12215. if ( updateBuffers ) {
  12216. setupVertexAttributes( material, program, geometry, 0 );
  12217. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12218. }
  12219. _gl.drawElements( mode, index.array.length, type, 0);
  12220. _infoRender.calls ++;
  12221. _infoRender.points += index.array.length;
  12222. } else {
  12223. // if there is more than 1 chunk
  12224. // must set attribute pointers to use new offsets for each chunk
  12225. // even if geometry and materials didn't change
  12226. if ( offsets.length > 1 ) updateBuffers = true;
  12227. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12228. var startIndex = offsets[ i ].index;
  12229. if ( updateBuffers ) {
  12230. setupVertexAttributes( material, program, geometry, startIndex );
  12231. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12232. }
  12233. // render indexed points
  12234. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12235. _infoRender.calls ++;
  12236. _infoRender.points += offsets[ i ].count;
  12237. }
  12238. }
  12239. } else {
  12240. // non-indexed points
  12241. if ( updateBuffers ) {
  12242. setupVertexAttributes( material, program, geometry, 0 );
  12243. }
  12244. var position = geometry.attributes.position;
  12245. var offsets = geometry.drawcalls;
  12246. if ( offsets.length === 0 ) {
  12247. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12248. _infoRender.calls ++;
  12249. _infoRender.points += position.array.length / 3;
  12250. } else {
  12251. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12252. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12253. _infoRender.calls ++;
  12254. _infoRender.points += offsets[ i ].count;
  12255. }
  12256. }
  12257. }
  12258. }
  12259. // Sorting
  12260. function painterSortStable ( a, b ) {
  12261. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12262. return a.object.renderOrder - b.object.renderOrder;
  12263. } else if ( a.object.material.id !== b.object.material.id ) {
  12264. return a.object.material.id - b.object.material.id;
  12265. } else if ( a.z !== b.z ) {
  12266. return a.z - b.z;
  12267. } else {
  12268. return a.id - b.id;
  12269. }
  12270. }
  12271. function reversePainterSortStable ( a, b ) {
  12272. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12273. return a.object.renderOrder - b.object.renderOrder;
  12274. } if ( a.z !== b.z ) {
  12275. return b.z - a.z;
  12276. } else {
  12277. return a.id - b.id;
  12278. }
  12279. }
  12280. // Rendering
  12281. this.render = function ( scene, camera, renderTarget, forceClear ) {
  12282. if ( camera instanceof THREE.Camera === false ) {
  12283. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  12284. return;
  12285. }
  12286. var fog = scene.fog;
  12287. // reset caching for this frame
  12288. _currentGeometryProgram = '';
  12289. _currentMaterialId = - 1;
  12290. _currentCamera = null;
  12291. _lightsNeedUpdate = true;
  12292. // update scene graph
  12293. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  12294. // update camera matrices and frustum
  12295. if ( camera.parent === undefined ) camera.updateMatrixWorld();
  12296. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12297. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  12298. _frustum.setFromMatrix( _projScreenMatrix );
  12299. lights.length = 0;
  12300. opaqueObjects.length = 0;
  12301. transparentObjects.length = 0;
  12302. opaqueImmediateObjects.length = 0;
  12303. transparentImmediateObjects.length = 0;
  12304. sprites.length = 0;
  12305. lensFlares.length = 0;
  12306. projectObject( scene );
  12307. if ( _this.sortObjects === true ) {
  12308. opaqueObjects.sort( painterSortStable );
  12309. transparentObjects.sort( reversePainterSortStable );
  12310. }
  12311. objects.update( opaqueObjects );
  12312. objects.update( transparentObjects );
  12313. //
  12314. shadowMap.render( scene, camera );
  12315. //
  12316. _infoRender.calls = 0;
  12317. _infoRender.vertices = 0;
  12318. _infoRender.faces = 0;
  12319. _infoRender.points = 0;
  12320. this.setRenderTarget( renderTarget );
  12321. if ( this.autoClear || forceClear ) {
  12322. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  12323. }
  12324. //
  12325. if ( scene.overrideMaterial ) {
  12326. var overrideMaterial = scene.overrideMaterial;
  12327. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  12328. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  12329. renderObjectsImmediate( opaqueImmediateObjects, camera, lights, fog, overrideMaterial );
  12330. renderObjectsImmediate( transparentImmediateObjects, camera, lights, fog, overrideMaterial );
  12331. } else {
  12332. // opaque pass (front-to-back order)
  12333. state.setBlending( THREE.NoBlending );
  12334. renderObjects( opaqueObjects, camera, lights, fog, null );
  12335. renderObjectsImmediate( opaqueImmediateObjects, camera, lights, fog, null );
  12336. // transparent pass (back-to-front order)
  12337. renderObjects( transparentObjects, camera, lights, fog, null );
  12338. renderObjectsImmediate( transparentImmediateObjects, camera, lights, fog, null );
  12339. }
  12340. // custom render plugins (post pass)
  12341. spritePlugin.render( scene, camera );
  12342. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  12343. // Generate mipmap if we're using any kind of mipmap filtering
  12344. if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
  12345. updateRenderTargetMipmap( renderTarget );
  12346. }
  12347. // Ensure depth buffer writing is enabled so it can be cleared on next render
  12348. state.setDepthTest( true );
  12349. state.setDepthWrite( true );
  12350. state.setColorWrite( true );
  12351. // _gl.finish();
  12352. };
  12353. function projectObject( object ) {
  12354. if ( object.visible === true ) {
  12355. if ( object instanceof THREE.Scene || object instanceof THREE.Group ) {
  12356. // skip
  12357. } else {
  12358. // update Skeleton objects
  12359. if ( object instanceof THREE.SkinnedMesh ) {
  12360. object.skeleton.update();
  12361. }
  12362. objects.init( object );
  12363. if ( object instanceof THREE.Light ) {
  12364. lights.push( object );
  12365. } else if ( object instanceof THREE.Sprite ) {
  12366. sprites.push( object );
  12367. } else if ( object instanceof THREE.LensFlare ) {
  12368. lensFlares.push( object );
  12369. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  12370. var material = object.material;
  12371. if ( material.transparent ) {
  12372. transparentImmediateObjects.push( object );
  12373. } else {
  12374. opaqueImmediateObjects.push( object );
  12375. }
  12376. } else {
  12377. var webglObject = objects.objects[ object.id ];
  12378. if ( webglObject && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  12379. var material = object.material;
  12380. if ( properties.get( material ) ) {
  12381. material.program = properties.get( material ).program;
  12382. }
  12383. if ( material.transparent ) {
  12384. transparentObjects.push( webglObject );
  12385. } else {
  12386. opaqueObjects.push( webglObject );
  12387. }
  12388. if ( _this.sortObjects === true ) {
  12389. _vector3.setFromMatrixPosition( object.matrixWorld );
  12390. _vector3.applyProjection( _projScreenMatrix );
  12391. webglObject.z = _vector3.z;
  12392. }
  12393. }
  12394. }
  12395. }
  12396. for ( var i = 0, l = object.children.length; i < l; i ++ ) {
  12397. projectObject( object.children[ i ] );
  12398. }
  12399. }
  12400. }
  12401. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  12402. var material = overrideMaterial;
  12403. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12404. var webglObject = renderList[ i ];
  12405. var object = webglObject.object;
  12406. setupMatrices( object, camera );
  12407. if ( overrideMaterial === null ) material = object.material;
  12408. if ( material instanceof THREE.MeshFaceMaterial ) {
  12409. var materials = material.materials;
  12410. for ( var j = 0, jl = materials.length; j < jl; j ++ ) {
  12411. _this.renderBufferDirect( camera, lights, fog, materials[ j ], object );
  12412. }
  12413. continue;
  12414. }
  12415. _this.renderBufferDirect( camera, lights, fog, material, object );
  12416. }
  12417. }
  12418. function renderObjectsImmediate( renderList, camera, lights, fog, overrideMaterial ) {
  12419. var material = overrideMaterial;
  12420. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12421. var object = renderList[ i ];
  12422. setupMatrices( object, camera );
  12423. if ( object.visible === true ) {
  12424. if ( overrideMaterial === null ) material = object.material;
  12425. _this.renderImmediateObject( camera, lights, fog, material, object );
  12426. }
  12427. }
  12428. }
  12429. this.renderImmediateObject = function ( camera, lights, fog, material, object ) {
  12430. setMaterial( material );
  12431. var program = setProgram( camera, lights, fog, material, object );
  12432. _currentGeometryProgram = '';
  12433. object.render( function ( object ) {
  12434. _this.renderBufferImmediate( object, program, material );
  12435. } );
  12436. };
  12437. // Materials
  12438. var shaderIDs = {
  12439. MeshDepthMaterial: 'depth',
  12440. MeshNormalMaterial: 'normal',
  12441. MeshBasicMaterial: 'basic',
  12442. MeshLambertMaterial: 'lambert',
  12443. MeshPhongMaterial: 'phong',
  12444. LineBasicMaterial: 'basic',
  12445. LineDashedMaterial: 'dashed',
  12446. PointCloudMaterial: 'particle_basic'
  12447. };
  12448. function initMaterial( material, lights, fog, object ) {
  12449. var materialProperties = properties.get( material );
  12450. var shaderID = shaderIDs[ material.type ];
  12451. // heuristics to create shader parameters according to lights in the scene
  12452. // (not to blow over maxLights budget)
  12453. var maxLightCount = allocateLights( lights );
  12454. var maxShadows = allocateShadows( lights );
  12455. var maxBones = allocateBones( object );
  12456. var parameters = {
  12457. precision: _precision,
  12458. supportsVertexTextures: _supportsVertexTextures,
  12459. map: !! material.map,
  12460. envMap: !! material.envMap,
  12461. envMapMode: material.envMap && material.envMap.mapping,
  12462. lightMap: !! material.lightMap,
  12463. aoMap: !! material.aoMap,
  12464. emissiveMap: !! material.emissiveMap,
  12465. bumpMap: !! material.bumpMap,
  12466. normalMap: !! material.normalMap,
  12467. specularMap: !! material.specularMap,
  12468. alphaMap: !! material.alphaMap,
  12469. combine: material.combine,
  12470. vertexColors: material.vertexColors,
  12471. fog: fog,
  12472. useFog: material.fog,
  12473. fogExp: fog instanceof THREE.FogExp2,
  12474. flatShading: material.shading === THREE.FlatShading,
  12475. sizeAttenuation: material.sizeAttenuation,
  12476. logarithmicDepthBuffer: _logarithmicDepthBuffer,
  12477. skinning: material.skinning,
  12478. maxBones: maxBones,
  12479. useVertexTexture: _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  12480. morphTargets: material.morphTargets,
  12481. morphNormals: material.morphNormals,
  12482. maxMorphTargets: _this.maxMorphTargets,
  12483. maxMorphNormals: _this.maxMorphNormals,
  12484. maxDirLights: maxLightCount.directional,
  12485. maxPointLights: maxLightCount.point,
  12486. maxSpotLights: maxLightCount.spot,
  12487. maxHemiLights: maxLightCount.hemi,
  12488. maxShadows: maxShadows,
  12489. shadowMapEnabled: shadowMap.enabled && object.receiveShadow && maxShadows > 0,
  12490. shadowMapType: shadowMap.type,
  12491. shadowMapDebug: shadowMap.debug,
  12492. shadowMapCascade: shadowMap.cascade,
  12493. alphaTest: material.alphaTest,
  12494. metal: material.metal,
  12495. doubleSided: material.side === THREE.DoubleSide,
  12496. flipSided: material.side === THREE.BackSide
  12497. };
  12498. // Generate code
  12499. var chunks = [];
  12500. if ( shaderID ) {
  12501. chunks.push( shaderID );
  12502. } else {
  12503. chunks.push( material.fragmentShader );
  12504. chunks.push( material.vertexShader );
  12505. }
  12506. if ( material.defines !== undefined ) {
  12507. for ( var name in material.defines ) {
  12508. chunks.push( name );
  12509. chunks.push( material.defines[ name ] );
  12510. }
  12511. }
  12512. for ( var name in parameters ) {
  12513. chunks.push( name );
  12514. chunks.push( parameters[ name ] );
  12515. }
  12516. var code = chunks.join();
  12517. var programChange = true;
  12518. if ( !materialProperties.program ) {
  12519. // new material
  12520. material.addEventListener( 'dispose', onMaterialDispose );
  12521. } else if ( materialProperties.program.code !== code ) {
  12522. // changed glsl or parameters
  12523. releaseMaterialProgramReference( material );
  12524. } else if ( shaderID !== undefined ) {
  12525. // same glsl and uniform list
  12526. return;
  12527. } else {
  12528. // only rebuild uniform list
  12529. programChange = false;
  12530. }
  12531. if ( shaderID ) {
  12532. var shader = THREE.ShaderLib[ shaderID ];
  12533. materialProperties.__webglShader = {
  12534. name: material.type,
  12535. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  12536. vertexShader: shader.vertexShader,
  12537. fragmentShader: shader.fragmentShader
  12538. };
  12539. } else {
  12540. materialProperties.__webglShader = {
  12541. name: material.type,
  12542. uniforms: material.uniforms,
  12543. vertexShader: material.vertexShader,
  12544. fragmentShader: material.fragmentShader
  12545. };
  12546. }
  12547. var program;
  12548. // Check if code has been already compiled
  12549. for ( var p = 0, pl = _programs.length; p < pl; p ++ ) {
  12550. var programInfo = _programs[ p ];
  12551. if ( programInfo.code === code ) {
  12552. program = programInfo;
  12553. if ( programChange ) {
  12554. program.usedTimes ++;
  12555. }
  12556. break;
  12557. }
  12558. }
  12559. if ( program === undefined ) {
  12560. material.__webglShader = materialProperties.__webglShader;
  12561. program = new THREE.WebGLProgram( _this, code, material, parameters );
  12562. _programs.push( program );
  12563. _infoMemory.programs = _programs.length;
  12564. }
  12565. materialProperties.program = program;
  12566. var attributes = program.getAttributes();
  12567. if ( material.morphTargets ) {
  12568. material.numSupportedMorphTargets = 0;
  12569. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  12570. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  12571. material.numSupportedMorphTargets ++;
  12572. }
  12573. }
  12574. }
  12575. if ( material.morphNormals ) {
  12576. material.numSupportedMorphNormals = 0;
  12577. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  12578. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  12579. material.numSupportedMorphNormals ++;
  12580. }
  12581. }
  12582. }
  12583. materialProperties.uniformsList = [];
  12584. var uniformLocations = materialProperties.program.getUniforms();
  12585. for ( var u in materialProperties.__webglShader.uniforms ) {
  12586. var location = uniformLocations[ u ];
  12587. if ( location ) {
  12588. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  12589. }
  12590. }
  12591. }
  12592. function setMaterial( material ) {
  12593. setMaterialFaces( material );
  12594. if ( material.transparent === true ) {
  12595. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  12596. } else {
  12597. state.setBlending( THREE.NoBlending );
  12598. }
  12599. state.setDepthFunc( material.depthFunc );
  12600. state.setDepthTest( material.depthTest );
  12601. state.setDepthWrite( material.depthWrite );
  12602. state.setColorWrite( material.colorWrite );
  12603. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12604. }
  12605. function setMaterialFaces( material ) {
  12606. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  12607. state.setFlipSided( material.side === THREE.BackSide );
  12608. }
  12609. function setProgram( camera, lights, fog, material, object ) {
  12610. _usedTextureUnits = 0;
  12611. var materialProperties = properties.get( material );
  12612. if ( material.needsUpdate || ! materialProperties.program ) {
  12613. initMaterial( material, lights, fog, object );
  12614. material.needsUpdate = false;
  12615. }
  12616. var refreshProgram = false;
  12617. var refreshMaterial = false;
  12618. var refreshLights = false;
  12619. var program = materialProperties.program,
  12620. p_uniforms = program.getUniforms(),
  12621. m_uniforms = materialProperties.__webglShader.uniforms;
  12622. if ( program.id !== _currentProgram ) {
  12623. _gl.useProgram( program.program );
  12624. _currentProgram = program.id;
  12625. refreshProgram = true;
  12626. refreshMaterial = true;
  12627. refreshLights = true;
  12628. }
  12629. if ( material.id !== _currentMaterialId ) {
  12630. if ( _currentMaterialId === -1 ) refreshLights = true;
  12631. _currentMaterialId = material.id;
  12632. refreshMaterial = true;
  12633. }
  12634. if ( refreshProgram || camera !== _currentCamera ) {
  12635. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  12636. if ( _logarithmicDepthBuffer ) {
  12637. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  12638. }
  12639. if ( camera !== _currentCamera ) _currentCamera = camera;
  12640. // load material specific uniforms
  12641. // (shader material also gets them for the sake of genericity)
  12642. if ( material instanceof THREE.ShaderMaterial ||
  12643. material instanceof THREE.MeshPhongMaterial ||
  12644. material.envMap ) {
  12645. if ( p_uniforms.cameraPosition !== null ) {
  12646. _vector3.setFromMatrixPosition( camera.matrixWorld );
  12647. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  12648. }
  12649. }
  12650. if ( material instanceof THREE.MeshPhongMaterial ||
  12651. material instanceof THREE.MeshLambertMaterial ||
  12652. material instanceof THREE.MeshBasicMaterial ||
  12653. material instanceof THREE.ShaderMaterial ||
  12654. material.skinning ) {
  12655. if ( p_uniforms.viewMatrix !== null ) {
  12656. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  12657. }
  12658. }
  12659. }
  12660. // skinning uniforms must be set even if material didn't change
  12661. // auto-setting of texture unit for bone texture must go before other textures
  12662. // not sure why, but otherwise weird things happen
  12663. if ( material.skinning ) {
  12664. if ( object.bindMatrix && p_uniforms.bindMatrix !== null ) {
  12665. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  12666. }
  12667. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== null ) {
  12668. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  12669. }
  12670. if ( _supportsBoneTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  12671. if ( p_uniforms.boneTexture !== null ) {
  12672. var textureUnit = getTextureUnit();
  12673. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  12674. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  12675. }
  12676. if ( p_uniforms.boneTextureWidth !== null ) {
  12677. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  12678. }
  12679. if ( p_uniforms.boneTextureHeight !== null ) {
  12680. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  12681. }
  12682. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  12683. if ( p_uniforms.boneGlobalMatrices !== null ) {
  12684. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  12685. }
  12686. }
  12687. }
  12688. if ( refreshMaterial ) {
  12689. // refresh uniforms common to several materials
  12690. if ( fog && material.fog ) {
  12691. refreshUniformsFog( m_uniforms, fog );
  12692. }
  12693. if ( material instanceof THREE.MeshPhongMaterial ||
  12694. material instanceof THREE.MeshLambertMaterial ||
  12695. material.lights ) {
  12696. if ( _lightsNeedUpdate ) {
  12697. refreshLights = true;
  12698. setupLights( lights );
  12699. _lightsNeedUpdate = false;
  12700. }
  12701. if ( refreshLights ) {
  12702. refreshUniformsLights( m_uniforms, _lights );
  12703. markUniformsLightsNeedsUpdate( m_uniforms, true );
  12704. } else {
  12705. markUniformsLightsNeedsUpdate( m_uniforms, false );
  12706. }
  12707. }
  12708. if ( material instanceof THREE.MeshBasicMaterial ||
  12709. material instanceof THREE.MeshLambertMaterial ||
  12710. material instanceof THREE.MeshPhongMaterial ) {
  12711. refreshUniformsCommon( m_uniforms, material );
  12712. }
  12713. // refresh single material specific uniforms
  12714. if ( material instanceof THREE.LineBasicMaterial ) {
  12715. refreshUniformsLine( m_uniforms, material );
  12716. } else if ( material instanceof THREE.LineDashedMaterial ) {
  12717. refreshUniformsLine( m_uniforms, material );
  12718. refreshUniformsDash( m_uniforms, material );
  12719. } else if ( material instanceof THREE.PointCloudMaterial ) {
  12720. refreshUniformsParticle( m_uniforms, material );
  12721. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  12722. refreshUniformsPhong( m_uniforms, material );
  12723. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  12724. refreshUniformsLambert( m_uniforms, material );
  12725. } else if ( material instanceof THREE.MeshBasicMaterial ) {
  12726. refreshUniformsBasic( m_uniforms, material );
  12727. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  12728. m_uniforms.mNear.value = camera.near;
  12729. m_uniforms.mFar.value = camera.far;
  12730. m_uniforms.opacity.value = material.opacity;
  12731. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  12732. m_uniforms.opacity.value = material.opacity;
  12733. }
  12734. if ( object.receiveShadow && ! material._shadowPass ) {
  12735. refreshUniformsShadow( m_uniforms, lights );
  12736. }
  12737. // load common uniforms
  12738. loadUniformsGeneric( materialProperties.uniformsList );
  12739. }
  12740. loadUniformsMatrices( p_uniforms, object );
  12741. if ( p_uniforms.modelMatrix !== null ) {
  12742. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  12743. }
  12744. return program;
  12745. }
  12746. // Uniforms (refresh uniforms objects)
  12747. function refreshUniformsCommon ( uniforms, material ) {
  12748. uniforms.opacity.value = material.opacity;
  12749. uniforms.diffuse.value = material.color;
  12750. uniforms.map.value = material.map;
  12751. uniforms.specularMap.value = material.specularMap;
  12752. uniforms.alphaMap.value = material.alphaMap;
  12753. if ( material.bumpMap ) {
  12754. uniforms.bumpMap.value = material.bumpMap;
  12755. uniforms.bumpScale.value = material.bumpScale;
  12756. }
  12757. if ( material.normalMap ) {
  12758. uniforms.normalMap.value = material.normalMap;
  12759. uniforms.normalScale.value.copy( material.normalScale );
  12760. }
  12761. // uv repeat and offset setting priorities
  12762. // 1. color map
  12763. // 2. specular map
  12764. // 3. normal map
  12765. // 4. bump map
  12766. // 5. alpha map
  12767. // 6. emissive map
  12768. var uvScaleMap;
  12769. if ( material.map ) {
  12770. uvScaleMap = material.map;
  12771. } else if ( material.specularMap ) {
  12772. uvScaleMap = material.specularMap;
  12773. } else if ( material.normalMap ) {
  12774. uvScaleMap = material.normalMap;
  12775. } else if ( material.bumpMap ) {
  12776. uvScaleMap = material.bumpMap;
  12777. } else if ( material.alphaMap ) {
  12778. uvScaleMap = material.alphaMap;
  12779. } else if ( material.emissiveMap ) {
  12780. uvScaleMap = material.emissiveMap;
  12781. }
  12782. if ( uvScaleMap !== undefined ) {
  12783. var offset = uvScaleMap.offset;
  12784. var repeat = uvScaleMap.repeat;
  12785. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  12786. }
  12787. uniforms.envMap.value = material.envMap;
  12788. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  12789. uniforms.reflectivity.value = material.reflectivity;
  12790. uniforms.refractionRatio.value = material.refractionRatio;
  12791. }
  12792. function refreshUniformsLine ( uniforms, material ) {
  12793. uniforms.diffuse.value = material.color;
  12794. uniforms.opacity.value = material.opacity;
  12795. }
  12796. function refreshUniformsDash ( uniforms, material ) {
  12797. uniforms.dashSize.value = material.dashSize;
  12798. uniforms.totalSize.value = material.dashSize + material.gapSize;
  12799. uniforms.scale.value = material.scale;
  12800. }
  12801. function refreshUniformsParticle ( uniforms, material ) {
  12802. uniforms.psColor.value = material.color;
  12803. uniforms.opacity.value = material.opacity;
  12804. uniforms.size.value = material.size;
  12805. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  12806. uniforms.map.value = material.map;
  12807. if ( material.map !== null ) {
  12808. var offset = material.map.offset;
  12809. var repeat = material.map.repeat;
  12810. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  12811. }
  12812. }
  12813. function refreshUniformsFog ( uniforms, fog ) {
  12814. uniforms.fogColor.value = fog.color;
  12815. if ( fog instanceof THREE.Fog ) {
  12816. uniforms.fogNear.value = fog.near;
  12817. uniforms.fogFar.value = fog.far;
  12818. } else if ( fog instanceof THREE.FogExp2 ) {
  12819. uniforms.fogDensity.value = fog.density;
  12820. }
  12821. }
  12822. function refreshUniformsPhong ( uniforms, material ) {
  12823. uniforms.shininess.value = material.shininess;
  12824. uniforms.emissive.value = material.emissive;
  12825. uniforms.specular.value = material.specular;
  12826. uniforms.lightMap.value = material.lightMap;
  12827. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  12828. uniforms.aoMap.value = material.aoMap;
  12829. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  12830. uniforms.emissiveMap.value = material.emissiveMap;
  12831. }
  12832. function refreshUniformsLambert ( uniforms, material ) {
  12833. uniforms.emissive.value = material.emissive;
  12834. }
  12835. function refreshUniformsBasic ( uniforms, material ) {
  12836. uniforms.aoMap.value = material.aoMap;
  12837. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  12838. }
  12839. function refreshUniformsLights ( uniforms, lights ) {
  12840. uniforms.ambientLightColor.value = lights.ambient;
  12841. uniforms.directionalLightColor.value = lights.directional.colors;
  12842. uniforms.directionalLightDirection.value = lights.directional.positions;
  12843. uniforms.pointLightColor.value = lights.point.colors;
  12844. uniforms.pointLightPosition.value = lights.point.positions;
  12845. uniforms.pointLightDistance.value = lights.point.distances;
  12846. uniforms.pointLightDecay.value = lights.point.decays;
  12847. uniforms.spotLightColor.value = lights.spot.colors;
  12848. uniforms.spotLightPosition.value = lights.spot.positions;
  12849. uniforms.spotLightDistance.value = lights.spot.distances;
  12850. uniforms.spotLightDirection.value = lights.spot.directions;
  12851. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  12852. uniforms.spotLightExponent.value = lights.spot.exponents;
  12853. uniforms.spotLightDecay.value = lights.spot.decays;
  12854. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  12855. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  12856. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  12857. }
  12858. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  12859. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  12860. uniforms.ambientLightColor.needsUpdate = value;
  12861. uniforms.directionalLightColor.needsUpdate = value;
  12862. uniforms.directionalLightDirection.needsUpdate = value;
  12863. uniforms.pointLightColor.needsUpdate = value;
  12864. uniforms.pointLightPosition.needsUpdate = value;
  12865. uniforms.pointLightDistance.needsUpdate = value;
  12866. uniforms.pointLightDecay.needsUpdate = value;
  12867. uniforms.spotLightColor.needsUpdate = value;
  12868. uniforms.spotLightPosition.needsUpdate = value;
  12869. uniforms.spotLightDistance.needsUpdate = value;
  12870. uniforms.spotLightDirection.needsUpdate = value;
  12871. uniforms.spotLightAngleCos.needsUpdate = value;
  12872. uniforms.spotLightExponent.needsUpdate = value;
  12873. uniforms.spotLightDecay.needsUpdate = value;
  12874. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  12875. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  12876. uniforms.hemisphereLightDirection.needsUpdate = value;
  12877. }
  12878. function refreshUniformsShadow ( uniforms, lights ) {
  12879. if ( uniforms.shadowMatrix ) {
  12880. var j = 0;
  12881. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  12882. var light = lights[ i ];
  12883. if ( ! light.castShadow ) continue;
  12884. if ( light instanceof THREE.SpotLight || ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) ) {
  12885. uniforms.shadowMap.value[ j ] = light.shadowMap;
  12886. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  12887. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  12888. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  12889. uniforms.shadowBias.value[ j ] = light.shadowBias;
  12890. j ++;
  12891. }
  12892. }
  12893. }
  12894. }
  12895. // Uniforms (load to GPU)
  12896. function loadUniformsMatrices ( uniforms, object ) {
  12897. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object._modelViewMatrix.elements );
  12898. if ( uniforms.normalMatrix ) {
  12899. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object._normalMatrix.elements );
  12900. }
  12901. }
  12902. function getTextureUnit() {
  12903. var textureUnit = _usedTextureUnits;
  12904. if ( textureUnit >= _maxTextures ) {
  12905. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + _maxTextures );
  12906. }
  12907. _usedTextureUnits += 1;
  12908. return textureUnit;
  12909. }
  12910. function loadUniformsGeneric ( uniforms ) {
  12911. var texture, textureUnit, offset;
  12912. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  12913. var uniform = uniforms[ j ][ 0 ];
  12914. // needsUpdate property is not added to all uniforms.
  12915. if ( uniform.needsUpdate === false ) continue;
  12916. var type = uniform.type;
  12917. var value = uniform.value;
  12918. var location = uniforms[ j ][ 1 ];
  12919. switch ( type ) {
  12920. case '1i':
  12921. _gl.uniform1i( location, value );
  12922. break;
  12923. case '1f':
  12924. _gl.uniform1f( location, value );
  12925. break;
  12926. case '2f':
  12927. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  12928. break;
  12929. case '3f':
  12930. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  12931. break;
  12932. case '4f':
  12933. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  12934. break;
  12935. case '1iv':
  12936. _gl.uniform1iv( location, value );
  12937. break;
  12938. case '3iv':
  12939. _gl.uniform3iv( location, value );
  12940. break;
  12941. case '1fv':
  12942. _gl.uniform1fv( location, value );
  12943. break;
  12944. case '2fv':
  12945. _gl.uniform2fv( location, value );
  12946. break;
  12947. case '3fv':
  12948. _gl.uniform3fv( location, value );
  12949. break;
  12950. case '4fv':
  12951. _gl.uniform4fv( location, value );
  12952. break;
  12953. case 'Matrix3fv':
  12954. _gl.uniformMatrix3fv( location, false, value );
  12955. break;
  12956. case 'Matrix4fv':
  12957. _gl.uniformMatrix4fv( location, false, value );
  12958. break;
  12959. //
  12960. case 'i':
  12961. // single integer
  12962. _gl.uniform1i( location, value );
  12963. break;
  12964. case 'f':
  12965. // single float
  12966. _gl.uniform1f( location, value );
  12967. break;
  12968. case 'v2':
  12969. // single THREE.Vector2
  12970. _gl.uniform2f( location, value.x, value.y );
  12971. break;
  12972. case 'v3':
  12973. // single THREE.Vector3
  12974. _gl.uniform3f( location, value.x, value.y, value.z );
  12975. break;
  12976. case 'v4':
  12977. // single THREE.Vector4
  12978. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  12979. break;
  12980. case 'c':
  12981. // single THREE.Color
  12982. _gl.uniform3f( location, value.r, value.g, value.b );
  12983. break;
  12984. case 'iv1':
  12985. // flat array of integers (JS or typed array)
  12986. _gl.uniform1iv( location, value );
  12987. break;
  12988. case 'iv':
  12989. // flat array of integers with 3 x N size (JS or typed array)
  12990. _gl.uniform3iv( location, value );
  12991. break;
  12992. case 'fv1':
  12993. // flat array of floats (JS or typed array)
  12994. _gl.uniform1fv( location, value );
  12995. break;
  12996. case 'fv':
  12997. // flat array of floats with 3 x N size (JS or typed array)
  12998. _gl.uniform3fv( location, value );
  12999. break;
  13000. case 'v2v':
  13001. // array of THREE.Vector2
  13002. if ( uniform._array === undefined ) {
  13003. uniform._array = new Float32Array( 2 * value.length );
  13004. }
  13005. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13006. offset = i * 2;
  13007. uniform._array[ offset + 0 ] = value[ i ].x;
  13008. uniform._array[ offset + 1 ] = value[ i ].y;
  13009. }
  13010. _gl.uniform2fv( location, uniform._array );
  13011. break;
  13012. case 'v3v':
  13013. // array of THREE.Vector3
  13014. if ( uniform._array === undefined ) {
  13015. uniform._array = new Float32Array( 3 * value.length );
  13016. }
  13017. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13018. offset = i * 3;
  13019. uniform._array[ offset + 0 ] = value[ i ].x;
  13020. uniform._array[ offset + 1 ] = value[ i ].y;
  13021. uniform._array[ offset + 2 ] = value[ i ].z;
  13022. }
  13023. _gl.uniform3fv( location, uniform._array );
  13024. break;
  13025. case 'v4v':
  13026. // array of THREE.Vector4
  13027. if ( uniform._array === undefined ) {
  13028. uniform._array = new Float32Array( 4 * value.length );
  13029. }
  13030. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13031. offset = i * 4;
  13032. uniform._array[ offset + 0 ] = value[ i ].x;
  13033. uniform._array[ offset + 1 ] = value[ i ].y;
  13034. uniform._array[ offset + 2 ] = value[ i ].z;
  13035. uniform._array[ offset + 3 ] = value[ i ].w;
  13036. }
  13037. _gl.uniform4fv( location, uniform._array );
  13038. break;
  13039. case 'm3':
  13040. // single THREE.Matrix3
  13041. _gl.uniformMatrix3fv( location, false, value.elements );
  13042. break;
  13043. case 'm3v':
  13044. // array of THREE.Matrix3
  13045. if ( uniform._array === undefined ) {
  13046. uniform._array = new Float32Array( 9 * value.length );
  13047. }
  13048. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13049. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  13050. }
  13051. _gl.uniformMatrix3fv( location, false, uniform._array );
  13052. break;
  13053. case 'm4':
  13054. // single THREE.Matrix4
  13055. _gl.uniformMatrix4fv( location, false, value.elements );
  13056. break;
  13057. case 'm4v':
  13058. // array of THREE.Matrix4
  13059. if ( uniform._array === undefined ) {
  13060. uniform._array = new Float32Array( 16 * value.length );
  13061. }
  13062. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13063. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  13064. }
  13065. _gl.uniformMatrix4fv( location, false, uniform._array );
  13066. break;
  13067. case 't':
  13068. // single THREE.Texture (2d or cube)
  13069. texture = value;
  13070. textureUnit = getTextureUnit();
  13071. _gl.uniform1i( location, textureUnit );
  13072. if ( ! texture ) continue;
  13073. if ( texture instanceof THREE.CubeTexture ||
  13074. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) { // CompressedTexture can have Array in image :/
  13075. setCubeTexture( texture, textureUnit );
  13076. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  13077. setCubeTextureDynamic( texture, textureUnit );
  13078. } else {
  13079. _this.setTexture( texture, textureUnit );
  13080. }
  13081. break;
  13082. case 'tv':
  13083. // array of THREE.Texture (2d)
  13084. if ( uniform._array === undefined ) {
  13085. uniform._array = [];
  13086. }
  13087. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13088. uniform._array[ i ] = getTextureUnit();
  13089. }
  13090. _gl.uniform1iv( location, uniform._array );
  13091. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13092. texture = uniform.value[ i ];
  13093. textureUnit = uniform._array[ i ];
  13094. if ( ! texture ) continue;
  13095. _this.setTexture( texture, textureUnit );
  13096. }
  13097. break;
  13098. default:
  13099. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  13100. }
  13101. }
  13102. }
  13103. function setupMatrices( object, camera ) {
  13104. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13105. object._normalMatrix.getNormalMatrix( object._modelViewMatrix );
  13106. }
  13107. function setColorLinear( array, offset, color, intensity ) {
  13108. array[ offset + 0 ] = color.r * intensity;
  13109. array[ offset + 1 ] = color.g * intensity;
  13110. array[ offset + 2 ] = color.b * intensity;
  13111. }
  13112. function setupLights ( lights ) {
  13113. var l, ll, light,
  13114. r = 0, g = 0, b = 0,
  13115. color, skyColor, groundColor,
  13116. intensity,
  13117. distance,
  13118. zlights = _lights,
  13119. dirColors = zlights.directional.colors,
  13120. dirPositions = zlights.directional.positions,
  13121. pointColors = zlights.point.colors,
  13122. pointPositions = zlights.point.positions,
  13123. pointDistances = zlights.point.distances,
  13124. pointDecays = zlights.point.decays,
  13125. spotColors = zlights.spot.colors,
  13126. spotPositions = zlights.spot.positions,
  13127. spotDistances = zlights.spot.distances,
  13128. spotDirections = zlights.spot.directions,
  13129. spotAnglesCos = zlights.spot.anglesCos,
  13130. spotExponents = zlights.spot.exponents,
  13131. spotDecays = zlights.spot.decays,
  13132. hemiSkyColors = zlights.hemi.skyColors,
  13133. hemiGroundColors = zlights.hemi.groundColors,
  13134. hemiPositions = zlights.hemi.positions,
  13135. dirLength = 0,
  13136. pointLength = 0,
  13137. spotLength = 0,
  13138. hemiLength = 0,
  13139. dirCount = 0,
  13140. pointCount = 0,
  13141. spotCount = 0,
  13142. hemiCount = 0,
  13143. dirOffset = 0,
  13144. pointOffset = 0,
  13145. spotOffset = 0,
  13146. hemiOffset = 0;
  13147. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  13148. light = lights[ l ];
  13149. if ( light.onlyShadow ) continue;
  13150. color = light.color;
  13151. intensity = light.intensity;
  13152. distance = light.distance;
  13153. if ( light instanceof THREE.AmbientLight ) {
  13154. if ( ! light.visible ) continue;
  13155. r += color.r;
  13156. g += color.g;
  13157. b += color.b;
  13158. } else if ( light instanceof THREE.DirectionalLight ) {
  13159. dirCount += 1;
  13160. if ( ! light.visible ) continue;
  13161. _direction.setFromMatrixPosition( light.matrixWorld );
  13162. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13163. _direction.sub( _vector3 );
  13164. _direction.normalize();
  13165. dirOffset = dirLength * 3;
  13166. dirPositions[ dirOffset + 0 ] = _direction.x;
  13167. dirPositions[ dirOffset + 1 ] = _direction.y;
  13168. dirPositions[ dirOffset + 2 ] = _direction.z;
  13169. setColorLinear( dirColors, dirOffset, color, intensity );
  13170. dirLength += 1;
  13171. } else if ( light instanceof THREE.PointLight ) {
  13172. pointCount += 1;
  13173. if ( ! light.visible ) continue;
  13174. pointOffset = pointLength * 3;
  13175. setColorLinear( pointColors, pointOffset, color, intensity );
  13176. _vector3.setFromMatrixPosition( light.matrixWorld );
  13177. pointPositions[ pointOffset + 0 ] = _vector3.x;
  13178. pointPositions[ pointOffset + 1 ] = _vector3.y;
  13179. pointPositions[ pointOffset + 2 ] = _vector3.z;
  13180. // distance is 0 if decay is 0, because there is no attenuation at all.
  13181. pointDistances[ pointLength ] = distance;
  13182. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13183. pointLength += 1;
  13184. } else if ( light instanceof THREE.SpotLight ) {
  13185. spotCount += 1;
  13186. if ( ! light.visible ) continue;
  13187. spotOffset = spotLength * 3;
  13188. setColorLinear( spotColors, spotOffset, color, intensity );
  13189. _direction.setFromMatrixPosition( light.matrixWorld );
  13190. spotPositions[ spotOffset + 0 ] = _direction.x;
  13191. spotPositions[ spotOffset + 1 ] = _direction.y;
  13192. spotPositions[ spotOffset + 2 ] = _direction.z;
  13193. spotDistances[ spotLength ] = distance;
  13194. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13195. _direction.sub( _vector3 );
  13196. _direction.normalize();
  13197. spotDirections[ spotOffset + 0 ] = _direction.x;
  13198. spotDirections[ spotOffset + 1 ] = _direction.y;
  13199. spotDirections[ spotOffset + 2 ] = _direction.z;
  13200. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  13201. spotExponents[ spotLength ] = light.exponent;
  13202. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13203. spotLength += 1;
  13204. } else if ( light instanceof THREE.HemisphereLight ) {
  13205. hemiCount += 1;
  13206. if ( ! light.visible ) continue;
  13207. _direction.setFromMatrixPosition( light.matrixWorld );
  13208. _direction.normalize();
  13209. hemiOffset = hemiLength * 3;
  13210. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  13211. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  13212. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  13213. skyColor = light.color;
  13214. groundColor = light.groundColor;
  13215. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  13216. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  13217. hemiLength += 1;
  13218. }
  13219. }
  13220. // null eventual remains from removed lights
  13221. // (this is to avoid if in shader)
  13222. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  13223. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  13224. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  13225. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  13226. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  13227. zlights.directional.length = dirLength;
  13228. zlights.point.length = pointLength;
  13229. zlights.spot.length = spotLength;
  13230. zlights.hemi.length = hemiLength;
  13231. zlights.ambient[ 0 ] = r;
  13232. zlights.ambient[ 1 ] = g;
  13233. zlights.ambient[ 2 ] = b;
  13234. }
  13235. // GL state setting
  13236. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  13237. if ( cullFace === THREE.CullFaceNone ) {
  13238. state.disable( _gl.CULL_FACE );
  13239. } else {
  13240. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  13241. _gl.frontFace( _gl.CW );
  13242. } else {
  13243. _gl.frontFace( _gl.CCW );
  13244. }
  13245. if ( cullFace === THREE.CullFaceBack ) {
  13246. _gl.cullFace( _gl.BACK );
  13247. } else if ( cullFace === THREE.CullFaceFront ) {
  13248. _gl.cullFace( _gl.FRONT );
  13249. } else {
  13250. _gl.cullFace( _gl.FRONT_AND_BACK );
  13251. }
  13252. state.enable( _gl.CULL_FACE );
  13253. }
  13254. };
  13255. this.setMaterialFaces = setMaterialFaces;
  13256. // Textures
  13257. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  13258. var extension;
  13259. if ( isImagePowerOfTwo ) {
  13260. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  13261. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  13262. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  13263. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  13264. } else {
  13265. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  13266. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  13267. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  13268. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. ( ' + texture.sourceFile + ' )' );
  13269. }
  13270. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  13271. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  13272. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  13273. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. ( ' + texture.sourceFile + ' )' );
  13274. }
  13275. }
  13276. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13277. if ( extension && texture.type !== THREE.FloatType && texture.type !== THREE.HalfFloatType ) {
  13278. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  13279. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  13280. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  13281. }
  13282. }
  13283. }
  13284. this.uploadTexture = function ( texture, slot ) {
  13285. var textureProperties = properties.get( texture );
  13286. if ( textureProperties.__webglInit === undefined ) {
  13287. textureProperties.__webglInit = true;
  13288. texture.__webglInit = true;
  13289. texture.addEventListener( 'dispose', onTextureDispose );
  13290. textureProperties.__webglTexture = _gl.createTexture();
  13291. _infoMemory.textures ++;
  13292. }
  13293. state.activeTexture( _gl.TEXTURE0 + slot );
  13294. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  13295. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13296. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  13297. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  13298. texture.image = clampToMaxSize( texture.image, _maxTextureSize );
  13299. var image = texture.image,
  13300. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13301. glFormat = paramThreeToGL( texture.format ),
  13302. glType = paramThreeToGL( texture.type );
  13303. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  13304. var mipmap, mipmaps = texture.mipmaps;
  13305. if ( texture instanceof THREE.DataTexture ) {
  13306. // use manually created mipmaps if available
  13307. // if there are no manual mipmaps
  13308. // set 0 level mipmap and then use GL to generate other mipmap levels
  13309. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13310. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13311. mipmap = mipmaps[ i ];
  13312. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13313. }
  13314. texture.generateMipmaps = false;
  13315. } else {
  13316. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13317. }
  13318. } else if ( texture instanceof THREE.CompressedTexture ) {
  13319. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13320. mipmap = mipmaps[ i ];
  13321. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13322. if ( getCompressedTextureFormats().indexOf( glFormat ) > -1 ) {
  13323. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13324. } else {
  13325. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  13326. }
  13327. } else {
  13328. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13329. }
  13330. }
  13331. } else { // regular Texture (image, video, canvas)
  13332. // use manually created mipmaps if available
  13333. // if there are no manual mipmaps
  13334. // set 0 level mipmap and then use GL to generate other mipmap levels
  13335. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13336. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13337. mipmap = mipmaps[ i ];
  13338. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  13339. }
  13340. texture.generateMipmaps = false;
  13341. } else {
  13342. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  13343. }
  13344. }
  13345. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13346. texture.needsUpdate = false;
  13347. if ( texture.onUpdate ) texture.onUpdate( texture );
  13348. };
  13349. this.setTexture = function ( texture, slot ) {
  13350. if ( texture.needsUpdate === true ) {
  13351. var image = texture.image;
  13352. if ( image === undefined ) {
  13353. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  13354. return;
  13355. }
  13356. if ( image.complete === false ) {
  13357. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  13358. return;
  13359. }
  13360. _this.uploadTexture( texture, slot );
  13361. return;
  13362. }
  13363. state.activeTexture( _gl.TEXTURE0 + slot );
  13364. state.bindTexture( _gl.TEXTURE_2D, properties.get( texture ).__webglTexture );
  13365. };
  13366. function clampToMaxSize ( image, maxSize ) {
  13367. if ( image.width > maxSize || image.height > maxSize ) {
  13368. // Warning: Scaling through the canvas will only work with images that use
  13369. // premultiplied alpha.
  13370. var scale = maxSize / Math.max( image.width, image.height );
  13371. var canvas = document.createElement( 'canvas' );
  13372. canvas.width = Math.floor( image.width * scale );
  13373. canvas.height = Math.floor( image.height * scale );
  13374. var context = canvas.getContext( '2d' );
  13375. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  13376. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  13377. return canvas;
  13378. }
  13379. return image;
  13380. }
  13381. function setCubeTexture ( texture, slot ) {
  13382. var textureProperties = properties.get( texture );
  13383. if ( texture.image.length === 6 ) {
  13384. if ( texture.needsUpdate ) {
  13385. if ( ! textureProperties.__image__webglTextureCube ) {
  13386. texture.addEventListener( 'dispose', onTextureDispose );
  13387. textureProperties.__image__webglTextureCube = _gl.createTexture();
  13388. _infoMemory.textures ++;
  13389. }
  13390. state.activeTexture( _gl.TEXTURE0 + slot );
  13391. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13392. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13393. var isCompressed = texture instanceof THREE.CompressedTexture;
  13394. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  13395. var cubeImage = [];
  13396. for ( var i = 0; i < 6; i ++ ) {
  13397. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  13398. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], _maxCubemapSize );
  13399. } else {
  13400. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13401. }
  13402. }
  13403. var image = cubeImage[ 0 ],
  13404. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13405. glFormat = paramThreeToGL( texture.format ),
  13406. glType = paramThreeToGL( texture.type );
  13407. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  13408. for ( var i = 0; i < 6; i ++ ) {
  13409. if ( ! isCompressed ) {
  13410. if ( isDataTexture ) {
  13411. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  13412. } else {
  13413. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  13414. }
  13415. } else {
  13416. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  13417. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  13418. mipmap = mipmaps[ j ];
  13419. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13420. if ( getCompressedTextureFormats().indexOf( glFormat ) > -1 ) {
  13421. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13422. } else {
  13423. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  13424. }
  13425. } else {
  13426. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13427. }
  13428. }
  13429. }
  13430. }
  13431. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  13432. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13433. }
  13434. texture.needsUpdate = false;
  13435. if ( texture.onUpdate ) texture.onUpdate( texture );
  13436. } else {
  13437. state.activeTexture( _gl.TEXTURE0 + slot );
  13438. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13439. }
  13440. }
  13441. }
  13442. function setCubeTextureDynamic ( texture, slot ) {
  13443. state.activeTexture( _gl.TEXTURE0 + slot );
  13444. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  13445. }
  13446. // Render targets
  13447. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  13448. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13449. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget ).__webglTexture, 0 );
  13450. }
  13451. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  13452. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  13453. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13454. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  13455. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13456. /* For some reason this is not working. Defaulting to RGBA4.
  13457. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13458. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  13459. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13460. */
  13461. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13462. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  13463. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13464. } else {
  13465. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  13466. }
  13467. }
  13468. this.setRenderTarget = function ( renderTarget ) {
  13469. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  13470. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  13471. var renderTargetProperties = properties.get( renderTarget );
  13472. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  13473. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  13474. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13475. renderTargetProperties.__webglTexture = _gl.createTexture();
  13476. _infoMemory.textures ++;
  13477. // Setup texture, create render and frame buffers
  13478. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
  13479. glFormat = paramThreeToGL( renderTarget.format ),
  13480. glType = paramThreeToGL( renderTarget.type );
  13481. if ( isCube ) {
  13482. renderTargetProperties.__webglFramebuffer = [];
  13483. renderTargetProperties.__webglRenderbuffer = [];
  13484. state.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTargetProperties.__webglTexture );
  13485. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
  13486. for ( var i = 0; i < 6; i ++ ) {
  13487. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13488. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  13489. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13490. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  13491. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  13492. }
  13493. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13494. } else {
  13495. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13496. if ( renderTarget.shareDepthFrom ) {
  13497. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  13498. } else {
  13499. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  13500. }
  13501. state.bindTexture( _gl.TEXTURE_2D, renderTargetProperties.__webglTexture );
  13502. setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
  13503. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13504. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  13505. if ( renderTarget.shareDepthFrom ) {
  13506. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13507. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13508. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13509. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13510. }
  13511. } else {
  13512. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  13513. }
  13514. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13515. }
  13516. // Release everything
  13517. if ( isCube ) {
  13518. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13519. } else {
  13520. state.bindTexture( _gl.TEXTURE_2D, null );
  13521. }
  13522. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  13523. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  13524. }
  13525. var framebuffer, width, height, vx, vy;
  13526. if ( renderTarget ) {
  13527. var renderTargetProperties = properties.get( renderTarget );
  13528. if ( isCube ) {
  13529. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  13530. } else {
  13531. framebuffer = renderTargetProperties.__webglFramebuffer;
  13532. }
  13533. width = renderTarget.width;
  13534. height = renderTarget.height;
  13535. vx = 0;
  13536. vy = 0;
  13537. } else {
  13538. framebuffer = null;
  13539. width = _viewportWidth;
  13540. height = _viewportHeight;
  13541. vx = _viewportX;
  13542. vy = _viewportY;
  13543. }
  13544. if ( framebuffer !== _currentFramebuffer ) {
  13545. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13546. _gl.viewport( vx, vy, width, height );
  13547. _currentFramebuffer = framebuffer;
  13548. }
  13549. _currentWidth = width;
  13550. _currentHeight = height;
  13551. };
  13552. this.readRenderTargetPixels = function( renderTarget, x, y, width, height, buffer ) {
  13553. if ( ! ( renderTarget instanceof THREE.WebGLRenderTarget ) ) {
  13554. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  13555. return;
  13556. }
  13557. if ( properties.get( renderTarget ).__webglFramebuffer ) {
  13558. if ( renderTarget.format !== THREE.RGBAFormat ) {
  13559. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA format. readPixels can read only RGBA format.' );
  13560. return;
  13561. }
  13562. var restore = false;
  13563. if ( properties.get( renderTarget ).__webglFramebuffer !== _currentFramebuffer ) {
  13564. _gl.bindFramebuffer( _gl.FRAMEBUFFER, properties.get( renderTarget ).__webglFramebuffer );
  13565. restore = true;
  13566. }
  13567. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  13568. _gl.readPixels( x, y, width, height, _gl.RGBA, _gl.UNSIGNED_BYTE, buffer );
  13569. } else {
  13570. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  13571. }
  13572. if ( restore ) {
  13573. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  13574. }
  13575. }
  13576. };
  13577. function updateRenderTargetMipmap ( renderTarget ) {
  13578. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  13579. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( renderTarget ).__webglTexture );
  13580. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13581. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13582. } else {
  13583. state.bindTexture( _gl.TEXTURE_2D, properties.get( renderTarget ).__webglTexture );
  13584. _gl.generateMipmap( _gl.TEXTURE_2D );
  13585. state.bindTexture( _gl.TEXTURE_2D, null );
  13586. }
  13587. }
  13588. // Fallback filters for non-power-of-2 textures
  13589. function filterFallback ( f ) {
  13590. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  13591. return _gl.NEAREST;
  13592. }
  13593. return _gl.LINEAR;
  13594. }
  13595. // Map three.js constants to WebGL constants
  13596. function paramThreeToGL ( p ) {
  13597. var extension;
  13598. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  13599. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  13600. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  13601. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  13602. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  13603. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  13604. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  13605. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  13606. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  13607. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  13608. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  13609. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  13610. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  13611. if ( p === THREE.ByteType ) return _gl.BYTE;
  13612. if ( p === THREE.ShortType ) return _gl.SHORT;
  13613. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  13614. if ( p === THREE.IntType ) return _gl.INT;
  13615. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  13616. if ( p === THREE.FloatType ) return _gl.FLOAT;
  13617. extension = extensions.get( 'OES_texture_half_float' );
  13618. if ( extension !== null ) {
  13619. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  13620. }
  13621. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  13622. if ( p === THREE.RGBFormat ) return _gl.RGB;
  13623. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  13624. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  13625. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  13626. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  13627. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  13628. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  13629. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  13630. if ( p === THREE.OneFactor ) return _gl.ONE;
  13631. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  13632. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  13633. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  13634. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  13635. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  13636. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  13637. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  13638. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  13639. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  13640. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13641. if ( extension !== null ) {
  13642. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13643. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13644. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13645. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13646. }
  13647. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13648. if ( extension !== null ) {
  13649. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13650. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13651. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13652. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13653. }
  13654. extension = extensions.get( 'EXT_blend_minmax' );
  13655. if ( extension !== null ) {
  13656. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  13657. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  13658. }
  13659. return 0;
  13660. }
  13661. // Allocations
  13662. function allocateBones ( object ) {
  13663. if ( _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  13664. return 1024;
  13665. } else {
  13666. // default for when object is not specified
  13667. // ( for example when prebuilding shader to be used with multiple objects )
  13668. //
  13669. // - leave some extra space for other uniforms
  13670. // - limit here is ANGLE's 254 max uniform vectors
  13671. // (up to 54 should be safe)
  13672. var nVertexUniforms = _gl.getParameter( _gl.MAX_VERTEX_UNIFORM_VECTORS );
  13673. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  13674. var maxBones = nVertexMatrices;
  13675. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  13676. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  13677. if ( maxBones < object.skeleton.bones.length ) {
  13678. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  13679. }
  13680. }
  13681. return maxBones;
  13682. }
  13683. }
  13684. function allocateLights( lights ) {
  13685. var dirLights = 0;
  13686. var pointLights = 0;
  13687. var spotLights = 0;
  13688. var hemiLights = 0;
  13689. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13690. var light = lights[ l ];
  13691. if ( light.onlyShadow || light.visible === false ) continue;
  13692. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  13693. if ( light instanceof THREE.PointLight ) pointLights ++;
  13694. if ( light instanceof THREE.SpotLight ) spotLights ++;
  13695. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  13696. }
  13697. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  13698. }
  13699. function allocateShadows( lights ) {
  13700. var maxShadows = 0;
  13701. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13702. var light = lights[ l ];
  13703. if ( ! light.castShadow ) continue;
  13704. if ( light instanceof THREE.SpotLight ) maxShadows ++;
  13705. if ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) maxShadows ++;
  13706. }
  13707. return maxShadows;
  13708. }
  13709. // DEPRECATED
  13710. this.initMaterial = function () {
  13711. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  13712. };
  13713. this.addPrePlugin = function () {
  13714. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  13715. };
  13716. this.addPostPlugin = function () {
  13717. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  13718. };
  13719. this.updateShadowMap = function () {
  13720. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  13721. };
  13722. Object.defineProperties( this, {
  13723. shadowMapEnabled: {
  13724. get: function () {
  13725. return shadowMap.enabled;
  13726. },
  13727. set: function ( value ) {
  13728. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  13729. shadowMap.enabled = value;
  13730. }
  13731. },
  13732. shadowMapType: {
  13733. get: function () {
  13734. return shadowMap.type;
  13735. },
  13736. set: function ( value ) {
  13737. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  13738. shadowMap.type = value;
  13739. }
  13740. },
  13741. shadowMapCullFace: {
  13742. get: function () {
  13743. return shadowMap.cullFace;
  13744. },
  13745. set: function ( value ) {
  13746. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  13747. shadowMap.cullFace = value;
  13748. }
  13749. },
  13750. shadowMapDebug: {
  13751. get: function () {
  13752. return shadowMap.debug;
  13753. },
  13754. set: function ( value ) {
  13755. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  13756. shadowMap.debug = value;
  13757. }
  13758. },
  13759. shadowMapCascade: {
  13760. get: function () {
  13761. return shadowMap.cascade;
  13762. },
  13763. set: function ( value ) {
  13764. console.warn( 'THREE.WebGLRenderer: .shadowMapCascade is now .shadowMap.cascade.' );
  13765. shadowMap.cascade = value;
  13766. }
  13767. }
  13768. } );
  13769. };
  13770. // File:src/renderers/WebGLRenderTarget.js
  13771. /**
  13772. * @author szimek / https://github.com/szimek/
  13773. * @author alteredq / http://alteredqualia.com/
  13774. */
  13775. THREE.WebGLRenderTarget = function ( width, height, options ) {
  13776. this.uuid = THREE.Math.generateUUID();
  13777. this.width = width;
  13778. this.height = height;
  13779. options = options || {};
  13780. this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
  13781. this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
  13782. this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
  13783. this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
  13784. this.anisotropy = options.anisotropy !== undefined ? options.anisotropy : 1;
  13785. this.offset = new THREE.Vector2( 0, 0 );
  13786. this.repeat = new THREE.Vector2( 1, 1 );
  13787. this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
  13788. this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
  13789. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  13790. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  13791. this.generateMipmaps = true;
  13792. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  13793. };
  13794. THREE.WebGLRenderTarget.prototype = {
  13795. constructor: THREE.WebGLRenderTarget,
  13796. setSize: function ( width, height ) {
  13797. if ( this.width !== width || this.height !== height ) {
  13798. this.width = width;
  13799. this.height = height;
  13800. this.dispose();
  13801. }
  13802. },
  13803. clone: function () {
  13804. var tmp = new THREE.WebGLRenderTarget( this.width, this.height );
  13805. tmp.wrapS = this.wrapS;
  13806. tmp.wrapT = this.wrapT;
  13807. tmp.magFilter = this.magFilter;
  13808. tmp.minFilter = this.minFilter;
  13809. tmp.anisotropy = this.anisotropy;
  13810. tmp.offset.copy( this.offset );
  13811. tmp.repeat.copy( this.repeat );
  13812. tmp.format = this.format;
  13813. tmp.type = this.type;
  13814. tmp.depthBuffer = this.depthBuffer;
  13815. tmp.stencilBuffer = this.stencilBuffer;
  13816. tmp.generateMipmaps = this.generateMipmaps;
  13817. tmp.shareDepthFrom = this.shareDepthFrom;
  13818. return tmp;
  13819. },
  13820. dispose: function () {
  13821. this.dispatchEvent( { type: 'dispose' } );
  13822. }
  13823. };
  13824. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  13825. // File:src/renderers/WebGLRenderTargetCube.js
  13826. /**
  13827. * @author alteredq / http://alteredqualia.com
  13828. */
  13829. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  13830. THREE.WebGLRenderTarget.call( this, width, height, options );
  13831. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  13832. };
  13833. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  13834. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  13835. // File:src/renderers/webgl/WebGLExtensions.js
  13836. /**
  13837. * @author mrdoob / http://mrdoob.com/
  13838. */
  13839. THREE.WebGLExtensions = function ( gl ) {
  13840. var extensions = {};
  13841. this.get = function ( name ) {
  13842. if ( extensions[ name ] !== undefined ) {
  13843. return extensions[ name ];
  13844. }
  13845. var extension;
  13846. switch ( name ) {
  13847. case 'EXT_texture_filter_anisotropic':
  13848. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  13849. break;
  13850. case 'WEBGL_compressed_texture_s3tc':
  13851. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  13852. break;
  13853. case 'WEBGL_compressed_texture_pvrtc':
  13854. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  13855. break;
  13856. default:
  13857. extension = gl.getExtension( name );
  13858. }
  13859. if ( extension === null ) {
  13860. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  13861. }
  13862. extensions[ name ] = extension;
  13863. return extension;
  13864. };
  13865. };
  13866. // File:src/renderers/webgl/WebGLGeometries.js
  13867. /**
  13868. * @author mrdoob / http://mrdoob.com/
  13869. */
  13870. THREE.WebGLGeometries = function ( gl, info ) {
  13871. var geometries = {};
  13872. this.get = function ( object ) {
  13873. var geometry = object.geometry;
  13874. if ( geometries[ geometry.id ] !== undefined ) {
  13875. return geometries[ geometry.id ];
  13876. }
  13877. geometry.addEventListener( 'dispose', onGeometryDispose );
  13878. if ( geometry instanceof THREE.BufferGeometry ) {
  13879. geometries[ geometry.id ] = geometry;
  13880. } else if ( geometry instanceof THREE.Geometry ) {
  13881. if ( object._bufferGeometry === undefined ) {
  13882. object._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  13883. }
  13884. geometries[ geometry.id ] = object._bufferGeometry;
  13885. }
  13886. info.memory.geometries ++;
  13887. return geometries[ geometry.id ];
  13888. };
  13889. function onGeometryDispose( event ) {
  13890. var geometry = event.target;
  13891. var buffergeometry = geometries[ geometry.id ];
  13892. for ( var name in buffergeometry.attributes ) {
  13893. var attribute = buffergeometry.attributes[ name ];
  13894. if ( attribute.buffer !== undefined ) {
  13895. gl.deleteBuffer( attribute.buffer );
  13896. delete attribute.buffer;
  13897. }
  13898. }
  13899. geometry.removeEventListener( 'dispose', onGeometryDispose );
  13900. delete geometries[ geometry.id ];
  13901. info.memory.geometries --;
  13902. }
  13903. };
  13904. // File:src/renderers/webgl/WebGLObjects.js
  13905. /**
  13906. * @author mrdoob / http://mrdoob.com/
  13907. */
  13908. THREE.WebGLObjects = function ( gl, properties, info ) {
  13909. var objects = {};
  13910. var morphInfluences = new Float32Array( 8 );
  13911. var geometries = new THREE.WebGLGeometries( gl, info );
  13912. //
  13913. function onObjectRemoved( event ) {
  13914. var object = event.target;
  13915. object.traverse( function ( child ) {
  13916. child.removeEventListener( 'remove', onObjectRemoved );
  13917. removeObject( child );
  13918. } );
  13919. }
  13920. function removeObject( object ) {
  13921. if ( object instanceof THREE.Mesh ||
  13922. object instanceof THREE.PointCloud ||
  13923. object instanceof THREE.Line ) {
  13924. delete objects[ object.id ];
  13925. }
  13926. delete object._modelViewMatrix;
  13927. delete object._normalMatrix;
  13928. properties.delete( object );
  13929. }
  13930. //
  13931. this.objects = objects;
  13932. this.geometries = geometries;
  13933. this.init = function ( object ) {
  13934. var objectProperties = properties.get( object );
  13935. if ( objectProperties.__webglInit === undefined ) {
  13936. objectProperties.__webglInit = true;
  13937. object._modelViewMatrix = new THREE.Matrix4();
  13938. object._normalMatrix = new THREE.Matrix3();
  13939. object.addEventListener( 'removed', onObjectRemoved );
  13940. }
  13941. if ( objectProperties.__webglActive === undefined ) {
  13942. objectProperties.__webglActive = true;
  13943. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.PointCloud ) {
  13944. objects[ object.id ] = {
  13945. id: object.id,
  13946. object: object,
  13947. z: 0
  13948. };
  13949. }
  13950. }
  13951. };
  13952. function numericalSort ( a, b ) {
  13953. return b[ 0 ] - a[ 0 ];
  13954. }
  13955. function updateObject( object ) {
  13956. var geometry = geometries.get( object );
  13957. if ( object.geometry instanceof THREE.Geometry ) {
  13958. geometry.updateFromObject( object );
  13959. }
  13960. // morph targets
  13961. if ( object.morphTargetInfluences !== undefined ) {
  13962. var activeInfluences = [];
  13963. var morphTargetInfluences = object.morphTargetInfluences;
  13964. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  13965. var influence = morphTargetInfluences[ i ];
  13966. activeInfluences.push( [ influence, i ] );
  13967. }
  13968. activeInfluences.sort( numericalSort );
  13969. if ( activeInfluences.length > 8 ) {
  13970. activeInfluences.length = 8;
  13971. }
  13972. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  13973. morphInfluences[ i ] = activeInfluences[ i ][ 0 ];
  13974. var attribute = geometry.morphAttributes[ activeInfluences[ i ][ 1 ] ];
  13975. geometry.addAttribute( 'morphTarget' + i, attribute );
  13976. }
  13977. var material = object.material;
  13978. if ( material.program !== undefined ) {
  13979. var uniforms = material.program.getUniforms();
  13980. if ( uniforms.morphTargetInfluences !== null ) {
  13981. gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  13982. }
  13983. } else {
  13984. console.warn( 'TOFIX: material.program is undefined' );
  13985. }
  13986. }
  13987. //
  13988. var attributes = geometry.attributes;
  13989. for ( var name in attributes ) {
  13990. updateAttribute( attributes[ name ], name );
  13991. }
  13992. }
  13993. function updateAttribute ( attribute, name ) {
  13994. var bufferType = ( name === 'index' ) ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
  13995. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  13996. var attributeProperties = properties.get( data );
  13997. if ( attributeProperties.__webglBuffer === undefined ) {
  13998. createBuffer( attributeProperties, data, bufferType );
  13999. } else if ( attributeProperties.version !== data.version ) {
  14000. updateBuffer( attributeProperties, data, bufferType );
  14001. }
  14002. }
  14003. function createBuffer ( attributeProperties, data, bufferType ) {
  14004. attributeProperties.__webglBuffer = gl.createBuffer();
  14005. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  14006. var usage = gl.STATIC_DRAW;
  14007. if ( data instanceof THREE.DynamicBufferAttribute
  14008. || ( data instanceof THREE.InstancedBufferAttribute && data.dynamic === true )
  14009. || ( data instanceof THREE.InterleavedBuffer && data.dynamic === true ) ) {
  14010. usage = gl.DYNAMIC_DRAW;
  14011. }
  14012. gl.bufferData( bufferType, data.array, usage );
  14013. attributeProperties.version = data.version;
  14014. }
  14015. function updateBuffer ( attributeProperties, data, bufferType ) {
  14016. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  14017. if ( data.updateRange === undefined || data.updateRange.count === -1 ) { // Not using update ranges
  14018. gl.bufferSubData( bufferType, 0, data.array );
  14019. } else if ( data.updateRange.count === 0 ) {
  14020. console.error( 'THREE.WebGLObjects.updateBuffer: using updateRange for THREE.DynamicBufferAttribute and marked as needsUpdate but count is 0, ensure you are using set methods or updating manually.' );
  14021. } else {
  14022. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  14023. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  14024. data.updateRange.count = 0; // reset range
  14025. }
  14026. attributeProperties.version = data.version;
  14027. }
  14028. // returns the webgl buffer for a specified attribute
  14029. this.getAttributeBuffer = function ( attribute ) {
  14030. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14031. return properties.get( attribute.data ).__webglBuffer;
  14032. }
  14033. return properties.get( attribute ).__webglBuffer;
  14034. };
  14035. this.update = function ( renderList ) {
  14036. for ( var i = 0, ul = renderList.length; i < ul; i++ ) {
  14037. var object = renderList[i].object;
  14038. if ( object.material.visible !== false ) {
  14039. updateObject( object );
  14040. }
  14041. }
  14042. };
  14043. this.clear = function () {
  14044. objects = {};
  14045. };
  14046. };
  14047. // File:src/renderers/webgl/WebGLProgram.js
  14048. THREE.WebGLProgram = ( function () {
  14049. var programIdCount = 0;
  14050. function generateDefines( defines ) {
  14051. var chunks = [];
  14052. for ( var name in defines ) {
  14053. var value = defines[ name ];
  14054. if ( value === false ) continue;
  14055. chunks.push( '#define ' + name + ' ' + value );
  14056. }
  14057. return chunks.join( '\n' );
  14058. }
  14059. function fetchUniformLocations( gl, program, identifiers ) {
  14060. var uniforms = {};
  14061. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  14062. for ( var i = 0; i < n; i ++ ) {
  14063. var info = gl.getActiveUniform( program , i );
  14064. var name = info.name;
  14065. var location = gl.getUniformLocation( program, name );
  14066. //console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  14067. var suffixPos = name.lastIndexOf( '[0]' );
  14068. if ( suffixPos !== -1 && suffixPos === name.length - 3 ) {
  14069. uniforms[ name.substr( 0, suffixPos ) ] = location;
  14070. }
  14071. uniforms[ name ] = location;
  14072. }
  14073. return uniforms;
  14074. }
  14075. function fetchAttributeLocations( gl, program, identifiers ) {
  14076. var attributes = {};
  14077. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  14078. for ( var i = 0; i < n; i ++ ) {
  14079. var info = gl.getActiveAttrib( program , i );
  14080. var name = info.name;
  14081. //console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name);
  14082. attributes[ name ] = gl.getAttribLocation( program, name );
  14083. }
  14084. return attributes;
  14085. }
  14086. function filterEmptyLine( string ) {
  14087. return string !== '';
  14088. }
  14089. return function ( renderer, code, material, parameters ) {
  14090. var gl = renderer.context;
  14091. var defines = material.defines;
  14092. var vertexShader = material.__webglShader.vertexShader;
  14093. var fragmentShader = material.__webglShader.fragmentShader;
  14094. var index0AttributeName = material.index0AttributeName;
  14095. /*
  14096. if ( index0AttributeName === undefined && parameters.morphTargets === true ) {
  14097. // programs with morphTargets displace position out of attribute 0
  14098. index0AttributeName = 'position';
  14099. }
  14100. */
  14101. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  14102. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  14103. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  14104. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  14105. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  14106. }
  14107. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14108. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  14109. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14110. if ( parameters.envMap ) {
  14111. switch ( material.envMap.mapping ) {
  14112. case THREE.CubeReflectionMapping:
  14113. case THREE.CubeRefractionMapping:
  14114. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14115. break;
  14116. case THREE.EquirectangularReflectionMapping:
  14117. case THREE.EquirectangularRefractionMapping:
  14118. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  14119. break;
  14120. case THREE.SphericalReflectionMapping:
  14121. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  14122. break;
  14123. }
  14124. switch ( material.envMap.mapping ) {
  14125. case THREE.CubeRefractionMapping:
  14126. case THREE.EquirectangularRefractionMapping:
  14127. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  14128. break;
  14129. }
  14130. switch ( material.combine ) {
  14131. case THREE.MultiplyOperation:
  14132. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14133. break;
  14134. case THREE.MixOperation:
  14135. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  14136. break;
  14137. case THREE.AddOperation:
  14138. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  14139. break;
  14140. }
  14141. }
  14142. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  14143. // console.log( 'building new program ' );
  14144. //
  14145. var customDefines = generateDefines( defines );
  14146. //
  14147. var program = gl.createProgram();
  14148. var prefixVertex, prefixFragment;
  14149. if ( material instanceof THREE.RawShaderMaterial ) {
  14150. prefixVertex = '';
  14151. prefixFragment = '';
  14152. } else {
  14153. prefixVertex = [
  14154. 'precision ' + parameters.precision + ' float;',
  14155. 'precision ' + parameters.precision + ' int;',
  14156. '#define SHADER_NAME ' + material.__webglShader.name,
  14157. customDefines,
  14158. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  14159. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14160. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14161. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14162. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14163. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14164. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14165. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14166. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14167. '#define MAX_BONES ' + parameters.maxBones,
  14168. parameters.map ? '#define USE_MAP' : '',
  14169. parameters.envMap ? '#define USE_ENVMAP' : '',
  14170. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14171. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14172. parameters.aoMap ? '#define USE_AOMAP' : '',
  14173. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14174. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14175. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14176. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14177. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14178. parameters.vertexColors ? '#define USE_COLOR' : '',
  14179. parameters.flatShading ? '#define FLAT_SHADED': '',
  14180. parameters.skinning ? '#define USE_SKINNING' : '',
  14181. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  14182. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  14183. parameters.morphNormals ? '#define USE_MORPHNORMALS' : '',
  14184. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14185. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14186. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14187. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14188. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14189. parameters.shadowMapCascade ? '#define SHADOWMAP_CASCADE' : '',
  14190. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  14191. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14192. parameters.logarithmicDepthBuffer && renderer.extensions.get('EXT_frag_depth') ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14193. 'uniform mat4 modelMatrix;',
  14194. 'uniform mat4 modelViewMatrix;',
  14195. 'uniform mat4 projectionMatrix;',
  14196. 'uniform mat4 viewMatrix;',
  14197. 'uniform mat3 normalMatrix;',
  14198. 'uniform vec3 cameraPosition;',
  14199. 'attribute vec3 position;',
  14200. 'attribute vec3 normal;',
  14201. 'attribute vec2 uv;',
  14202. '#ifdef USE_COLOR',
  14203. ' attribute vec3 color;',
  14204. '#endif',
  14205. '#ifdef USE_MORPHTARGETS',
  14206. ' attribute vec3 morphTarget0;',
  14207. ' attribute vec3 morphTarget1;',
  14208. ' attribute vec3 morphTarget2;',
  14209. ' attribute vec3 morphTarget3;',
  14210. ' #ifdef USE_MORPHNORMALS',
  14211. ' attribute vec3 morphNormal0;',
  14212. ' attribute vec3 morphNormal1;',
  14213. ' attribute vec3 morphNormal2;',
  14214. ' attribute vec3 morphNormal3;',
  14215. ' #else',
  14216. ' attribute vec3 morphTarget4;',
  14217. ' attribute vec3 morphTarget5;',
  14218. ' attribute vec3 morphTarget6;',
  14219. ' attribute vec3 morphTarget7;',
  14220. ' #endif',
  14221. '#endif',
  14222. '#ifdef USE_SKINNING',
  14223. ' attribute vec4 skinIndex;',
  14224. ' attribute vec4 skinWeight;',
  14225. '#endif',
  14226. '\n'
  14227. ].filter( filterEmptyLine ).join( '\n' );
  14228. prefixFragment = [
  14229. ( parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  14230. 'precision ' + parameters.precision + ' float;',
  14231. 'precision ' + parameters.precision + ' int;',
  14232. '#define SHADER_NAME ' + material.__webglShader.name,
  14233. customDefines,
  14234. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14235. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14236. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14237. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14238. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14239. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  14240. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14241. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14242. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14243. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  14244. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  14245. parameters.map ? '#define USE_MAP' : '',
  14246. parameters.envMap ? '#define USE_ENVMAP' : '',
  14247. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  14248. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14249. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  14250. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14251. parameters.aoMap ? '#define USE_AOMAP' : '',
  14252. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14253. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14254. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14255. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14256. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14257. parameters.vertexColors ? '#define USE_COLOR' : '',
  14258. parameters.flatShading ? '#define FLAT_SHADED': '',
  14259. parameters.metal ? '#define METAL' : '',
  14260. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14261. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14262. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14263. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14264. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14265. parameters.shadowMapCascade ? '#define SHADOWMAP_CASCADE' : '',
  14266. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14267. parameters.logarithmicDepthBuffer && renderer.extensions.get('EXT_frag_depth') ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14268. 'uniform mat4 viewMatrix;',
  14269. 'uniform vec3 cameraPosition;',
  14270. '\n'
  14271. ].filter( filterEmptyLine ).join( '\n' );
  14272. }
  14273. var vertexGlsl = prefixVertex + vertexShader;
  14274. var fragmentGlsl = prefixFragment + fragmentShader;
  14275. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  14276. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  14277. gl.attachShader( program, glVertexShader );
  14278. gl.attachShader( program, glFragmentShader );
  14279. if ( index0AttributeName !== undefined ) {
  14280. // Force a particular attribute to index 0.
  14281. // because potentially expensive emulation is done by browser if attribute 0 is disabled.
  14282. // And, color, for example is often automatically bound to index 0 so disabling it
  14283. gl.bindAttribLocation( program, 0, index0AttributeName );
  14284. }
  14285. gl.linkProgram( program );
  14286. var programLog = gl.getProgramInfoLog( program );
  14287. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  14288. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  14289. var runnable = true;
  14290. var haveDiagnostics = true;
  14291. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  14292. runnable = false;
  14293. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  14294. } else if ( programLog !== '' ) {
  14295. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  14296. } else if ( vertexLog === '' || fragmentLog === '' ) {
  14297. haveDiagnostics = false;
  14298. }
  14299. if ( haveDiagnostics ) {
  14300. this.diagnostics = {
  14301. runnable: runnable,
  14302. material: material,
  14303. programLog: programLog,
  14304. vertexShader: {
  14305. log: vertexLog,
  14306. prefix: prefixVertex
  14307. },
  14308. fragmentShader: {
  14309. log: fragmentLog,
  14310. prefix: prefixFragment
  14311. }
  14312. };
  14313. }
  14314. // clean up
  14315. gl.deleteShader( glVertexShader );
  14316. gl.deleteShader( glFragmentShader );
  14317. // set up caching for uniform locations
  14318. var cachedUniforms;
  14319. this.getUniforms = function() {
  14320. if ( cachedUniforms === undefined ) {
  14321. cachedUniforms = fetchUniformLocations( gl, program );
  14322. }
  14323. return cachedUniforms;
  14324. };
  14325. // set up caching for attribute locations
  14326. var cachedAttributes;
  14327. this.getAttributes = function() {
  14328. if ( cachedAttributes === undefined ) {
  14329. cachedAttributes = fetchAttributeLocations( gl, program );
  14330. }
  14331. return cachedAttributes;
  14332. };
  14333. // DEPRECATED
  14334. Object.defineProperties( this, {
  14335. uniforms: {
  14336. get: function() {
  14337. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  14338. return this.getUniforms();
  14339. }
  14340. },
  14341. attributes: {
  14342. get: function() {
  14343. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  14344. return this.getAttributes();
  14345. }
  14346. }
  14347. });
  14348. //
  14349. this.id = programIdCount ++;
  14350. this.code = code;
  14351. this.usedTimes = 1;
  14352. this.program = program;
  14353. this.vertexShader = glVertexShader;
  14354. this.fragmentShader = glFragmentShader;
  14355. return this;
  14356. };
  14357. } )();
  14358. // File:src/renderers/webgl/WebGLProperties.js
  14359. /**
  14360. * @author fordacious / fordacious.github.io
  14361. */
  14362. THREE.WebGLProperties = function () {
  14363. var properties = {};
  14364. this.get = function ( object ) {
  14365. var uuid = object.uuid;
  14366. var map = properties[ uuid ];
  14367. if ( map === undefined ) {
  14368. map = {};
  14369. properties[ uuid ] = map;
  14370. }
  14371. return map;
  14372. };
  14373. this.delete = function ( object ) {
  14374. delete properties[ object.uuid ];
  14375. };
  14376. this.clear = function () {
  14377. properties = {};
  14378. };
  14379. };
  14380. // File:src/renderers/webgl/WebGLShader.js
  14381. THREE.WebGLShader = ( function () {
  14382. var addLineNumbers = function ( string ) {
  14383. var lines = string.split( '\n' );
  14384. for ( var i = 0; i < lines.length; i ++ ) {
  14385. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  14386. }
  14387. return lines.join( '\n' );
  14388. };
  14389. return function ( gl, type, string ) {
  14390. var shader = gl.createShader( type );
  14391. gl.shaderSource( shader, string );
  14392. gl.compileShader( shader );
  14393. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  14394. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  14395. }
  14396. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  14397. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  14398. }
  14399. // --enable-privileged-webgl-extension
  14400. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  14401. return shader;
  14402. };
  14403. } )();
  14404. // File:src/renderers/webgl/WebGLShadowMap.js
  14405. /**
  14406. * @author alteredq / http://alteredqualia.com/
  14407. * @author mrdoob / http://mrdoob.com/
  14408. */
  14409. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  14410. var _gl = _renderer.context,
  14411. _state = _renderer.state,
  14412. _frustum = new THREE.Frustum(),
  14413. _projScreenMatrix = new THREE.Matrix4(),
  14414. _min = new THREE.Vector3(),
  14415. _max = new THREE.Vector3(),
  14416. _matrixPosition = new THREE.Vector3(),
  14417. _renderList = [];
  14418. // init
  14419. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  14420. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  14421. var _depthMaterial = new THREE.ShaderMaterial( {
  14422. uniforms: depthUniforms,
  14423. vertexShader: depthShader.vertexShader,
  14424. fragmentShader: depthShader.fragmentShader
  14425. } );
  14426. var _depthMaterialMorph = new THREE.ShaderMaterial( {
  14427. uniforms: depthUniforms,
  14428. vertexShader: depthShader.vertexShader,
  14429. fragmentShader: depthShader.fragmentShader,
  14430. morphTargets: true
  14431. } );
  14432. var _depthMaterialSkin = new THREE.ShaderMaterial( {
  14433. uniforms: depthUniforms,
  14434. vertexShader: depthShader.vertexShader,
  14435. fragmentShader: depthShader.fragmentShader,
  14436. skinning: true
  14437. } );
  14438. var _depthMaterialMorphSkin = new THREE.ShaderMaterial( {
  14439. uniforms: depthUniforms,
  14440. vertexShader: depthShader.vertexShader,
  14441. fragmentShader: depthShader.fragmentShader,
  14442. morphTargets: true,
  14443. skinning: true
  14444. } );
  14445. _depthMaterial._shadowPass = true;
  14446. _depthMaterialMorph._shadowPass = true;
  14447. _depthMaterialSkin._shadowPass = true;
  14448. _depthMaterialMorphSkin._shadowPass = true;
  14449. //
  14450. var scope = this;
  14451. this.enabled = false;
  14452. this.autoUpdate = true;
  14453. this.needsUpdate = false;
  14454. this.type = THREE.PCFShadowMap;
  14455. this.cullFace = THREE.CullFaceFront;
  14456. this.cascade = false;
  14457. this.render = function ( scene, camera ) {
  14458. if ( scope.enabled === false ) return;
  14459. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  14460. var i, il, j, jl, n,
  14461. shadowMap, shadowMatrix, shadowCamera,
  14462. webglObject, object, material, light,
  14463. lights = [],
  14464. k = 0,
  14465. fog = null;
  14466. // set GL state for depth map
  14467. _gl.clearColor( 1, 1, 1, 1 );
  14468. _state.disable( _gl.BLEND );
  14469. _state.enable( _gl.CULL_FACE );
  14470. _gl.frontFace( _gl.CCW );
  14471. if ( scope.cullFace === THREE.CullFaceFront ) {
  14472. _gl.cullFace( _gl.FRONT );
  14473. } else {
  14474. _gl.cullFace( _gl.BACK );
  14475. }
  14476. _state.setDepthTest( true );
  14477. // preprocess lights
  14478. // - skip lights that are not casting shadows
  14479. // - create virtual lights for cascaded shadow maps
  14480. for ( i = 0, il = _lights.length; i < il; i ++ ) {
  14481. light = _lights[ i ];
  14482. if ( ! light.castShadow ) continue;
  14483. if ( ( light instanceof THREE.DirectionalLight ) && light.shadowCascade ) {
  14484. for ( n = 0; n < light.shadowCascadeCount; n ++ ) {
  14485. var virtualLight;
  14486. if ( ! light.shadowCascadeArray[ n ] ) {
  14487. virtualLight = createVirtualLight( light, n );
  14488. virtualLight.originalCamera = camera;
  14489. var gyro = new THREE.Gyroscope();
  14490. gyro.position.copy( light.shadowCascadeOffset );
  14491. gyro.add( virtualLight );
  14492. gyro.add( virtualLight.target );
  14493. camera.add( gyro );
  14494. light.shadowCascadeArray[ n ] = virtualLight;
  14495. //console.log( "Created virtualLight", virtualLight );
  14496. } else {
  14497. virtualLight = light.shadowCascadeArray[ n ];
  14498. }
  14499. updateVirtualLight( light, n );
  14500. lights[ k ] = virtualLight;
  14501. k ++;
  14502. }
  14503. } else {
  14504. lights[ k ] = light;
  14505. k ++;
  14506. }
  14507. }
  14508. // render depth map
  14509. for ( i = 0, il = lights.length; i < il; i ++ ) {
  14510. light = lights[ i ];
  14511. if ( ! light.shadowMap ) {
  14512. var shadowFilter = THREE.LinearFilter;
  14513. if ( scope.type === THREE.PCFSoftShadowMap ) {
  14514. shadowFilter = THREE.NearestFilter;
  14515. }
  14516. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  14517. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  14518. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  14519. light.shadowMatrix = new THREE.Matrix4();
  14520. }
  14521. if ( ! light.shadowCamera ) {
  14522. if ( light instanceof THREE.SpotLight ) {
  14523. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  14524. } else if ( light instanceof THREE.DirectionalLight ) {
  14525. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  14526. } else {
  14527. console.error( "THREE.ShadowMapPlugin: Unsupported light type for shadow", light );
  14528. continue;
  14529. }
  14530. scene.add( light.shadowCamera );
  14531. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14532. }
  14533. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  14534. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  14535. scene.add( light.cameraHelper );
  14536. }
  14537. if ( light.isVirtual && virtualLight.originalCamera == camera ) {
  14538. updateShadowCamera( camera, light );
  14539. }
  14540. shadowMap = light.shadowMap;
  14541. shadowMatrix = light.shadowMatrix;
  14542. shadowCamera = light.shadowCamera;
  14543. //
  14544. shadowCamera.position.setFromMatrixPosition( light.matrixWorld );
  14545. _matrixPosition.setFromMatrixPosition( light.target.matrixWorld );
  14546. shadowCamera.lookAt( _matrixPosition );
  14547. shadowCamera.updateMatrixWorld();
  14548. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  14549. //
  14550. if ( light.cameraHelper ) light.cameraHelper.visible = light.shadowCameraVisible;
  14551. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  14552. // compute shadow matrix
  14553. shadowMatrix.set(
  14554. 0.5, 0.0, 0.0, 0.5,
  14555. 0.0, 0.5, 0.0, 0.5,
  14556. 0.0, 0.0, 0.5, 0.5,
  14557. 0.0, 0.0, 0.0, 1.0
  14558. );
  14559. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  14560. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  14561. // update camera matrices and frustum
  14562. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  14563. _frustum.setFromMatrix( _projScreenMatrix );
  14564. // render shadow map
  14565. _renderer.setRenderTarget( shadowMap );
  14566. _renderer.clear();
  14567. // set object matrices & frustum culling
  14568. _renderList.length = 0;
  14569. projectObject( scene, shadowCamera );
  14570. // render regular objects
  14571. var objectMaterial, useMorphing, useSkinning;
  14572. for ( j = 0, jl = _renderList.length; j < jl; j ++ ) {
  14573. webglObject = _renderList[ j ];
  14574. object = webglObject.object;
  14575. // culling is overridden globally for all objects
  14576. // while rendering depth map
  14577. // need to deal with MeshFaceMaterial somehow
  14578. // in that case just use the first of material.materials for now
  14579. // (proper solution would require to break objects by materials
  14580. // similarly to regular rendering and then set corresponding
  14581. // depth materials per each chunk instead of just once per object)
  14582. objectMaterial = getObjectMaterial( object );
  14583. useMorphing = object.geometry.morphTargets !== undefined && object.geometry.morphTargets.length > 0 && objectMaterial.morphTargets;
  14584. useSkinning = object instanceof THREE.SkinnedMesh && objectMaterial.skinning;
  14585. if ( object.customDepthMaterial ) {
  14586. material = object.customDepthMaterial;
  14587. } else if ( useSkinning ) {
  14588. material = useMorphing ? _depthMaterialMorphSkin : _depthMaterialSkin;
  14589. } else if ( useMorphing ) {
  14590. material = _depthMaterialMorph;
  14591. } else {
  14592. material = _depthMaterial;
  14593. }
  14594. _renderer.setMaterialFaces( objectMaterial );
  14595. _renderer.renderBufferDirect( shadowCamera, _lights, fog, material, object );
  14596. }
  14597. }
  14598. // restore GL state
  14599. var clearColor = _renderer.getClearColor(),
  14600. clearAlpha = _renderer.getClearAlpha();
  14601. _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
  14602. _state.enable( _gl.BLEND );
  14603. if ( scope.cullFace === THREE.CullFaceFront ) {
  14604. _gl.cullFace( _gl.BACK );
  14605. }
  14606. _renderer.resetGLState();
  14607. scope.needsUpdate = false;
  14608. };
  14609. function projectObject( object, camera ) {
  14610. if ( object.visible === true ) {
  14611. var webglObject = _objects.objects[ object.id ];
  14612. if ( webglObject && object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  14613. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14614. _renderList.push( webglObject );
  14615. }
  14616. for ( var i = 0, l = object.children.length; i < l; i ++ ) {
  14617. projectObject( object.children[ i ], camera );
  14618. }
  14619. }
  14620. }
  14621. function createVirtualLight( light, cascade ) {
  14622. var virtualLight = new THREE.DirectionalLight();
  14623. virtualLight.isVirtual = true;
  14624. virtualLight.onlyShadow = true;
  14625. virtualLight.castShadow = true;
  14626. virtualLight.shadowCameraNear = light.shadowCameraNear;
  14627. virtualLight.shadowCameraFar = light.shadowCameraFar;
  14628. virtualLight.shadowCameraLeft = light.shadowCameraLeft;
  14629. virtualLight.shadowCameraRight = light.shadowCameraRight;
  14630. virtualLight.shadowCameraBottom = light.shadowCameraBottom;
  14631. virtualLight.shadowCameraTop = light.shadowCameraTop;
  14632. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  14633. virtualLight.shadowDarkness = light.shadowDarkness;
  14634. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  14635. virtualLight.shadowMapWidth = light.shadowCascadeWidth[ cascade ];
  14636. virtualLight.shadowMapHeight = light.shadowCascadeHeight[ cascade ];
  14637. virtualLight.pointsWorld = [];
  14638. virtualLight.pointsFrustum = [];
  14639. var pointsWorld = virtualLight.pointsWorld,
  14640. pointsFrustum = virtualLight.pointsFrustum;
  14641. for ( var i = 0; i < 8; i ++ ) {
  14642. pointsWorld[ i ] = new THREE.Vector3();
  14643. pointsFrustum[ i ] = new THREE.Vector3();
  14644. }
  14645. var nearZ = light.shadowCascadeNearZ[ cascade ];
  14646. var farZ = light.shadowCascadeFarZ[ cascade ];
  14647. pointsFrustum[ 0 ].set( - 1, - 1, nearZ );
  14648. pointsFrustum[ 1 ].set( 1, - 1, nearZ );
  14649. pointsFrustum[ 2 ].set( - 1, 1, nearZ );
  14650. pointsFrustum[ 3 ].set( 1, 1, nearZ );
  14651. pointsFrustum[ 4 ].set( - 1, - 1, farZ );
  14652. pointsFrustum[ 5 ].set( 1, - 1, farZ );
  14653. pointsFrustum[ 6 ].set( - 1, 1, farZ );
  14654. pointsFrustum[ 7 ].set( 1, 1, farZ );
  14655. return virtualLight;
  14656. }
  14657. // Synchronize virtual light with the original light
  14658. function updateVirtualLight( light, cascade ) {
  14659. var virtualLight = light.shadowCascadeArray[ cascade ];
  14660. virtualLight.position.copy( light.position );
  14661. virtualLight.target.position.copy( light.target.position );
  14662. virtualLight.lookAt( virtualLight.target );
  14663. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  14664. virtualLight.shadowDarkness = light.shadowDarkness;
  14665. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  14666. var nearZ = light.shadowCascadeNearZ[ cascade ];
  14667. var farZ = light.shadowCascadeFarZ[ cascade ];
  14668. var pointsFrustum = virtualLight.pointsFrustum;
  14669. pointsFrustum[ 0 ].z = nearZ;
  14670. pointsFrustum[ 1 ].z = nearZ;
  14671. pointsFrustum[ 2 ].z = nearZ;
  14672. pointsFrustum[ 3 ].z = nearZ;
  14673. pointsFrustum[ 4 ].z = farZ;
  14674. pointsFrustum[ 5 ].z = farZ;
  14675. pointsFrustum[ 6 ].z = farZ;
  14676. pointsFrustum[ 7 ].z = farZ;
  14677. }
  14678. // Fit shadow camera's ortho frustum to camera frustum
  14679. function updateShadowCamera( camera, light ) {
  14680. var shadowCamera = light.shadowCamera,
  14681. pointsFrustum = light.pointsFrustum,
  14682. pointsWorld = light.pointsWorld;
  14683. _min.set( Infinity, Infinity, Infinity );
  14684. _max.set( - Infinity, - Infinity, - Infinity );
  14685. for ( var i = 0; i < 8; i ++ ) {
  14686. var p = pointsWorld[ i ];
  14687. p.copy( pointsFrustum[ i ] );
  14688. p.unproject( camera );
  14689. p.applyMatrix4( shadowCamera.matrixWorldInverse );
  14690. if ( p.x < _min.x ) _min.x = p.x;
  14691. if ( p.x > _max.x ) _max.x = p.x;
  14692. if ( p.y < _min.y ) _min.y = p.y;
  14693. if ( p.y > _max.y ) _max.y = p.y;
  14694. if ( p.z < _min.z ) _min.z = p.z;
  14695. if ( p.z > _max.z ) _max.z = p.z;
  14696. }
  14697. shadowCamera.left = _min.x;
  14698. shadowCamera.right = _max.x;
  14699. shadowCamera.top = _max.y;
  14700. shadowCamera.bottom = _min.y;
  14701. // can't really fit near/far
  14702. //shadowCamera.near = _min.z;
  14703. //shadowCamera.far = _max.z;
  14704. shadowCamera.updateProjectionMatrix();
  14705. }
  14706. // For the moment just ignore objects that have multiple materials with different animation methods
  14707. // Only the first material will be taken into account for deciding which depth material to use for shadow maps
  14708. function getObjectMaterial( object ) {
  14709. return object.material instanceof THREE.MeshFaceMaterial
  14710. ? object.material.materials[ 0 ]
  14711. : object.material;
  14712. }
  14713. };
  14714. // File:src/renderers/webgl/WebGLState.js
  14715. /**
  14716. * @author mrdoob / http://mrdoob.com/
  14717. */
  14718. THREE.WebGLState = function ( gl, paramThreeToGL ) {
  14719. var _this = this;
  14720. var newAttributes = new Uint8Array( 16 );
  14721. var enabledAttributes = new Uint8Array( 16 );
  14722. var capabilities = {};
  14723. var currentBlending = null;
  14724. var currentBlendEquation = null;
  14725. var currentBlendSrc = null;
  14726. var currentBlendDst = null;
  14727. var currentBlendEquationAlpha = null;
  14728. var currentBlendSrcAlpha = null;
  14729. var currentBlendDstAlpha = null;
  14730. var currentDepthFunc = null;
  14731. var currentDepthWrite = null;
  14732. var currentColorWrite = null;
  14733. var currentFlipSided = null;
  14734. var currentLineWidth = null;
  14735. var currentPolygonOffsetFactor = null;
  14736. var currentPolygonOffsetUnits = null;
  14737. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14738. var currentTextureSlot = undefined;
  14739. var currentBoundTextures = {};
  14740. this.init = function () {
  14741. gl.clearColor( 0, 0, 0, 1 );
  14742. gl.clearDepth( 1 );
  14743. gl.clearStencil( 0 );
  14744. this.enable( gl.DEPTH_TEST );
  14745. gl.depthFunc( gl.LEQUAL );
  14746. gl.frontFace( gl.CCW );
  14747. gl.cullFace( gl.BACK );
  14748. this.enable( gl.CULL_FACE );
  14749. this.enable( gl.BLEND );
  14750. gl.blendEquation( gl.FUNC_ADD );
  14751. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  14752. };
  14753. this.initAttributes = function () {
  14754. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  14755. newAttributes[ i ] = 0;
  14756. }
  14757. };
  14758. this.enableAttribute = function ( attribute ) {
  14759. newAttributes[ attribute ] = 1;
  14760. if ( enabledAttributes[ attribute ] === 0 ) {
  14761. gl.enableVertexAttribArray( attribute );
  14762. enabledAttributes[ attribute ] = 1;
  14763. }
  14764. };
  14765. this.disableUnusedAttributes = function () {
  14766. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  14767. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  14768. gl.disableVertexAttribArray( i );
  14769. enabledAttributes[ i ] = 0;
  14770. }
  14771. }
  14772. };
  14773. this.enable = function ( id ) {
  14774. if ( capabilities[ id ] !== true ) {
  14775. gl.enable( id );
  14776. capabilities[ id ] = true;
  14777. }
  14778. };
  14779. this.disable = function ( id ) {
  14780. if ( capabilities[ id ] !== false ) {
  14781. gl.disable( id );
  14782. capabilities[ id ] = false;
  14783. }
  14784. };
  14785. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  14786. if ( blending !== currentBlending ) {
  14787. if ( blending === THREE.NoBlending ) {
  14788. this.disable( gl.BLEND );
  14789. } else if ( blending === THREE.AdditiveBlending ) {
  14790. this.enable( gl.BLEND );
  14791. gl.blendEquation( gl.FUNC_ADD );
  14792. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  14793. } else if ( blending === THREE.SubtractiveBlending ) {
  14794. // TODO: Find blendFuncSeparate() combination
  14795. this.enable( gl.BLEND );
  14796. gl.blendEquation( gl.FUNC_ADD );
  14797. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  14798. } else if ( blending === THREE.MultiplyBlending ) {
  14799. // TODO: Find blendFuncSeparate() combination
  14800. this.enable( gl.BLEND );
  14801. gl.blendEquation( gl.FUNC_ADD );
  14802. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  14803. } else if ( blending === THREE.CustomBlending ) {
  14804. this.enable( gl.BLEND );
  14805. } else {
  14806. this.enable( gl.BLEND );
  14807. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  14808. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  14809. }
  14810. currentBlending = blending;
  14811. }
  14812. if ( blending === THREE.CustomBlending ) {
  14813. blendEquationAlpha = blendEquationAlpha || blendEquation;
  14814. blendSrcAlpha = blendSrcAlpha || blendSrc;
  14815. blendDstAlpha = blendDstAlpha || blendDst;
  14816. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  14817. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  14818. currentBlendEquation = blendEquation;
  14819. currentBlendEquationAlpha = blendEquationAlpha;
  14820. }
  14821. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  14822. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  14823. currentBlendSrc = blendSrc;
  14824. currentBlendDst = blendDst;
  14825. currentBlendSrcAlpha = blendSrcAlpha;
  14826. currentBlendDstAlpha = blendDstAlpha;
  14827. }
  14828. } else {
  14829. currentBlendEquation = null;
  14830. currentBlendSrc = null;
  14831. currentBlendDst = null;
  14832. currentBlendEquationAlpha = null;
  14833. currentBlendSrcAlpha = null;
  14834. currentBlendDstAlpha = null;
  14835. }
  14836. };
  14837. this.setDepthFunc = function ( depthFunc ) {
  14838. if ( currentDepthFunc !== depthFunc ) {
  14839. if ( depthFunc ) {
  14840. switch ( depthFunc ) {
  14841. case THREE.NeverDepth:
  14842. gl.depthFunc( gl.NEVER );
  14843. break;
  14844. case THREE.AlwaysDepth:
  14845. gl.depthFunc( gl.ALWAYS );
  14846. break;
  14847. case THREE.LessDepth:
  14848. gl.depthFunc( gl.LESS );
  14849. break;
  14850. case THREE.LessEqualDepth:
  14851. gl.depthFunc( gl.LEQUAL );
  14852. break;
  14853. case THREE.EqualDepth:
  14854. gl.depthFunc( gl.EQUAL );
  14855. break;
  14856. case THREE.GreaterEqualDepth:
  14857. gl.depthFunc( gl.GEQUAL );
  14858. break;
  14859. case THREE.GreaterDepth:
  14860. gl.depthFunc( gl.GREATER );
  14861. break;
  14862. case THREE.NotEqualDepth:
  14863. gl.depthFunc( gl.NOTEQUAL );
  14864. break;
  14865. default:
  14866. gl.depthFunc( gl.LEQUAL );
  14867. }
  14868. } else {
  14869. gl.depthFunc( gl.LEQUAL );
  14870. }
  14871. currentDepthFunc = depthFunc;
  14872. }
  14873. };
  14874. this.setDepthTest = function ( depthTest ) {
  14875. if ( depthTest ) {
  14876. this.enable( gl.DEPTH_TEST );
  14877. } else {
  14878. this.disable( gl.DEPTH_TEST );
  14879. }
  14880. };
  14881. this.setDepthWrite = function ( depthWrite ) {
  14882. if ( currentDepthWrite !== depthWrite ) {
  14883. gl.depthMask( depthWrite );
  14884. currentDepthWrite = depthWrite;
  14885. }
  14886. };
  14887. this.setColorWrite = function ( colorWrite ) {
  14888. if ( currentColorWrite !== colorWrite ) {
  14889. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  14890. currentColorWrite = colorWrite;
  14891. }
  14892. };
  14893. this.setFlipSided = function ( flipSided ) {
  14894. if ( currentFlipSided !== flipSided ) {
  14895. if ( flipSided ) {
  14896. gl.frontFace( gl.CW );
  14897. } else {
  14898. gl.frontFace( gl.CCW );
  14899. }
  14900. currentFlipSided = flipSided;
  14901. }
  14902. };
  14903. this.setLineWidth = function ( width ) {
  14904. if ( width !== currentLineWidth ) {
  14905. gl.lineWidth( width );
  14906. currentLineWidth = width;
  14907. }
  14908. };
  14909. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  14910. if ( polygonOffset ) {
  14911. this.enable( gl.POLYGON_OFFSET_FILL );
  14912. } else {
  14913. this.disable( gl.POLYGON_OFFSET_FILL );
  14914. }
  14915. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  14916. gl.polygonOffset( factor, units );
  14917. currentPolygonOffsetFactor = factor;
  14918. currentPolygonOffsetUnits = units;
  14919. }
  14920. };
  14921. this.setScissorTest = function ( scissorTest ) {
  14922. if ( scissorTest ) {
  14923. this.enable( gl.SCISSOR_TEST );
  14924. } else {
  14925. this.disable( gl.SCISSOR_TEST );
  14926. }
  14927. };
  14928. // texture
  14929. this.activeTexture = function ( webglSlot ) {
  14930. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  14931. if ( currentTextureSlot !== webglSlot ) {
  14932. gl.activeTexture( webglSlot );
  14933. currentTextureSlot = webglSlot;
  14934. }
  14935. }
  14936. this.bindTexture = function ( webglType, webglTexture ) {
  14937. if ( currentTextureSlot === undefined ) {
  14938. _this.activeTexture();
  14939. }
  14940. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  14941. if ( boundTexture === undefined ) {
  14942. boundTexture = { type: undefined, texture: undefined };
  14943. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  14944. }
  14945. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  14946. gl.bindTexture( webglType, webglTexture );
  14947. boundTexture.type = webglType;
  14948. boundTexture.texture = webglTexture;
  14949. }
  14950. };
  14951. this.compressedTexImage2D = function () {
  14952. try {
  14953. gl.compressedTexImage2D.apply( gl, arguments );
  14954. } catch ( error ) {
  14955. console.error( error );
  14956. }
  14957. };
  14958. this.texImage2D = function () {
  14959. try {
  14960. gl.texImage2D.apply( gl, arguments );
  14961. } catch ( error ) {
  14962. console.error( error );
  14963. }
  14964. };
  14965. //
  14966. this.reset = function () {
  14967. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  14968. if ( enabledAttributes[ i ] === 1 ) {
  14969. gl.disableVertexAttribArray( i );
  14970. enabledAttributes[ i ] = 0;
  14971. }
  14972. }
  14973. capabilities = {};
  14974. currentBlending = null;
  14975. currentDepthWrite = null;
  14976. currentColorWrite = null;
  14977. currentFlipSided = null;
  14978. };
  14979. };
  14980. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  14981. /**
  14982. * @author mikael emtinger / http://gomo.se/
  14983. * @author alteredq / http://alteredqualia.com/
  14984. */
  14985. THREE.LensFlarePlugin = function ( renderer, flares ) {
  14986. var gl = renderer.context;
  14987. var state = renderer.state;
  14988. var vertexBuffer, elementBuffer;
  14989. var program, attributes, uniforms;
  14990. var hasVertexTexture;
  14991. var tempTexture, occlusionTexture;
  14992. var init = function () {
  14993. var vertices = new Float32Array( [
  14994. -1, -1, 0, 0,
  14995. 1, -1, 1, 0,
  14996. 1, 1, 1, 1,
  14997. -1, 1, 0, 1
  14998. ] );
  14999. var faces = new Uint16Array( [
  15000. 0, 1, 2,
  15001. 0, 2, 3
  15002. ] );
  15003. // buffers
  15004. vertexBuffer = gl.createBuffer();
  15005. elementBuffer = gl.createBuffer();
  15006. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15007. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15008. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15009. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15010. // textures
  15011. tempTexture = gl.createTexture();
  15012. occlusionTexture = gl.createTexture();
  15013. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15014. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  15015. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15016. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15017. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15018. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15019. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15020. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  15021. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15022. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15023. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15024. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15025. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  15026. var shader;
  15027. if ( hasVertexTexture ) {
  15028. shader = {
  15029. vertexShader: [
  15030. "uniform lowp int renderType;",
  15031. "uniform vec3 screenPosition;",
  15032. "uniform vec2 scale;",
  15033. "uniform float rotation;",
  15034. "uniform sampler2D occlusionMap;",
  15035. "attribute vec2 position;",
  15036. "attribute vec2 uv;",
  15037. "varying vec2 vUV;",
  15038. "varying float vVisibility;",
  15039. "void main() {",
  15040. "vUV = uv;",
  15041. "vec2 pos = position;",
  15042. "if( renderType == 2 ) {",
  15043. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  15044. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  15045. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  15046. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  15047. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  15048. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  15049. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  15050. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  15051. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  15052. "vVisibility = visibility.r / 9.0;",
  15053. "vVisibility *= 1.0 - visibility.g / 9.0;",
  15054. "vVisibility *= visibility.b / 9.0;",
  15055. "vVisibility *= 1.0 - visibility.a / 9.0;",
  15056. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15057. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15058. "}",
  15059. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15060. "}"
  15061. ].join( "\n" ),
  15062. fragmentShader: [
  15063. "uniform lowp int renderType;",
  15064. "uniform sampler2D map;",
  15065. "uniform float opacity;",
  15066. "uniform vec3 color;",
  15067. "varying vec2 vUV;",
  15068. "varying float vVisibility;",
  15069. "void main() {",
  15070. // pink square
  15071. "if( renderType == 0 ) {",
  15072. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  15073. // restore
  15074. "} else if( renderType == 1 ) {",
  15075. "gl_FragColor = texture2D( map, vUV );",
  15076. // flare
  15077. "} else {",
  15078. "vec4 texture = texture2D( map, vUV );",
  15079. "texture.a *= opacity * vVisibility;",
  15080. "gl_FragColor = texture;",
  15081. "gl_FragColor.rgb *= color;",
  15082. "}",
  15083. "}"
  15084. ].join( "\n" )
  15085. };
  15086. } else {
  15087. shader = {
  15088. vertexShader: [
  15089. "uniform lowp int renderType;",
  15090. "uniform vec3 screenPosition;",
  15091. "uniform vec2 scale;",
  15092. "uniform float rotation;",
  15093. "attribute vec2 position;",
  15094. "attribute vec2 uv;",
  15095. "varying vec2 vUV;",
  15096. "void main() {",
  15097. "vUV = uv;",
  15098. "vec2 pos = position;",
  15099. "if( renderType == 2 ) {",
  15100. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15101. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15102. "}",
  15103. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15104. "}"
  15105. ].join( "\n" ),
  15106. fragmentShader: [
  15107. "precision mediump float;",
  15108. "uniform lowp int renderType;",
  15109. "uniform sampler2D map;",
  15110. "uniform sampler2D occlusionMap;",
  15111. "uniform float opacity;",
  15112. "uniform vec3 color;",
  15113. "varying vec2 vUV;",
  15114. "void main() {",
  15115. // pink square
  15116. "if( renderType == 0 ) {",
  15117. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  15118. // restore
  15119. "} else if( renderType == 1 ) {",
  15120. "gl_FragColor = texture2D( map, vUV );",
  15121. // flare
  15122. "} else {",
  15123. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  15124. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  15125. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  15126. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  15127. "visibility = ( 1.0 - visibility / 4.0 );",
  15128. "vec4 texture = texture2D( map, vUV );",
  15129. "texture.a *= opacity * visibility;",
  15130. "gl_FragColor = texture;",
  15131. "gl_FragColor.rgb *= color;",
  15132. "}",
  15133. "}"
  15134. ].join( "\n" )
  15135. };
  15136. }
  15137. program = createProgram( shader );
  15138. attributes = {
  15139. vertex: gl.getAttribLocation ( program, "position" ),
  15140. uv: gl.getAttribLocation ( program, "uv" )
  15141. };
  15142. uniforms = {
  15143. renderType: gl.getUniformLocation( program, "renderType" ),
  15144. map: gl.getUniformLocation( program, "map" ),
  15145. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  15146. opacity: gl.getUniformLocation( program, "opacity" ),
  15147. color: gl.getUniformLocation( program, "color" ),
  15148. scale: gl.getUniformLocation( program, "scale" ),
  15149. rotation: gl.getUniformLocation( program, "rotation" ),
  15150. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  15151. };
  15152. };
  15153. /*
  15154. * Render lens flares
  15155. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  15156. * reads these back and calculates occlusion.
  15157. */
  15158. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  15159. if ( flares.length === 0 ) return;
  15160. var tempPosition = new THREE.Vector3();
  15161. var invAspect = viewportHeight / viewportWidth,
  15162. halfViewportWidth = viewportWidth * 0.5,
  15163. halfViewportHeight = viewportHeight * 0.5;
  15164. var size = 16 / viewportHeight,
  15165. scale = new THREE.Vector2( size * invAspect, size );
  15166. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  15167. screenPositionPixels = new THREE.Vector2( 1, 1 );
  15168. if ( program === undefined ) {
  15169. init();
  15170. }
  15171. gl.useProgram( program );
  15172. state.initAttributes();
  15173. state.enableAttribute( attributes.vertex );
  15174. state.enableAttribute( attributes.uv );
  15175. state.disableUnusedAttributes();
  15176. // loop through all lens flares to update their occlusion and positions
  15177. // setup gl and common used attribs/uniforms
  15178. gl.uniform1i( uniforms.occlusionMap, 0 );
  15179. gl.uniform1i( uniforms.map, 1 );
  15180. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15181. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  15182. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15183. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15184. state.disable( gl.CULL_FACE );
  15185. gl.depthMask( false );
  15186. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  15187. size = 16 / viewportHeight;
  15188. scale.set( size * invAspect, size );
  15189. // calc object screen position
  15190. var flare = flares[ i ];
  15191. tempPosition.set( flare.matrixWorld.elements[12], flare.matrixWorld.elements[13], flare.matrixWorld.elements[14] );
  15192. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  15193. tempPosition.applyProjection( camera.projectionMatrix );
  15194. // setup arrays for gl programs
  15195. screenPosition.copy( tempPosition );
  15196. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  15197. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  15198. // screen cull
  15199. if ( hasVertexTexture || (
  15200. screenPositionPixels.x > 0 &&
  15201. screenPositionPixels.x < viewportWidth &&
  15202. screenPositionPixels.y > 0 &&
  15203. screenPositionPixels.y < viewportHeight ) ) {
  15204. // save current RGB to temp texture
  15205. state.activeTexture( gl.TEXTURE0 );
  15206. state.bindTexture( gl.TEXTURE_2D, null );
  15207. state.activeTexture( gl.TEXTURE1 );
  15208. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15209. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15210. // render pink quad
  15211. gl.uniform1i( uniforms.renderType, 0 );
  15212. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15213. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15214. state.disable( gl.BLEND );
  15215. state.enable( gl.DEPTH_TEST );
  15216. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15217. // copy result to occlusionMap
  15218. state.activeTexture( gl.TEXTURE0 );
  15219. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15220. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15221. // restore graphics
  15222. gl.uniform1i( uniforms.renderType, 1 );
  15223. state.disable( gl.DEPTH_TEST );
  15224. state.activeTexture( gl.TEXTURE1 );
  15225. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15226. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15227. // update object positions
  15228. flare.positionScreen.copy( screenPosition );
  15229. if ( flare.customUpdateCallback ) {
  15230. flare.customUpdateCallback( flare );
  15231. } else {
  15232. flare.updateLensFlares();
  15233. }
  15234. // render flares
  15235. gl.uniform1i( uniforms.renderType, 2 );
  15236. state.enable( gl.BLEND );
  15237. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  15238. var sprite = flare.lensFlares[ j ];
  15239. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  15240. screenPosition.x = sprite.x;
  15241. screenPosition.y = sprite.y;
  15242. screenPosition.z = sprite.z;
  15243. size = sprite.size * sprite.scale / viewportHeight;
  15244. scale.x = size * invAspect;
  15245. scale.y = size;
  15246. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15247. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15248. gl.uniform1f( uniforms.rotation, sprite.rotation );
  15249. gl.uniform1f( uniforms.opacity, sprite.opacity );
  15250. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  15251. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  15252. renderer.setTexture( sprite.texture, 1 );
  15253. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15254. }
  15255. }
  15256. }
  15257. }
  15258. // restore gl
  15259. state.enable( gl.CULL_FACE );
  15260. state.enable( gl.DEPTH_TEST );
  15261. gl.depthMask( true );
  15262. renderer.resetGLState();
  15263. };
  15264. function createProgram ( shader ) {
  15265. var program = gl.createProgram();
  15266. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15267. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15268. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  15269. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  15270. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  15271. gl.compileShader( fragmentShader );
  15272. gl.compileShader( vertexShader );
  15273. gl.attachShader( program, fragmentShader );
  15274. gl.attachShader( program, vertexShader );
  15275. gl.linkProgram( program );
  15276. return program;
  15277. }
  15278. };
  15279. // File:src/renderers/webgl/plugins/SpritePlugin.js
  15280. /**
  15281. * @author mikael emtinger / http://gomo.se/
  15282. * @author alteredq / http://alteredqualia.com/
  15283. */
  15284. THREE.SpritePlugin = function ( renderer, sprites ) {
  15285. var gl = renderer.context;
  15286. var state = renderer.state;
  15287. var vertexBuffer, elementBuffer;
  15288. var program, attributes, uniforms;
  15289. var texture;
  15290. // decompose matrixWorld
  15291. var spritePosition = new THREE.Vector3();
  15292. var spriteRotation = new THREE.Quaternion();
  15293. var spriteScale = new THREE.Vector3();
  15294. var init = function () {
  15295. var vertices = new Float32Array( [
  15296. - 0.5, - 0.5, 0, 0,
  15297. 0.5, - 0.5, 1, 0,
  15298. 0.5, 0.5, 1, 1,
  15299. - 0.5, 0.5, 0, 1
  15300. ] );
  15301. var faces = new Uint16Array( [
  15302. 0, 1, 2,
  15303. 0, 2, 3
  15304. ] );
  15305. vertexBuffer = gl.createBuffer();
  15306. elementBuffer = gl.createBuffer();
  15307. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15308. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15309. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15310. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15311. program = createProgram();
  15312. attributes = {
  15313. position: gl.getAttribLocation ( program, 'position' ),
  15314. uv: gl.getAttribLocation ( program, 'uv' )
  15315. };
  15316. uniforms = {
  15317. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  15318. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  15319. rotation: gl.getUniformLocation( program, 'rotation' ),
  15320. scale: gl.getUniformLocation( program, 'scale' ),
  15321. color: gl.getUniformLocation( program, 'color' ),
  15322. map: gl.getUniformLocation( program, 'map' ),
  15323. opacity: gl.getUniformLocation( program, 'opacity' ),
  15324. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  15325. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  15326. fogType: gl.getUniformLocation( program, 'fogType' ),
  15327. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  15328. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  15329. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  15330. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  15331. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  15332. };
  15333. var canvas = document.createElement( 'canvas' );
  15334. canvas.width = 8;
  15335. canvas.height = 8;
  15336. var context = canvas.getContext( '2d' );
  15337. context.fillStyle = 'white';
  15338. context.fillRect( 0, 0, 8, 8 );
  15339. texture = new THREE.Texture( canvas );
  15340. texture.needsUpdate = true;
  15341. };
  15342. this.render = function ( scene, camera ) {
  15343. if ( sprites.length === 0 ) return;
  15344. // setup gl
  15345. if ( program === undefined ) {
  15346. init();
  15347. }
  15348. gl.useProgram( program );
  15349. state.initAttributes();
  15350. state.enableAttribute( attributes.position );
  15351. state.enableAttribute( attributes.uv );
  15352. state.disableUnusedAttributes();
  15353. state.disable( gl.CULL_FACE );
  15354. state.enable( gl.BLEND );
  15355. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15356. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  15357. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15358. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15359. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15360. state.activeTexture( gl.TEXTURE0 );
  15361. gl.uniform1i( uniforms.map, 0 );
  15362. var oldFogType = 0;
  15363. var sceneFogType = 0;
  15364. var fog = scene.fog;
  15365. if ( fog ) {
  15366. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  15367. if ( fog instanceof THREE.Fog ) {
  15368. gl.uniform1f( uniforms.fogNear, fog.near );
  15369. gl.uniform1f( uniforms.fogFar, fog.far );
  15370. gl.uniform1i( uniforms.fogType, 1 );
  15371. oldFogType = 1;
  15372. sceneFogType = 1;
  15373. } else if ( fog instanceof THREE.FogExp2 ) {
  15374. gl.uniform1f( uniforms.fogDensity, fog.density );
  15375. gl.uniform1i( uniforms.fogType, 2 );
  15376. oldFogType = 2;
  15377. sceneFogType = 2;
  15378. }
  15379. } else {
  15380. gl.uniform1i( uniforms.fogType, 0 );
  15381. oldFogType = 0;
  15382. sceneFogType = 0;
  15383. }
  15384. // update positions and sort
  15385. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15386. var sprite = sprites[ i ];
  15387. sprite._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  15388. sprite.z = - sprite._modelViewMatrix.elements[ 14 ];
  15389. }
  15390. sprites.sort( painterSortStable );
  15391. // render all sprites
  15392. var scale = [];
  15393. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15394. var sprite = sprites[ i ];
  15395. var material = sprite.material;
  15396. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  15397. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements );
  15398. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  15399. scale[ 0 ] = spriteScale.x;
  15400. scale[ 1 ] = spriteScale.y;
  15401. var fogType = 0;
  15402. if ( scene.fog && material.fog ) {
  15403. fogType = sceneFogType;
  15404. }
  15405. if ( oldFogType !== fogType ) {
  15406. gl.uniform1i( uniforms.fogType, fogType );
  15407. oldFogType = fogType;
  15408. }
  15409. if ( material.map !== null ) {
  15410. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  15411. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  15412. } else {
  15413. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  15414. gl.uniform2f( uniforms.uvScale, 1, 1 );
  15415. }
  15416. gl.uniform1f( uniforms.opacity, material.opacity );
  15417. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  15418. gl.uniform1f( uniforms.rotation, material.rotation );
  15419. gl.uniform2fv( uniforms.scale, scale );
  15420. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  15421. state.setDepthTest( material.depthTest );
  15422. state.setDepthWrite( material.depthWrite );
  15423. if ( material.map && material.map.image && material.map.image.width ) {
  15424. renderer.setTexture( material.map, 0 );
  15425. } else {
  15426. renderer.setTexture( texture, 0 );
  15427. }
  15428. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15429. }
  15430. // restore gl
  15431. state.enable( gl.CULL_FACE );
  15432. renderer.resetGLState();
  15433. };
  15434. function createProgram () {
  15435. var program = gl.createProgram();
  15436. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15437. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15438. gl.shaderSource( vertexShader, [
  15439. 'precision ' + renderer.getPrecision() + ' float;',
  15440. 'uniform mat4 modelViewMatrix;',
  15441. 'uniform mat4 projectionMatrix;',
  15442. 'uniform float rotation;',
  15443. 'uniform vec2 scale;',
  15444. 'uniform vec2 uvOffset;',
  15445. 'uniform vec2 uvScale;',
  15446. 'attribute vec2 position;',
  15447. 'attribute vec2 uv;',
  15448. 'varying vec2 vUV;',
  15449. 'void main() {',
  15450. 'vUV = uvOffset + uv * uvScale;',
  15451. 'vec2 alignedPosition = position * scale;',
  15452. 'vec2 rotatedPosition;',
  15453. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  15454. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  15455. 'vec4 finalPosition;',
  15456. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  15457. 'finalPosition.xy += rotatedPosition;',
  15458. 'finalPosition = projectionMatrix * finalPosition;',
  15459. 'gl_Position = finalPosition;',
  15460. '}'
  15461. ].join( '\n' ) );
  15462. gl.shaderSource( fragmentShader, [
  15463. 'precision ' + renderer.getPrecision() + ' float;',
  15464. 'uniform vec3 color;',
  15465. 'uniform sampler2D map;',
  15466. 'uniform float opacity;',
  15467. 'uniform int fogType;',
  15468. 'uniform vec3 fogColor;',
  15469. 'uniform float fogDensity;',
  15470. 'uniform float fogNear;',
  15471. 'uniform float fogFar;',
  15472. 'uniform float alphaTest;',
  15473. 'varying vec2 vUV;',
  15474. 'void main() {',
  15475. 'vec4 texture = texture2D( map, vUV );',
  15476. 'if ( texture.a < alphaTest ) discard;',
  15477. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  15478. 'if ( fogType > 0 ) {',
  15479. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  15480. 'float fogFactor = 0.0;',
  15481. 'if ( fogType == 1 ) {',
  15482. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  15483. '} else {',
  15484. 'const float LOG2 = 1.442695;',
  15485. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  15486. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  15487. '}',
  15488. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  15489. '}',
  15490. '}'
  15491. ].join( '\n' ) );
  15492. gl.compileShader( vertexShader );
  15493. gl.compileShader( fragmentShader );
  15494. gl.attachShader( program, vertexShader );
  15495. gl.attachShader( program, fragmentShader );
  15496. gl.linkProgram( program );
  15497. return program;
  15498. }
  15499. function painterSortStable ( a, b ) {
  15500. if ( a.z !== b.z ) {
  15501. return b.z - a.z;
  15502. } else {
  15503. return b.id - a.id;
  15504. }
  15505. }
  15506. };
  15507. // File:src/extras/GeometryUtils.js
  15508. /**
  15509. * @author mrdoob / http://mrdoob.com/
  15510. */
  15511. THREE.GeometryUtils = {
  15512. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  15513. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  15514. var matrix;
  15515. if ( geometry2 instanceof THREE.Mesh ) {
  15516. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  15517. matrix = geometry2.matrix;
  15518. geometry2 = geometry2.geometry;
  15519. }
  15520. geometry1.merge( geometry2, matrix, materialIndexOffset );
  15521. },
  15522. center: function ( geometry ) {
  15523. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  15524. return geometry.center();
  15525. }
  15526. };
  15527. // File:src/extras/ImageUtils.js
  15528. /**
  15529. * @author alteredq / http://alteredqualia.com/
  15530. * @author mrdoob / http://mrdoob.com/
  15531. * @author Daosheng Mu / https://github.com/DaoshengMu/
  15532. */
  15533. THREE.ImageUtils = {
  15534. crossOrigin: undefined,
  15535. loadTexture: function ( url, mapping, onLoad, onError ) {
  15536. var loader = new THREE.ImageLoader();
  15537. loader.crossOrigin = this.crossOrigin;
  15538. var texture = new THREE.Texture( undefined, mapping );
  15539. loader.load( url, function ( image ) {
  15540. texture.image = image;
  15541. texture.needsUpdate = true;
  15542. if ( onLoad ) onLoad( texture );
  15543. }, undefined, function ( event ) {
  15544. if ( onError ) onError( event );
  15545. } );
  15546. texture.sourceFile = url;
  15547. return texture;
  15548. },
  15549. loadTextureCube: function ( array, mapping, onLoad, onError ) {
  15550. var images = [];
  15551. var loader = new THREE.ImageLoader();
  15552. loader.crossOrigin = this.crossOrigin;
  15553. var texture = new THREE.CubeTexture( images, mapping );
  15554. var loaded = 0;
  15555. var loadTexture = function ( i ) {
  15556. loader.load( array[ i ], function ( image ) {
  15557. texture.images[ i ] = image;
  15558. loaded += 1;
  15559. if ( loaded === 6 ) {
  15560. texture.needsUpdate = true;
  15561. if ( onLoad ) onLoad( texture );
  15562. }
  15563. }, undefined, onError );
  15564. };
  15565. for ( var i = 0, il = array.length; i < il; ++ i ) {
  15566. loadTexture( i );
  15567. }
  15568. return texture;
  15569. },
  15570. loadCompressedTexture: function () {
  15571. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  15572. },
  15573. loadCompressedTextureCube: function () {
  15574. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  15575. },
  15576. getNormalMap: function ( image, depth ) {
  15577. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  15578. var cross = function ( a, b ) {
  15579. return [ a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ], a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ], a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ] ];
  15580. };
  15581. var subtract = function ( a, b ) {
  15582. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  15583. };
  15584. var normalize = function ( a ) {
  15585. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  15586. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  15587. };
  15588. depth = depth | 1;
  15589. var width = image.width;
  15590. var height = image.height;
  15591. var canvas = document.createElement( 'canvas' );
  15592. canvas.width = width;
  15593. canvas.height = height;
  15594. var context = canvas.getContext( '2d' );
  15595. context.drawImage( image, 0, 0 );
  15596. var data = context.getImageData( 0, 0, width, height ).data;
  15597. var imageData = context.createImageData( width, height );
  15598. var output = imageData.data;
  15599. for ( var x = 0; x < width; x ++ ) {
  15600. for ( var y = 0; y < height; y ++ ) {
  15601. var ly = y - 1 < 0 ? 0 : y - 1;
  15602. var uy = y + 1 > height - 1 ? height - 1 : y + 1;
  15603. var lx = x - 1 < 0 ? 0 : x - 1;
  15604. var ux = x + 1 > width - 1 ? width - 1 : x + 1;
  15605. var points = [];
  15606. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  15607. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  15608. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  15609. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  15610. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  15611. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  15612. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  15613. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  15614. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  15615. var normals = [];
  15616. var num_points = points.length;
  15617. for ( var i = 0; i < num_points; i ++ ) {
  15618. var v1 = points[ i ];
  15619. var v2 = points[ ( i + 1 ) % num_points ];
  15620. v1 = subtract( v1, origin );
  15621. v2 = subtract( v2, origin );
  15622. normals.push( normalize( cross( v1, v2 ) ) );
  15623. }
  15624. var normal = [ 0, 0, 0 ];
  15625. for ( var i = 0; i < normals.length; i ++ ) {
  15626. normal[ 0 ] += normals[ i ][ 0 ];
  15627. normal[ 1 ] += normals[ i ][ 1 ];
  15628. normal[ 2 ] += normals[ i ][ 2 ];
  15629. }
  15630. normal[ 0 ] /= normals.length;
  15631. normal[ 1 ] /= normals.length;
  15632. normal[ 2 ] /= normals.length;
  15633. var idx = ( y * width + x ) * 4;
  15634. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15635. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15636. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  15637. output[ idx + 3 ] = 255;
  15638. }
  15639. }
  15640. context.putImageData( imageData, 0, 0 );
  15641. return canvas;
  15642. },
  15643. generateDataTexture: function ( width, height, color ) {
  15644. var size = width * height;
  15645. var data = new Uint8Array( 3 * size );
  15646. var r = Math.floor( color.r * 255 );
  15647. var g = Math.floor( color.g * 255 );
  15648. var b = Math.floor( color.b * 255 );
  15649. for ( var i = 0; i < size; i ++ ) {
  15650. data[ i * 3 ] = r;
  15651. data[ i * 3 + 1 ] = g;
  15652. data[ i * 3 + 2 ] = b;
  15653. }
  15654. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  15655. texture.needsUpdate = true;
  15656. return texture;
  15657. }
  15658. };
  15659. // File:src/extras/SceneUtils.js
  15660. /**
  15661. * @author alteredq / http://alteredqualia.com/
  15662. */
  15663. THREE.SceneUtils = {
  15664. createMultiMaterialObject: function ( geometry, materials ) {
  15665. var group = new THREE.Object3D();
  15666. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  15667. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  15668. }
  15669. return group;
  15670. },
  15671. detach: function ( child, parent, scene ) {
  15672. child.applyMatrix( parent.matrixWorld );
  15673. parent.remove( child );
  15674. scene.add( child );
  15675. },
  15676. attach: function ( child, scene, parent ) {
  15677. var matrixWorldInverse = new THREE.Matrix4();
  15678. matrixWorldInverse.getInverse( parent.matrixWorld );
  15679. child.applyMatrix( matrixWorldInverse );
  15680. scene.remove( child );
  15681. parent.add( child );
  15682. }
  15683. };
  15684. // File:src/extras/FontUtils.js
  15685. /**
  15686. * @author zz85 / http://www.lab4games.net/zz85/blog
  15687. * @author alteredq / http://alteredqualia.com/
  15688. *
  15689. * For Text operations in three.js (See TextGeometry)
  15690. *
  15691. * It uses techniques used in:
  15692. *
  15693. * Triangulation ported from AS3
  15694. * Simple Polygon Triangulation
  15695. * http://actionsnippet.com/?p=1462
  15696. *
  15697. * A Method to triangulate shapes with holes
  15698. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  15699. *
  15700. */
  15701. THREE.FontUtils = {
  15702. faces: {},
  15703. // Just for now. face[weight][style]
  15704. face: 'helvetiker',
  15705. weight: 'normal',
  15706. style: 'normal',
  15707. size: 150,
  15708. divisions: 10,
  15709. getFace: function () {
  15710. try {
  15711. return this.faces[ this.face.toLowerCase() ][ this.weight ][ this.style ];
  15712. } catch (e) {
  15713. throw "The font " + this.face + " with " + this.weight + " weight and " + this.style + " style is missing."
  15714. }
  15715. },
  15716. loadFace: function ( data ) {
  15717. var family = data.familyName.toLowerCase();
  15718. var ThreeFont = this;
  15719. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  15720. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  15721. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15722. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15723. return data;
  15724. },
  15725. drawText: function ( text ) {
  15726. // RenderText
  15727. var i,
  15728. face = this.getFace(),
  15729. scale = this.size / face.resolution,
  15730. offset = 0,
  15731. chars = String( text ).split( '' ),
  15732. length = chars.length;
  15733. var fontPaths = [];
  15734. for ( i = 0; i < length; i ++ ) {
  15735. var path = new THREE.Path();
  15736. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  15737. offset += ret.offset;
  15738. fontPaths.push( ret.path );
  15739. }
  15740. // get the width
  15741. var width = offset / 2;
  15742. //
  15743. // for ( p = 0; p < allPts.length; p++ ) {
  15744. //
  15745. // allPts[ p ].x -= width;
  15746. //
  15747. // }
  15748. //var extract = this.extractPoints( allPts, characterPts );
  15749. //extract.contour = allPts;
  15750. //extract.paths = fontPaths;
  15751. //extract.offset = width;
  15752. return { paths: fontPaths, offset: width };
  15753. },
  15754. extractGlyphPoints: function ( c, face, scale, offset, path ) {
  15755. var pts = [];
  15756. var i, i2, divisions,
  15757. outline, action, length,
  15758. scaleX, scaleY,
  15759. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  15760. laste,
  15761. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  15762. if ( ! glyph ) return;
  15763. if ( glyph.o ) {
  15764. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  15765. length = outline.length;
  15766. scaleX = scale;
  15767. scaleY = scale;
  15768. for ( i = 0; i < length; ) {
  15769. action = outline[ i ++ ];
  15770. //console.log( action );
  15771. switch ( action ) {
  15772. case 'm':
  15773. // Move To
  15774. x = outline[ i ++ ] * scaleX + offset;
  15775. y = outline[ i ++ ] * scaleY;
  15776. path.moveTo( x, y );
  15777. break;
  15778. case 'l':
  15779. // Line To
  15780. x = outline[ i ++ ] * scaleX + offset;
  15781. y = outline[ i ++ ] * scaleY;
  15782. path.lineTo( x, y );
  15783. break;
  15784. case 'q':
  15785. // QuadraticCurveTo
  15786. cpx = outline[ i ++ ] * scaleX + offset;
  15787. cpy = outline[ i ++ ] * scaleY;
  15788. cpx1 = outline[ i ++ ] * scaleX + offset;
  15789. cpy1 = outline[ i ++ ] * scaleY;
  15790. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  15791. laste = pts[ pts.length - 1 ];
  15792. if ( laste ) {
  15793. cpx0 = laste.x;
  15794. cpy0 = laste.y;
  15795. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15796. var t = i2 / divisions;
  15797. THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  15798. THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  15799. }
  15800. }
  15801. break;
  15802. case 'b':
  15803. // Cubic Bezier Curve
  15804. cpx = outline[ i ++ ] * scaleX + offset;
  15805. cpy = outline[ i ++ ] * scaleY;
  15806. cpx1 = outline[ i ++ ] * scaleX + offset;
  15807. cpy1 = outline[ i ++ ] * scaleY;
  15808. cpx2 = outline[ i ++ ] * scaleX + offset;
  15809. cpy2 = outline[ i ++ ] * scaleY;
  15810. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  15811. laste = pts[ pts.length - 1 ];
  15812. if ( laste ) {
  15813. cpx0 = laste.x;
  15814. cpy0 = laste.y;
  15815. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15816. var t = i2 / divisions;
  15817. THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  15818. THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  15819. }
  15820. }
  15821. break;
  15822. }
  15823. }
  15824. }
  15825. return { offset: glyph.ha * scale, path:path };
  15826. }
  15827. };
  15828. THREE.FontUtils.generateShapes = function ( text, parameters ) {
  15829. // Parameters
  15830. parameters = parameters || {};
  15831. var size = parameters.size !== undefined ? parameters.size : 100;
  15832. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments : 4;
  15833. var font = parameters.font !== undefined ? parameters.font : 'helvetiker';
  15834. var weight = parameters.weight !== undefined ? parameters.weight : 'normal';
  15835. var style = parameters.style !== undefined ? parameters.style : 'normal';
  15836. THREE.FontUtils.size = size;
  15837. THREE.FontUtils.divisions = curveSegments;
  15838. THREE.FontUtils.face = font;
  15839. THREE.FontUtils.weight = weight;
  15840. THREE.FontUtils.style = style;
  15841. // Get a Font data json object
  15842. var data = THREE.FontUtils.drawText( text );
  15843. var paths = data.paths;
  15844. var shapes = [];
  15845. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  15846. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  15847. }
  15848. return shapes;
  15849. };
  15850. /**
  15851. * This code is a quick port of code written in C++ which was submitted to
  15852. * flipcode.com by John W. Ratcliff // July 22, 2000
  15853. * See original code and more information here:
  15854. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  15855. *
  15856. * ported to actionscript by Zevan Rosser
  15857. * www.actionsnippet.com
  15858. *
  15859. * ported to javascript by Joshua Koo
  15860. * http://www.lab4games.net/zz85/blog
  15861. *
  15862. */
  15863. ( function ( namespace ) {
  15864. var EPSILON = 0.0000000001;
  15865. // takes in an contour array and returns
  15866. var process = function ( contour, indices ) {
  15867. var n = contour.length;
  15868. if ( n < 3 ) return null;
  15869. var result = [],
  15870. verts = [],
  15871. vertIndices = [];
  15872. /* we want a counter-clockwise polygon in verts */
  15873. var u, v, w;
  15874. if ( area( contour ) > 0.0 ) {
  15875. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  15876. } else {
  15877. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  15878. }
  15879. var nv = n;
  15880. /* remove nv - 2 vertices, creating 1 triangle every time */
  15881. var count = 2 * nv; /* error detection */
  15882. for ( v = nv - 1; nv > 2; ) {
  15883. /* if we loop, it is probably a non-simple polygon */
  15884. if ( ( count -- ) <= 0 ) {
  15885. //** Triangulate: ERROR - probable bad polygon!
  15886. //throw ( "Warning, unable to triangulate polygon!" );
  15887. //return null;
  15888. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  15889. console.warn( 'THREE.FontUtils: Warning, unable to triangulate polygon! in Triangulate.process()' );
  15890. if ( indices ) return vertIndices;
  15891. return result;
  15892. }
  15893. /* three consecutive vertices in current polygon, <u,v,w> */
  15894. u = v; if ( nv <= u ) u = 0; /* previous */
  15895. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  15896. w = v + 1; if ( nv <= w ) w = 0; /* next */
  15897. if ( snip( contour, u, v, w, nv, verts ) ) {
  15898. var a, b, c, s, t;
  15899. /* true names of the vertices */
  15900. a = verts[ u ];
  15901. b = verts[ v ];
  15902. c = verts[ w ];
  15903. /* output Triangle */
  15904. result.push( [ contour[ a ],
  15905. contour[ b ],
  15906. contour[ c ] ] );
  15907. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  15908. /* remove v from the remaining polygon */
  15909. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  15910. verts[ s ] = verts[ t ];
  15911. }
  15912. nv --;
  15913. /* reset error detection counter */
  15914. count = 2 * nv;
  15915. }
  15916. }
  15917. if ( indices ) return vertIndices;
  15918. return result;
  15919. };
  15920. // calculate area of the contour polygon
  15921. var area = function ( contour ) {
  15922. var n = contour.length;
  15923. var a = 0.0;
  15924. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  15925. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  15926. }
  15927. return a * 0.5;
  15928. };
  15929. var snip = function ( contour, u, v, w, n, verts ) {
  15930. var p;
  15931. var ax, ay, bx, by;
  15932. var cx, cy, px, py;
  15933. ax = contour[ verts[ u ] ].x;
  15934. ay = contour[ verts[ u ] ].y;
  15935. bx = contour[ verts[ v ] ].x;
  15936. by = contour[ verts[ v ] ].y;
  15937. cx = contour[ verts[ w ] ].x;
  15938. cy = contour[ verts[ w ] ].y;
  15939. if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  15940. var aX, aY, bX, bY, cX, cY;
  15941. var apx, apy, bpx, bpy, cpx, cpy;
  15942. var cCROSSap, bCROSScp, aCROSSbp;
  15943. aX = cx - bx; aY = cy - by;
  15944. bX = ax - cx; bY = ay - cy;
  15945. cX = bx - ax; cY = by - ay;
  15946. for ( p = 0; p < n; p ++ ) {
  15947. px = contour[ verts[ p ] ].x;
  15948. py = contour[ verts[ p ] ].y;
  15949. if ( ( ( px === ax ) && ( py === ay ) ) ||
  15950. ( ( px === bx ) && ( py === by ) ) ||
  15951. ( ( px === cx ) && ( py === cy ) ) ) continue;
  15952. apx = px - ax; apy = py - ay;
  15953. bpx = px - bx; bpy = py - by;
  15954. cpx = px - cx; cpy = py - cy;
  15955. // see if p is inside triangle abc
  15956. aCROSSbp = aX * bpy - aY * bpx;
  15957. cCROSSap = cX * apy - cY * apx;
  15958. bCROSScp = bX * cpy - bY * cpx;
  15959. if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
  15960. }
  15961. return true;
  15962. };
  15963. namespace.Triangulate = process;
  15964. namespace.Triangulate.area = area;
  15965. return namespace;
  15966. } )( THREE.FontUtils );
  15967. // To use the typeface.js face files, hook up the API
  15968. THREE.typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  15969. if ( typeof self !== 'undefined' ) self._typeface_js = THREE.typeface_js;
  15970. // File:src/extras/audio/Audio.js
  15971. /**
  15972. * @author mrdoob / http://mrdoob.com/
  15973. */
  15974. THREE.Audio = function ( listener ) {
  15975. THREE.Object3D.call( this );
  15976. this.type = 'Audio';
  15977. this.context = listener.context;
  15978. this.source = this.context.createBufferSource();
  15979. this.source.onended = this.onEnded.bind(this);
  15980. this.gain = this.context.createGain();
  15981. this.gain.connect( this.context.destination );
  15982. this.panner = this.context.createPanner();
  15983. this.panner.connect( this.gain );
  15984. this.autoplay = false;
  15985. this.startTime = 0;
  15986. this.isPlaying = false;
  15987. };
  15988. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  15989. THREE.Audio.prototype.constructor = THREE.Audio;
  15990. THREE.Audio.prototype.load = function ( file ) {
  15991. var scope = this;
  15992. var request = new XMLHttpRequest();
  15993. request.open( 'GET', file, true );
  15994. request.responseType = 'arraybuffer';
  15995. request.onload = function ( e ) {
  15996. scope.context.decodeAudioData( this.response, function ( buffer ) {
  15997. scope.source.buffer = buffer;
  15998. if( scope.autoplay ) scope.play();
  15999. } );
  16000. };
  16001. request.send();
  16002. return this;
  16003. };
  16004. THREE.Audio.prototype.play = function () {
  16005. if ( this.isPlaying === true ) {
  16006. console.warn( 'THREE.Audio: Audio is already playing.' );
  16007. return;
  16008. }
  16009. var source = this.context.createBufferSource();
  16010. source.buffer = this.source.buffer;
  16011. source.loop = this.source.loop;
  16012. source.onended = this.source.onended;
  16013. source.connect( this.panner );
  16014. source.start( 0, this.startTime );
  16015. this.isPlaying = true;
  16016. this.source = source;
  16017. };
  16018. THREE.Audio.prototype.pause = function () {
  16019. this.source.stop();
  16020. this.startTime = this.context.currentTime;
  16021. };
  16022. THREE.Audio.prototype.stop = function () {
  16023. this.source.stop();
  16024. this.startTime = 0;
  16025. };
  16026. THREE.Audio.prototype.onEnded = function() {
  16027. this.isPlaying = false;
  16028. };
  16029. THREE.Audio.prototype.setLoop = function ( value ) {
  16030. this.source.loop = value;
  16031. };
  16032. THREE.Audio.prototype.setRefDistance = function ( value ) {
  16033. this.panner.refDistance = value;
  16034. };
  16035. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  16036. this.panner.rolloffFactor = value;
  16037. };
  16038. THREE.Audio.prototype.setVolume = function ( value ) {
  16039. this.gain.gain.value = value;
  16040. };
  16041. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  16042. var position = new THREE.Vector3();
  16043. return function ( force ) {
  16044. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16045. position.setFromMatrixPosition( this.matrixWorld );
  16046. this.panner.setPosition( position.x, position.y, position.z );
  16047. };
  16048. } )();
  16049. // File:src/extras/audio/AudioListener.js
  16050. /**
  16051. * @author mrdoob / http://mrdoob.com/
  16052. */
  16053. THREE.AudioListener = function () {
  16054. THREE.Object3D.call( this );
  16055. this.type = 'AudioListener';
  16056. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  16057. };
  16058. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  16059. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  16060. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  16061. var position = new THREE.Vector3();
  16062. var quaternion = new THREE.Quaternion();
  16063. var scale = new THREE.Vector3();
  16064. var orientation = new THREE.Vector3();
  16065. return function ( force ) {
  16066. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16067. var listener = this.context.listener;
  16068. var up = this.up;
  16069. this.matrixWorld.decompose( position, quaternion, scale );
  16070. orientation.set( 0, 0, -1 ).applyQuaternion( quaternion );
  16071. listener.setPosition( position.x, position.y, position.z );
  16072. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  16073. };
  16074. } )();
  16075. // File:src/extras/core/Curve.js
  16076. /**
  16077. * @author zz85 / http://www.lab4games.net/zz85/blog
  16078. * Extensible curve object
  16079. *
  16080. * Some common of Curve methods
  16081. * .getPoint(t), getTangent(t)
  16082. * .getPointAt(u), getTagentAt(u)
  16083. * .getPoints(), .getSpacedPoints()
  16084. * .getLength()
  16085. * .updateArcLengths()
  16086. *
  16087. * This following classes subclasses THREE.Curve:
  16088. *
  16089. * -- 2d classes --
  16090. * THREE.LineCurve
  16091. * THREE.QuadraticBezierCurve
  16092. * THREE.CubicBezierCurve
  16093. * THREE.SplineCurve
  16094. * THREE.ArcCurve
  16095. * THREE.EllipseCurve
  16096. *
  16097. * -- 3d classes --
  16098. * THREE.LineCurve3
  16099. * THREE.QuadraticBezierCurve3
  16100. * THREE.CubicBezierCurve3
  16101. * THREE.SplineCurve3
  16102. * THREE.ClosedSplineCurve3
  16103. *
  16104. * A series of curves can be represented as a THREE.CurvePath
  16105. *
  16106. **/
  16107. /**************************************************************
  16108. * Abstract Curve base class
  16109. **************************************************************/
  16110. THREE.Curve = function () {
  16111. };
  16112. // Virtual base class method to overwrite and implement in subclasses
  16113. // - t [0 .. 1]
  16114. THREE.Curve.prototype.getPoint = function ( t ) {
  16115. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  16116. return null;
  16117. };
  16118. // Get point at relative position in curve according to arc length
  16119. // - u [0 .. 1]
  16120. THREE.Curve.prototype.getPointAt = function ( u ) {
  16121. var t = this.getUtoTmapping( u );
  16122. return this.getPoint( t );
  16123. };
  16124. // Get sequence of points using getPoint( t )
  16125. THREE.Curve.prototype.getPoints = function ( divisions ) {
  16126. if ( ! divisions ) divisions = 5;
  16127. var d, pts = [];
  16128. for ( d = 0; d <= divisions; d ++ ) {
  16129. pts.push( this.getPoint( d / divisions ) );
  16130. }
  16131. return pts;
  16132. };
  16133. // Get sequence of points using getPointAt( u )
  16134. THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
  16135. if ( ! divisions ) divisions = 5;
  16136. var d, pts = [];
  16137. for ( d = 0; d <= divisions; d ++ ) {
  16138. pts.push( this.getPointAt( d / divisions ) );
  16139. }
  16140. return pts;
  16141. };
  16142. // Get total curve arc length
  16143. THREE.Curve.prototype.getLength = function () {
  16144. var lengths = this.getLengths();
  16145. return lengths[ lengths.length - 1 ];
  16146. };
  16147. // Get list of cumulative segment lengths
  16148. THREE.Curve.prototype.getLengths = function ( divisions ) {
  16149. if ( ! divisions ) divisions = (this.__arcLengthDivisions) ? (this.__arcLengthDivisions) : 200;
  16150. if ( this.cacheArcLengths
  16151. && ( this.cacheArcLengths.length === divisions + 1 )
  16152. && ! this.needsUpdate) {
  16153. //console.log( "cached", this.cacheArcLengths );
  16154. return this.cacheArcLengths;
  16155. }
  16156. this.needsUpdate = false;
  16157. var cache = [];
  16158. var current, last = this.getPoint( 0 );
  16159. var p, sum = 0;
  16160. cache.push( 0 );
  16161. for ( p = 1; p <= divisions; p ++ ) {
  16162. current = this.getPoint ( p / divisions );
  16163. sum += current.distanceTo( last );
  16164. cache.push( sum );
  16165. last = current;
  16166. }
  16167. this.cacheArcLengths = cache;
  16168. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  16169. };
  16170. THREE.Curve.prototype.updateArcLengths = function() {
  16171. this.needsUpdate = true;
  16172. this.getLengths();
  16173. };
  16174. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  16175. THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
  16176. var arcLengths = this.getLengths();
  16177. var i = 0, il = arcLengths.length;
  16178. var targetArcLength; // The targeted u distance value to get
  16179. if ( distance ) {
  16180. targetArcLength = distance;
  16181. } else {
  16182. targetArcLength = u * arcLengths[ il - 1 ];
  16183. }
  16184. //var time = Date.now();
  16185. // binary search for the index with largest value smaller than target u distance
  16186. var low = 0, high = il - 1, comparison;
  16187. while ( low <= high ) {
  16188. 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
  16189. comparison = arcLengths[ i ] - targetArcLength;
  16190. if ( comparison < 0 ) {
  16191. low = i + 1;
  16192. } else if ( comparison > 0 ) {
  16193. high = i - 1;
  16194. } else {
  16195. high = i;
  16196. break;
  16197. // DONE
  16198. }
  16199. }
  16200. i = high;
  16201. //console.log('b' , i, low, high, Date.now()- time);
  16202. if ( arcLengths[ i ] === targetArcLength ) {
  16203. var t = i / ( il - 1 );
  16204. return t;
  16205. }
  16206. // we could get finer grain at lengths, or use simple interpolation between two points
  16207. var lengthBefore = arcLengths[ i ];
  16208. var lengthAfter = arcLengths[ i + 1 ];
  16209. var segmentLength = lengthAfter - lengthBefore;
  16210. // determine where we are between the 'before' and 'after' points
  16211. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  16212. // add that fractional amount to t
  16213. var t = ( i + segmentFraction ) / ( il - 1 );
  16214. return t;
  16215. };
  16216. // Returns a unit vector tangent at t
  16217. // In case any sub curve does not implement its tangent derivation,
  16218. // 2 points a small delta apart will be used to find its gradient
  16219. // which seems to give a reasonable approximation
  16220. THREE.Curve.prototype.getTangent = function( t ) {
  16221. var delta = 0.0001;
  16222. var t1 = t - delta;
  16223. var t2 = t + delta;
  16224. // Capping in case of danger
  16225. if ( t1 < 0 ) t1 = 0;
  16226. if ( t2 > 1 ) t2 = 1;
  16227. var pt1 = this.getPoint( t1 );
  16228. var pt2 = this.getPoint( t2 );
  16229. var vec = pt2.clone().sub(pt1);
  16230. return vec.normalize();
  16231. };
  16232. THREE.Curve.prototype.getTangentAt = function ( u ) {
  16233. var t = this.getUtoTmapping( u );
  16234. return this.getTangent( t );
  16235. };
  16236. /**************************************************************
  16237. * Utils
  16238. **************************************************************/
  16239. THREE.Curve.Utils = {
  16240. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  16241. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  16242. },
  16243. // Puay Bing, thanks for helping with this derivative!
  16244. tangentCubicBezier: function (t, p0, p1, p2, p3 ) {
  16245. return - 3 * p0 * (1 - t) * (1 - t) +
  16246. 3 * p1 * (1 - t) * (1 - t) - 6 * t * p1 * (1 - t) +
  16247. 6 * t * p2 * (1 - t) - 3 * t * t * p2 +
  16248. 3 * t * t * p3;
  16249. },
  16250. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  16251. // To check if my formulas are correct
  16252. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  16253. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  16254. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  16255. var h11 = 3 * t * t - 2 * t; // t3 − t2
  16256. return h00 + h10 + h01 + h11;
  16257. },
  16258. // Catmull-Rom
  16259. interpolate: function( p0, p1, p2, p3, t ) {
  16260. var v0 = ( p2 - p0 ) * 0.5;
  16261. var v1 = ( p3 - p1 ) * 0.5;
  16262. var t2 = t * t;
  16263. var t3 = t * t2;
  16264. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  16265. }
  16266. };
  16267. // TODO: Transformation for Curves?
  16268. /**************************************************************
  16269. * 3D Curves
  16270. **************************************************************/
  16271. // A Factory method for creating new curve subclasses
  16272. THREE.Curve.create = function ( constructor, getPointFunc ) {
  16273. constructor.prototype = Object.create( THREE.Curve.prototype );
  16274. constructor.prototype.constructor = constructor;
  16275. constructor.prototype.getPoint = getPointFunc;
  16276. return constructor;
  16277. };
  16278. // File:src/extras/core/CurvePath.js
  16279. /**
  16280. * @author zz85 / http://www.lab4games.net/zz85/blog
  16281. *
  16282. **/
  16283. /**************************************************************
  16284. * Curved Path - a curve path is simply a array of connected
  16285. * curves, but retains the api of a curve
  16286. **************************************************************/
  16287. THREE.CurvePath = function () {
  16288. this.curves = [];
  16289. this.bends = [];
  16290. this.autoClose = false; // Automatically closes the path
  16291. };
  16292. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  16293. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  16294. THREE.CurvePath.prototype.add = function ( curve ) {
  16295. this.curves.push( curve );
  16296. };
  16297. THREE.CurvePath.prototype.checkConnection = function() {
  16298. // TODO
  16299. // If the ending of curve is not connected to the starting
  16300. // or the next curve, then, this is not a real path
  16301. };
  16302. THREE.CurvePath.prototype.closePath = function() {
  16303. // TODO Test
  16304. // and verify for vector3 (needs to implement equals)
  16305. // Add a line curve if start and end of lines are not connected
  16306. var startPoint = this.curves[0].getPoint(0);
  16307. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  16308. if (! startPoint.equals(endPoint)) {
  16309. this.curves.push( new THREE.LineCurve(endPoint, startPoint) );
  16310. }
  16311. };
  16312. // To get accurate point with reference to
  16313. // entire path distance at time t,
  16314. // following has to be done:
  16315. // 1. Length of each sub path have to be known
  16316. // 2. Locate and identify type of curve
  16317. // 3. Get t for the curve
  16318. // 4. Return curve.getPointAt(t')
  16319. THREE.CurvePath.prototype.getPoint = function( t ) {
  16320. var d = t * this.getLength();
  16321. var curveLengths = this.getCurveLengths();
  16322. var i = 0, diff, curve;
  16323. // To think about boundaries points.
  16324. while ( i < curveLengths.length ) {
  16325. if ( curveLengths[ i ] >= d ) {
  16326. diff = curveLengths[ i ] - d;
  16327. curve = this.curves[ i ];
  16328. var u = 1 - diff / curve.getLength();
  16329. return curve.getPointAt( u );
  16330. }
  16331. i ++;
  16332. }
  16333. return null;
  16334. // loop where sum != 0, sum > d , sum+1 <d
  16335. };
  16336. /*
  16337. THREE.CurvePath.prototype.getTangent = function( t ) {
  16338. };*/
  16339. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  16340. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  16341. // getPoint() depends on getLength
  16342. THREE.CurvePath.prototype.getLength = function() {
  16343. var lens = this.getCurveLengths();
  16344. return lens[ lens.length - 1 ];
  16345. };
  16346. // Compute lengths and cache them
  16347. // We cannot overwrite getLengths() because UtoT mapping uses it.
  16348. THREE.CurvePath.prototype.getCurveLengths = function() {
  16349. // We use cache values if curves and cache array are same length
  16350. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  16351. return this.cacheLengths;
  16352. }
  16353. // Get length of sub-curve
  16354. // Push sums into cached array
  16355. var lengths = [], sums = 0;
  16356. var i, il = this.curves.length;
  16357. for ( i = 0; i < il; i ++ ) {
  16358. sums += this.curves[ i ].getLength();
  16359. lengths.push( sums );
  16360. }
  16361. this.cacheLengths = lengths;
  16362. return lengths;
  16363. };
  16364. // Returns min and max coordinates
  16365. THREE.CurvePath.prototype.getBoundingBox = function () {
  16366. var points = this.getPoints();
  16367. var maxX, maxY, maxZ;
  16368. var minX, minY, minZ;
  16369. maxX = maxY = Number.NEGATIVE_INFINITY;
  16370. minX = minY = Number.POSITIVE_INFINITY;
  16371. var p, i, il, sum;
  16372. var v3 = points[0] instanceof THREE.Vector3;
  16373. sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
  16374. for ( i = 0, il = points.length; i < il; i ++ ) {
  16375. p = points[ i ];
  16376. if ( p.x > maxX ) maxX = p.x;
  16377. else if ( p.x < minX ) minX = p.x;
  16378. if ( p.y > maxY ) maxY = p.y;
  16379. else if ( p.y < minY ) minY = p.y;
  16380. if ( v3 ) {
  16381. if ( p.z > maxZ ) maxZ = p.z;
  16382. else if ( p.z < minZ ) minZ = p.z;
  16383. }
  16384. sum.add( p );
  16385. }
  16386. var ret = {
  16387. minX: minX,
  16388. minY: minY,
  16389. maxX: maxX,
  16390. maxY: maxY
  16391. };
  16392. if ( v3 ) {
  16393. ret.maxZ = maxZ;
  16394. ret.minZ = minZ;
  16395. }
  16396. return ret;
  16397. };
  16398. /**************************************************************
  16399. * Create Geometries Helpers
  16400. **************************************************************/
  16401. /// Generate geometry from path points (for Line or Points objects)
  16402. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  16403. var pts = this.getPoints( divisions, true );
  16404. return this.createGeometry( pts );
  16405. };
  16406. // Generate geometry from equidistant sampling along the path
  16407. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  16408. var pts = this.getSpacedPoints( divisions, true );
  16409. return this.createGeometry( pts );
  16410. };
  16411. THREE.CurvePath.prototype.createGeometry = function( points ) {
  16412. var geometry = new THREE.Geometry();
  16413. for ( var i = 0; i < points.length; i ++ ) {
  16414. geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, points[ i ].z || 0) );
  16415. }
  16416. return geometry;
  16417. };
  16418. /**************************************************************
  16419. * Bend / Wrap Helper Methods
  16420. **************************************************************/
  16421. // Wrap path / Bend modifiers?
  16422. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  16423. this.bends.push( bendpath );
  16424. };
  16425. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  16426. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  16427. var i, il;
  16428. if ( ! bends ) {
  16429. bends = this.bends;
  16430. }
  16431. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16432. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16433. }
  16434. return oldPts;
  16435. };
  16436. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  16437. var oldPts = this.getSpacedPoints( segments );
  16438. var i, il;
  16439. if ( ! bends ) {
  16440. bends = this.bends;
  16441. }
  16442. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16443. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16444. }
  16445. return oldPts;
  16446. };
  16447. // This returns getPoints() bend/wrapped around the contour of a path.
  16448. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  16449. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  16450. var bounds = this.getBoundingBox();
  16451. var i, il, p, oldX, oldY, xNorm;
  16452. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  16453. p = oldPts[ i ];
  16454. oldX = p.x;
  16455. oldY = p.y;
  16456. xNorm = oldX / bounds.maxX;
  16457. // If using actual distance, for length > path, requires line extrusions
  16458. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  16459. xNorm = path.getUtoTmapping( xNorm, oldX );
  16460. // check for out of bounds?
  16461. var pathPt = path.getPoint( xNorm );
  16462. var normal = path.getTangent( xNorm );
  16463. normal.set( - normal.y, normal.x ).multiplyScalar( oldY );
  16464. p.x = pathPt.x + normal.x;
  16465. p.y = pathPt.y + normal.y;
  16466. }
  16467. return oldPts;
  16468. };
  16469. // File:src/extras/core/Gyroscope.js
  16470. /**
  16471. * @author alteredq / http://alteredqualia.com/
  16472. */
  16473. THREE.Gyroscope = function () {
  16474. THREE.Object3D.call( this );
  16475. };
  16476. THREE.Gyroscope.prototype = Object.create( THREE.Object3D.prototype );
  16477. THREE.Gyroscope.prototype.constructor = THREE.Gyroscope;
  16478. THREE.Gyroscope.prototype.updateMatrixWorld = ( function () {
  16479. var translationObject = new THREE.Vector3();
  16480. var quaternionObject = new THREE.Quaternion();
  16481. var scaleObject = new THREE.Vector3();
  16482. var translationWorld = new THREE.Vector3();
  16483. var quaternionWorld = new THREE.Quaternion();
  16484. var scaleWorld = new THREE.Vector3();
  16485. return function ( force ) {
  16486. this.matrixAutoUpdate && this.updateMatrix();
  16487. // update matrixWorld
  16488. if ( this.matrixWorldNeedsUpdate || force ) {
  16489. if ( this.parent ) {
  16490. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  16491. this.matrixWorld.decompose( translationWorld, quaternionWorld, scaleWorld );
  16492. this.matrix.decompose( translationObject, quaternionObject, scaleObject );
  16493. this.matrixWorld.compose( translationWorld, quaternionObject, scaleWorld );
  16494. } else {
  16495. this.matrixWorld.copy( this.matrix );
  16496. }
  16497. this.matrixWorldNeedsUpdate = false;
  16498. force = true;
  16499. }
  16500. // update children
  16501. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  16502. this.children[ i ].updateMatrixWorld( force );
  16503. }
  16504. };
  16505. }() );
  16506. // File:src/extras/core/Path.js
  16507. /**
  16508. * @author zz85 / http://www.lab4games.net/zz85/blog
  16509. * Creates free form 2d path using series of points, lines or curves.
  16510. *
  16511. **/
  16512. THREE.Path = function ( points ) {
  16513. THREE.CurvePath.call(this);
  16514. this.actions = [];
  16515. if ( points ) {
  16516. this.fromPoints( points );
  16517. }
  16518. };
  16519. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  16520. THREE.Path.prototype.constructor = THREE.Path;
  16521. THREE.PathActions = {
  16522. MOVE_TO: 'moveTo',
  16523. LINE_TO: 'lineTo',
  16524. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  16525. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  16526. CSPLINE_THRU: 'splineThru', // Catmull-Rom spline
  16527. ARC: 'arc', // Circle
  16528. ELLIPSE: 'ellipse'
  16529. };
  16530. // TODO Clean up PATH API
  16531. // Create path using straight lines to connect all points
  16532. // - vectors: array of Vector2
  16533. THREE.Path.prototype.fromPoints = function ( vectors ) {
  16534. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  16535. for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
  16536. this.lineTo( vectors[ v ].x, vectors[ v ].y );
  16537. }
  16538. };
  16539. // startPath() endPath()?
  16540. THREE.Path.prototype.moveTo = function ( x, y ) {
  16541. var args = Array.prototype.slice.call( arguments );
  16542. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  16543. };
  16544. THREE.Path.prototype.lineTo = function ( x, y ) {
  16545. var args = Array.prototype.slice.call( arguments );
  16546. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16547. var x0 = lastargs[ lastargs.length - 2 ];
  16548. var y0 = lastargs[ lastargs.length - 1 ];
  16549. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  16550. this.curves.push( curve );
  16551. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  16552. };
  16553. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  16554. var args = Array.prototype.slice.call( arguments );
  16555. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16556. var x0 = lastargs[ lastargs.length - 2 ];
  16557. var y0 = lastargs[ lastargs.length - 1 ];
  16558. var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
  16559. new THREE.Vector2( aCPx, aCPy ),
  16560. new THREE.Vector2( aX, aY ) );
  16561. this.curves.push( curve );
  16562. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  16563. };
  16564. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
  16565. aCP2x, aCP2y,
  16566. aX, aY ) {
  16567. var args = Array.prototype.slice.call( arguments );
  16568. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16569. var x0 = lastargs[ lastargs.length - 2 ];
  16570. var y0 = lastargs[ lastargs.length - 1 ];
  16571. var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
  16572. new THREE.Vector2( aCP1x, aCP1y ),
  16573. new THREE.Vector2( aCP2x, aCP2y ),
  16574. new THREE.Vector2( aX, aY ) );
  16575. this.curves.push( curve );
  16576. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  16577. };
  16578. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  16579. var args = Array.prototype.slice.call( arguments );
  16580. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16581. var x0 = lastargs[ lastargs.length - 2 ];
  16582. var y0 = lastargs[ lastargs.length - 1 ];
  16583. //---
  16584. var npts = [ new THREE.Vector2( x0, y0 ) ];
  16585. Array.prototype.push.apply( npts, pts );
  16586. var curve = new THREE.SplineCurve( npts );
  16587. this.curves.push( curve );
  16588. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  16589. };
  16590. // FUTURE: Change the API or follow canvas API?
  16591. THREE.Path.prototype.arc = function ( aX, aY, aRadius,
  16592. aStartAngle, aEndAngle, aClockwise ) {
  16593. var lastargs = this.actions[ this.actions.length - 1].args;
  16594. var x0 = lastargs[ lastargs.length - 2 ];
  16595. var y0 = lastargs[ lastargs.length - 1 ];
  16596. this.absarc(aX + x0, aY + y0, aRadius,
  16597. aStartAngle, aEndAngle, aClockwise );
  16598. };
  16599. THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
  16600. aStartAngle, aEndAngle, aClockwise ) {
  16601. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  16602. };
  16603. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
  16604. aStartAngle, aEndAngle, aClockwise ) {
  16605. var lastargs = this.actions[ this.actions.length - 1].args;
  16606. var x0 = lastargs[ lastargs.length - 2 ];
  16607. var y0 = lastargs[ lastargs.length - 1 ];
  16608. this.absellipse(aX + x0, aY + y0, xRadius, yRadius,
  16609. aStartAngle, aEndAngle, aClockwise );
  16610. };
  16611. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
  16612. aStartAngle, aEndAngle, aClockwise ) {
  16613. var args = Array.prototype.slice.call( arguments );
  16614. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
  16615. aStartAngle, aEndAngle, aClockwise );
  16616. this.curves.push( curve );
  16617. var lastPoint = curve.getPoint(1);
  16618. args.push(lastPoint.x);
  16619. args.push(lastPoint.y);
  16620. this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
  16621. };
  16622. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  16623. if ( ! divisions ) divisions = 40;
  16624. var points = [];
  16625. for ( var i = 0; i < divisions; i ++ ) {
  16626. points.push( this.getPoint( i / divisions ) );
  16627. //if( !this.getPoint( i / divisions ) ) throw "DIE";
  16628. }
  16629. // if ( closedPath ) {
  16630. //
  16631. // points.push( points[ 0 ] );
  16632. //
  16633. // }
  16634. return points;
  16635. };
  16636. /* Return an array of vectors based on contour of the path */
  16637. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  16638. if (this.useSpacedPoints) {
  16639. return this.getSpacedPoints( divisions, closedPath );
  16640. }
  16641. divisions = divisions || 12;
  16642. var points = [];
  16643. var i, il, item, action, args;
  16644. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  16645. laste, j,
  16646. t, tx, ty;
  16647. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  16648. item = this.actions[ i ];
  16649. action = item.action;
  16650. args = item.args;
  16651. switch ( action ) {
  16652. case THREE.PathActions.MOVE_TO:
  16653. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16654. break;
  16655. case THREE.PathActions.LINE_TO:
  16656. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16657. break;
  16658. case THREE.PathActions.QUADRATIC_CURVE_TO:
  16659. cpx = args[ 2 ];
  16660. cpy = args[ 3 ];
  16661. cpx1 = args[ 0 ];
  16662. cpy1 = args[ 1 ];
  16663. if ( points.length > 0 ) {
  16664. laste = points[ points.length - 1 ];
  16665. cpx0 = laste.x;
  16666. cpy0 = laste.y;
  16667. } else {
  16668. laste = this.actions[ i - 1 ].args;
  16669. cpx0 = laste[ laste.length - 2 ];
  16670. cpy0 = laste[ laste.length - 1 ];
  16671. }
  16672. for ( j = 1; j <= divisions; j ++ ) {
  16673. t = j / divisions;
  16674. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  16675. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  16676. points.push( new THREE.Vector2( tx, ty ) );
  16677. }
  16678. break;
  16679. case THREE.PathActions.BEZIER_CURVE_TO:
  16680. cpx = args[ 4 ];
  16681. cpy = args[ 5 ];
  16682. cpx1 = args[ 0 ];
  16683. cpy1 = args[ 1 ];
  16684. cpx2 = args[ 2 ];
  16685. cpy2 = args[ 3 ];
  16686. if ( points.length > 0 ) {
  16687. laste = points[ points.length - 1 ];
  16688. cpx0 = laste.x;
  16689. cpy0 = laste.y;
  16690. } else {
  16691. laste = this.actions[ i - 1 ].args;
  16692. cpx0 = laste[ laste.length - 2 ];
  16693. cpy0 = laste[ laste.length - 1 ];
  16694. }
  16695. for ( j = 1; j <= divisions; j ++ ) {
  16696. t = j / divisions;
  16697. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  16698. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  16699. points.push( new THREE.Vector2( tx, ty ) );
  16700. }
  16701. break;
  16702. case THREE.PathActions.CSPLINE_THRU:
  16703. laste = this.actions[ i - 1 ].args;
  16704. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  16705. var spts = [ last ];
  16706. var n = divisions * args[ 0 ].length;
  16707. spts = spts.concat( args[ 0 ] );
  16708. var spline = new THREE.SplineCurve( spts );
  16709. for ( j = 1; j <= n; j ++ ) {
  16710. points.push( spline.getPointAt( j / n ) ) ;
  16711. }
  16712. break;
  16713. case THREE.PathActions.ARC:
  16714. var aX = args[ 0 ], aY = args[ 1 ],
  16715. aRadius = args[ 2 ],
  16716. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  16717. aClockwise = !! args[ 5 ];
  16718. var deltaAngle = aEndAngle - aStartAngle;
  16719. var angle;
  16720. var tdivisions = divisions * 2;
  16721. for ( j = 1; j <= tdivisions; j ++ ) {
  16722. t = j / tdivisions;
  16723. if ( ! aClockwise ) {
  16724. t = 1 - t;
  16725. }
  16726. angle = aStartAngle + t * deltaAngle;
  16727. tx = aX + aRadius * Math.cos( angle );
  16728. ty = aY + aRadius * Math.sin( angle );
  16729. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16730. points.push( new THREE.Vector2( tx, ty ) );
  16731. }
  16732. //console.log(points);
  16733. break;
  16734. case THREE.PathActions.ELLIPSE:
  16735. var aX = args[ 0 ], aY = args[ 1 ],
  16736. xRadius = args[ 2 ],
  16737. yRadius = args[ 3 ],
  16738. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  16739. aClockwise = !! args[ 6 ];
  16740. var deltaAngle = aEndAngle - aStartAngle;
  16741. var angle;
  16742. var tdivisions = divisions * 2;
  16743. for ( j = 1; j <= tdivisions; j ++ ) {
  16744. t = j / tdivisions;
  16745. if ( ! aClockwise ) {
  16746. t = 1 - t;
  16747. }
  16748. angle = aStartAngle + t * deltaAngle;
  16749. tx = aX + xRadius * Math.cos( angle );
  16750. ty = aY + yRadius * Math.sin( angle );
  16751. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16752. points.push( new THREE.Vector2( tx, ty ) );
  16753. }
  16754. //console.log(points);
  16755. break;
  16756. } // end switch
  16757. }
  16758. // Normalize to remove the closing point by default.
  16759. var lastPoint = points[ points.length - 1];
  16760. var EPSILON = 0.0000000001;
  16761. if ( Math.abs(lastPoint.x - points[ 0 ].x) < EPSILON &&
  16762. Math.abs(lastPoint.y - points[ 0 ].y) < EPSILON)
  16763. points.splice( points.length - 1, 1);
  16764. if ( closedPath ) {
  16765. points.push( points[ 0 ] );
  16766. }
  16767. return points;
  16768. };
  16769. //
  16770. // Breaks path into shapes
  16771. //
  16772. // Assumptions (if parameter isCCW==true the opposite holds):
  16773. // - solid shapes are defined clockwise (CW)
  16774. // - holes are defined counterclockwise (CCW)
  16775. //
  16776. // If parameter noHoles==true:
  16777. // - all subPaths are regarded as solid shapes
  16778. // - definition order CW/CCW has no relevance
  16779. //
  16780. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  16781. function extractSubpaths( inActions ) {
  16782. var i, il, item, action, args;
  16783. var subPaths = [], lastPath = new THREE.Path();
  16784. for ( i = 0, il = inActions.length; i < il; i ++ ) {
  16785. item = inActions[ i ];
  16786. args = item.args;
  16787. action = item.action;
  16788. if ( action === THREE.PathActions.MOVE_TO ) {
  16789. if ( lastPath.actions.length !== 0 ) {
  16790. subPaths.push( lastPath );
  16791. lastPath = new THREE.Path();
  16792. }
  16793. }
  16794. lastPath[ action ].apply( lastPath, args );
  16795. }
  16796. if ( lastPath.actions.length !== 0 ) {
  16797. subPaths.push( lastPath );
  16798. }
  16799. // console.log(subPaths);
  16800. return subPaths;
  16801. }
  16802. function toShapesNoHoles( inSubpaths ) {
  16803. var shapes = [];
  16804. for ( var i = 0, il = inSubpaths.length; i < il; i ++ ) {
  16805. var tmpPath = inSubpaths[ i ];
  16806. var tmpShape = new THREE.Shape();
  16807. tmpShape.actions = tmpPath.actions;
  16808. tmpShape.curves = tmpPath.curves;
  16809. shapes.push( tmpShape );
  16810. }
  16811. //console.log("shape", shapes);
  16812. return shapes;
  16813. }
  16814. function isPointInsidePolygon( inPt, inPolygon ) {
  16815. var EPSILON = 0.0000000001;
  16816. var polyLen = inPolygon.length;
  16817. // inPt on polygon contour => immediate success or
  16818. // toggling of inside/outside at every single! intersection point of an edge
  16819. // with the horizontal line through inPt, left of inPt
  16820. // not counting lowerY endpoints of edges and whole edges on that line
  16821. var inside = false;
  16822. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  16823. var edgeLowPt = inPolygon[ p ];
  16824. var edgeHighPt = inPolygon[ q ];
  16825. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  16826. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  16827. if ( Math.abs(edgeDy) > EPSILON ) { // not parallel
  16828. if ( edgeDy < 0 ) {
  16829. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  16830. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  16831. }
  16832. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  16833. if ( inPt.y === edgeLowPt.y ) {
  16834. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  16835. // continue; // no intersection or edgeLowPt => doesn't count !!!
  16836. } else {
  16837. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  16838. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  16839. if ( perpEdge < 0 ) continue;
  16840. inside = ! inside; // true intersection left of inPt
  16841. }
  16842. } else { // parallel or collinear
  16843. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  16844. // edge lies on the same horizontal line as inPt
  16845. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  16846. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  16847. // continue;
  16848. }
  16849. }
  16850. return inside;
  16851. }
  16852. var subPaths = extractSubpaths( this.actions );
  16853. if ( subPaths.length === 0 ) return [];
  16854. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  16855. var solid, tmpPath, tmpShape, shapes = [];
  16856. if ( subPaths.length === 1) {
  16857. tmpPath = subPaths[0];
  16858. tmpShape = new THREE.Shape();
  16859. tmpShape.actions = tmpPath.actions;
  16860. tmpShape.curves = tmpPath.curves;
  16861. shapes.push( tmpShape );
  16862. return shapes;
  16863. }
  16864. var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  16865. holesFirst = isCCW ? ! holesFirst : holesFirst;
  16866. // console.log("Holes first", holesFirst);
  16867. var betterShapeHoles = [];
  16868. var newShapes = [];
  16869. var newShapeHoles = [];
  16870. var mainIdx = 0;
  16871. var tmpPoints;
  16872. newShapes[mainIdx] = undefined;
  16873. newShapeHoles[mainIdx] = [];
  16874. var i, il;
  16875. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  16876. tmpPath = subPaths[ i ];
  16877. tmpPoints = tmpPath.getPoints();
  16878. solid = THREE.Shape.Utils.isClockWise( tmpPoints );
  16879. solid = isCCW ? ! solid : solid;
  16880. if ( solid ) {
  16881. if ( (! holesFirst ) && ( newShapes[mainIdx] ) ) mainIdx ++;
  16882. newShapes[mainIdx] = { s: new THREE.Shape(), p: tmpPoints };
  16883. newShapes[mainIdx].s.actions = tmpPath.actions;
  16884. newShapes[mainIdx].s.curves = tmpPath.curves;
  16885. if ( holesFirst ) mainIdx ++;
  16886. newShapeHoles[mainIdx] = [];
  16887. //console.log('cw', i);
  16888. } else {
  16889. newShapeHoles[mainIdx].push( { h: tmpPath, p: tmpPoints[0] } );
  16890. //console.log('ccw', i);
  16891. }
  16892. }
  16893. // only Holes? -> probably all Shapes with wrong orientation
  16894. if ( ! newShapes[0] ) return toShapesNoHoles( subPaths );
  16895. if ( newShapes.length > 1 ) {
  16896. var ambiguous = false;
  16897. var toChange = [];
  16898. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  16899. betterShapeHoles[sIdx] = [];
  16900. }
  16901. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  16902. var sho = newShapeHoles[sIdx];
  16903. for (var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  16904. var ho = sho[hIdx];
  16905. var hole_unassigned = true;
  16906. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  16907. if ( isPointInsidePolygon( ho.p, newShapes[s2Idx].p ) ) {
  16908. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  16909. if ( hole_unassigned ) {
  16910. hole_unassigned = false;
  16911. betterShapeHoles[s2Idx].push( ho );
  16912. } else {
  16913. ambiguous = true;
  16914. }
  16915. }
  16916. }
  16917. if ( hole_unassigned ) { betterShapeHoles[sIdx].push( ho ); }
  16918. }
  16919. }
  16920. // console.log("ambiguous: ", ambiguous);
  16921. if ( toChange.length > 0 ) {
  16922. // console.log("to change: ", toChange);
  16923. if (! ambiguous) newShapeHoles = betterShapeHoles;
  16924. }
  16925. }
  16926. var tmpHoles, j, jl;
  16927. for ( i = 0, il = newShapes.length; i < il; i ++ ) {
  16928. tmpShape = newShapes[i].s;
  16929. shapes.push( tmpShape );
  16930. tmpHoles = newShapeHoles[i];
  16931. for ( j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  16932. tmpShape.holes.push( tmpHoles[j].h );
  16933. }
  16934. }
  16935. //console.log("shape", shapes);
  16936. return shapes;
  16937. };
  16938. // File:src/extras/core/Shape.js
  16939. /**
  16940. * @author zz85 / http://www.lab4games.net/zz85/blog
  16941. * Defines a 2d shape plane using paths.
  16942. **/
  16943. // STEP 1 Create a path.
  16944. // STEP 2 Turn path into shape.
  16945. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  16946. // STEP 3a - Extract points from each shape, turn to vertices
  16947. // STEP 3b - Triangulate each shape, add faces.
  16948. THREE.Shape = function () {
  16949. THREE.Path.apply( this, arguments );
  16950. this.holes = [];
  16951. };
  16952. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  16953. THREE.Shape.prototype.constructor = THREE.Shape;
  16954. // Convenience method to return ExtrudeGeometry
  16955. THREE.Shape.prototype.extrude = function ( options ) {
  16956. var extruded = new THREE.ExtrudeGeometry( this, options );
  16957. return extruded;
  16958. };
  16959. // Convenience method to return ShapeGeometry
  16960. THREE.Shape.prototype.makeGeometry = function ( options ) {
  16961. var geometry = new THREE.ShapeGeometry( this, options );
  16962. return geometry;
  16963. };
  16964. // Get points of holes
  16965. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  16966. var i, il = this.holes.length, holesPts = [];
  16967. for ( i = 0; i < il; i ++ ) {
  16968. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  16969. }
  16970. return holesPts;
  16971. };
  16972. // Get points of holes (spaced by regular distance)
  16973. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  16974. var i, il = this.holes.length, holesPts = [];
  16975. for ( i = 0; i < il; i ++ ) {
  16976. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  16977. }
  16978. return holesPts;
  16979. };
  16980. // Get points of shape and holes (keypoints based on segments parameter)
  16981. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  16982. return {
  16983. shape: this.getTransformedPoints( divisions ),
  16984. holes: this.getPointsHoles( divisions )
  16985. };
  16986. };
  16987. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  16988. if (this.useSpacedPoints) {
  16989. return this.extractAllSpacedPoints(divisions);
  16990. }
  16991. return this.extractAllPoints(divisions);
  16992. };
  16993. //
  16994. // THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  16995. //
  16996. // return {
  16997. //
  16998. // shape: this.transform( bend, divisions ),
  16999. // holes: this.getPointsHoles( divisions, bend )
  17000. //
  17001. // };
  17002. //
  17003. // };
  17004. // Get points of shape and holes (spaced by regular distance)
  17005. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  17006. return {
  17007. shape: this.getTransformedSpacedPoints( divisions ),
  17008. holes: this.getSpacedPointsHoles( divisions )
  17009. };
  17010. };
  17011. /**************************************************************
  17012. * Utils
  17013. **************************************************************/
  17014. THREE.Shape.Utils = {
  17015. triangulateShape: function ( contour, holes ) {
  17016. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  17017. // inOtherPt needs to be collinear to the inSegment
  17018. if ( inSegPt1.x !== inSegPt2.x ) {
  17019. if ( inSegPt1.x < inSegPt2.x ) {
  17020. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  17021. } else {
  17022. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  17023. }
  17024. } else {
  17025. if ( inSegPt1.y < inSegPt2.y ) {
  17026. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  17027. } else {
  17028. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  17029. }
  17030. }
  17031. }
  17032. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  17033. var EPSILON = 0.0000000001;
  17034. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  17035. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  17036. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  17037. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  17038. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  17039. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  17040. if ( Math.abs(limit) > EPSILON ) { // not parallel
  17041. var perpSeg2;
  17042. if ( limit > 0 ) {
  17043. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  17044. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17045. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  17046. } else {
  17047. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  17048. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17049. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  17050. }
  17051. // i.e. to reduce rounding errors
  17052. // intersection at endpoint of segment#1?
  17053. if ( perpSeg2 === 0 ) {
  17054. if ( ( inExcludeAdjacentSegs ) &&
  17055. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17056. return [ inSeg1Pt1 ];
  17057. }
  17058. if ( perpSeg2 === limit ) {
  17059. if ( ( inExcludeAdjacentSegs ) &&
  17060. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17061. return [ inSeg1Pt2 ];
  17062. }
  17063. // intersection at endpoint of segment#2?
  17064. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  17065. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  17066. // return real intersection point
  17067. var factorSeg1 = perpSeg2 / limit;
  17068. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  17069. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  17070. } else { // parallel or collinear
  17071. if ( ( perpSeg1 !== 0 ) ||
  17072. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  17073. // they are collinear or degenerate
  17074. var seg1Pt = ( (seg1dx === 0) && (seg1dy === 0) ); // segment1 is just a point?
  17075. var seg2Pt = ( (seg2dx === 0) && (seg2dy === 0) ); // segment2 is just a point?
  17076. // both segments are points
  17077. if ( seg1Pt && seg2Pt ) {
  17078. if ( (inSeg1Pt1.x !== inSeg2Pt1.x) ||
  17079. (inSeg1Pt1.y !== inSeg2Pt1.y) ) return []; // they are distinct points
  17080. return [ inSeg1Pt1 ]; // they are the same point
  17081. }
  17082. // segment#1 is a single point
  17083. if ( seg1Pt ) {
  17084. if (! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  17085. return [ inSeg1Pt1 ];
  17086. }
  17087. // segment#2 is a single point
  17088. if ( seg2Pt ) {
  17089. if (! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  17090. return [ inSeg2Pt1 ];
  17091. }
  17092. // they are collinear segments, which might overlap
  17093. var seg1min, seg1max, seg1minVal, seg1maxVal;
  17094. var seg2min, seg2max, seg2minVal, seg2maxVal;
  17095. if (seg1dx !== 0) { // the segments are NOT on a vertical line
  17096. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  17097. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  17098. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  17099. } else {
  17100. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  17101. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  17102. }
  17103. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  17104. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  17105. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  17106. } else {
  17107. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  17108. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  17109. }
  17110. } else { // the segments are on a vertical line
  17111. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  17112. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  17113. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  17114. } else {
  17115. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  17116. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  17117. }
  17118. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  17119. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  17120. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  17121. } else {
  17122. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  17123. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  17124. }
  17125. }
  17126. if ( seg1minVal <= seg2minVal ) {
  17127. if ( seg1maxVal < seg2minVal ) return [];
  17128. if ( seg1maxVal === seg2minVal ) {
  17129. if ( inExcludeAdjacentSegs ) return [];
  17130. return [ seg2min ];
  17131. }
  17132. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  17133. return [ seg2min, seg2max ];
  17134. } else {
  17135. if ( seg1minVal > seg2maxVal ) return [];
  17136. if ( seg1minVal === seg2maxVal ) {
  17137. if ( inExcludeAdjacentSegs ) return [];
  17138. return [ seg1min ];
  17139. }
  17140. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  17141. return [ seg1min, seg2max ];
  17142. }
  17143. }
  17144. }
  17145. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  17146. // The order of legs is important
  17147. var EPSILON = 0.0000000001;
  17148. // translation of all points, so that Vertex is at (0,0)
  17149. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  17150. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  17151. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  17152. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  17153. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  17154. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  17155. if ( Math.abs(from2toAngle) > EPSILON ) { // angle != 180 deg.
  17156. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  17157. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  17158. if ( from2toAngle > 0 ) { // main angle < 180 deg.
  17159. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  17160. } else { // main angle > 180 deg.
  17161. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  17162. }
  17163. } else { // angle == 180 deg.
  17164. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  17165. return ( from2otherAngle > 0 );
  17166. }
  17167. }
  17168. function removeHoles( contour, holes ) {
  17169. var shape = contour.concat(); // work on this shape
  17170. var hole;
  17171. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  17172. // Check if hole point lies within angle around shape point
  17173. var lastShapeIdx = shape.length - 1;
  17174. var prevShapeIdx = inShapeIdx - 1;
  17175. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  17176. var nextShapeIdx = inShapeIdx + 1;
  17177. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  17178. var insideAngle = isPointInsideAngle( shape[inShapeIdx], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[inHoleIdx] );
  17179. if (! insideAngle ) {
  17180. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  17181. return false;
  17182. }
  17183. // Check if shape point lies within angle around hole point
  17184. var lastHoleIdx = hole.length - 1;
  17185. var prevHoleIdx = inHoleIdx - 1;
  17186. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  17187. var nextHoleIdx = inHoleIdx + 1;
  17188. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  17189. insideAngle = isPointInsideAngle( hole[inHoleIdx], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[inShapeIdx] );
  17190. if (! insideAngle ) {
  17191. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  17192. return false;
  17193. }
  17194. return true;
  17195. }
  17196. function intersectsShapeEdge( inShapePt, inHolePt ) {
  17197. // checks for intersections with shape edges
  17198. var sIdx, nextIdx, intersection;
  17199. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  17200. nextIdx = sIdx + 1; nextIdx %= shape.length;
  17201. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[sIdx], shape[nextIdx], true );
  17202. if ( intersection.length > 0 ) return true;
  17203. }
  17204. return false;
  17205. }
  17206. var indepHoles = [];
  17207. function intersectsHoleEdge( inShapePt, inHolePt ) {
  17208. // checks for intersections with hole edges
  17209. var ihIdx, chkHole,
  17210. hIdx, nextIdx, intersection;
  17211. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  17212. chkHole = holes[indepHoles[ihIdx]];
  17213. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  17214. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  17215. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[hIdx], chkHole[nextIdx], true );
  17216. if ( intersection.length > 0 ) return true;
  17217. }
  17218. }
  17219. return false;
  17220. }
  17221. var holeIndex, shapeIndex,
  17222. shapePt, holePt,
  17223. holeIdx, cutKey, failedCuts = [],
  17224. tmpShape1, tmpShape2,
  17225. tmpHole1, tmpHole2;
  17226. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17227. indepHoles.push( h );
  17228. }
  17229. var minShapeIndex = 0;
  17230. var counter = indepHoles.length * 2;
  17231. while ( indepHoles.length > 0 ) {
  17232. counter --;
  17233. if ( counter < 0 ) {
  17234. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  17235. break;
  17236. }
  17237. // search for shape-vertex and hole-vertex,
  17238. // which can be connected without intersections
  17239. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  17240. shapePt = shape[ shapeIndex ];
  17241. holeIndex = - 1;
  17242. // search for hole which can be reached without intersections
  17243. for ( var h = 0; h < indepHoles.length; h ++ ) {
  17244. holeIdx = indepHoles[h];
  17245. // prevent multiple checks
  17246. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  17247. if ( failedCuts[cutKey] !== undefined ) continue;
  17248. hole = holes[holeIdx];
  17249. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  17250. holePt = hole[ h2 ];
  17251. if (! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  17252. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  17253. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  17254. holeIndex = h2;
  17255. indepHoles.splice(h, 1);
  17256. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  17257. tmpShape2 = shape.slice( shapeIndex );
  17258. tmpHole1 = hole.slice( holeIndex );
  17259. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  17260. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  17261. minShapeIndex = shapeIndex;
  17262. // Debug only, to show the selected cuts
  17263. // glob_CutLines.push( [ shapePt, holePt ] );
  17264. break;
  17265. }
  17266. if ( holeIndex >= 0 ) break; // hole-vertex found
  17267. failedCuts[cutKey] = true; // remember failure
  17268. }
  17269. if ( holeIndex >= 0 ) break; // hole-vertex found
  17270. }
  17271. }
  17272. return shape; /* shape with no holes */
  17273. }
  17274. var i, il, f, face,
  17275. key, index,
  17276. allPointsMap = {};
  17277. // 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.
  17278. var allpoints = contour.concat();
  17279. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17280. Array.prototype.push.apply( allpoints, holes[h] );
  17281. }
  17282. //console.log( "allpoints",allpoints, allpoints.length );
  17283. // prepare all points map
  17284. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  17285. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  17286. if ( allPointsMap[ key ] !== undefined ) {
  17287. console.warn( "THREE.Shape: Duplicate point", key );
  17288. }
  17289. allPointsMap[ key ] = i;
  17290. }
  17291. // remove holes by cutting paths to holes and adding them to the shape
  17292. var shapeWithoutHoles = removeHoles( contour, holes );
  17293. var triangles = THREE.FontUtils.Triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  17294. //console.log( "triangles",triangles, triangles.length );
  17295. // check all face vertices against all points map
  17296. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  17297. face = triangles[ i ];
  17298. for ( f = 0; f < 3; f ++ ) {
  17299. key = face[ f ].x + ":" + face[ f ].y;
  17300. index = allPointsMap[ key ];
  17301. if ( index !== undefined ) {
  17302. face[ f ] = index;
  17303. }
  17304. }
  17305. }
  17306. return triangles.concat();
  17307. },
  17308. isClockWise: function ( pts ) {
  17309. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  17310. },
  17311. // Bezier Curves formulas obtained from
  17312. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  17313. // Quad Bezier Functions
  17314. b2p0: function ( t, p ) {
  17315. var k = 1 - t;
  17316. return k * k * p;
  17317. },
  17318. b2p1: function ( t, p ) {
  17319. return 2 * ( 1 - t ) * t * p;
  17320. },
  17321. b2p2: function ( t, p ) {
  17322. return t * t * p;
  17323. },
  17324. b2: function ( t, p0, p1, p2 ) {
  17325. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  17326. },
  17327. // Cubic Bezier Functions
  17328. b3p0: function ( t, p ) {
  17329. var k = 1 - t;
  17330. return k * k * k * p;
  17331. },
  17332. b3p1: function ( t, p ) {
  17333. var k = 1 - t;
  17334. return 3 * k * k * t * p;
  17335. },
  17336. b3p2: function ( t, p ) {
  17337. var k = 1 - t;
  17338. return 3 * k * t * t * p;
  17339. },
  17340. b3p3: function ( t, p ) {
  17341. return t * t * t * p;
  17342. },
  17343. b3: function ( t, p0, p1, p2, p3 ) {
  17344. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  17345. }
  17346. };
  17347. // File:src/extras/curves/LineCurve.js
  17348. /**************************************************************
  17349. * Line
  17350. **************************************************************/
  17351. THREE.LineCurve = function ( v1, v2 ) {
  17352. this.v1 = v1;
  17353. this.v2 = v2;
  17354. };
  17355. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  17356. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  17357. THREE.LineCurve.prototype.getPoint = function ( t ) {
  17358. var point = this.v2.clone().sub(this.v1);
  17359. point.multiplyScalar( t ).add( this.v1 );
  17360. return point;
  17361. };
  17362. // Line curve is linear, so we can overwrite default getPointAt
  17363. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  17364. return this.getPoint( u );
  17365. };
  17366. THREE.LineCurve.prototype.getTangent = function( t ) {
  17367. var tangent = this.v2.clone().sub(this.v1);
  17368. return tangent.normalize();
  17369. };
  17370. // File:src/extras/curves/QuadraticBezierCurve.js
  17371. /**************************************************************
  17372. * Quadratic Bezier curve
  17373. **************************************************************/
  17374. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  17375. this.v0 = v0;
  17376. this.v1 = v1;
  17377. this.v2 = v2;
  17378. };
  17379. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17380. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  17381. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  17382. var vector = new THREE.Vector2();
  17383. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17384. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17385. return vector;
  17386. };
  17387. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  17388. var vector = new THREE.Vector2();
  17389. vector.x = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  17390. vector.y = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  17391. // returns unit vector
  17392. return vector.normalize();
  17393. };
  17394. // File:src/extras/curves/CubicBezierCurve.js
  17395. /**************************************************************
  17396. * Cubic Bezier curve
  17397. **************************************************************/
  17398. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  17399. this.v0 = v0;
  17400. this.v1 = v1;
  17401. this.v2 = v2;
  17402. this.v3 = v3;
  17403. };
  17404. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17405. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  17406. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  17407. var tx, ty;
  17408. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17409. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17410. return new THREE.Vector2( tx, ty );
  17411. };
  17412. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  17413. var tx, ty;
  17414. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17415. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17416. var tangent = new THREE.Vector2( tx, ty );
  17417. tangent.normalize();
  17418. return tangent;
  17419. };
  17420. // File:src/extras/curves/SplineCurve.js
  17421. /**************************************************************
  17422. * Spline curve
  17423. **************************************************************/
  17424. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  17425. this.points = ( points == undefined ) ? [] : points;
  17426. };
  17427. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  17428. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  17429. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  17430. var points = this.points;
  17431. var point = ( points.length - 1 ) * t;
  17432. var intPoint = Math.floor( point );
  17433. var weight = point - intPoint;
  17434. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  17435. var point1 = points[ intPoint ];
  17436. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17437. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17438. var vector = new THREE.Vector2();
  17439. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17440. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17441. return vector;
  17442. };
  17443. // File:src/extras/curves/EllipseCurve.js
  17444. /**************************************************************
  17445. * Ellipse curve
  17446. **************************************************************/
  17447. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise ) {
  17448. this.aX = aX;
  17449. this.aY = aY;
  17450. this.xRadius = xRadius;
  17451. this.yRadius = yRadius;
  17452. this.aStartAngle = aStartAngle;
  17453. this.aEndAngle = aEndAngle;
  17454. this.aClockwise = aClockwise;
  17455. };
  17456. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  17457. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  17458. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  17459. var deltaAngle = this.aEndAngle - this.aStartAngle;
  17460. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  17461. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  17462. var angle;
  17463. if ( this.aClockwise === true ) {
  17464. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  17465. } else {
  17466. angle = this.aStartAngle + t * deltaAngle;
  17467. }
  17468. var vector = new THREE.Vector2();
  17469. vector.x = this.aX + this.xRadius * Math.cos( angle );
  17470. vector.y = this.aY + this.yRadius * Math.sin( angle );
  17471. return vector;
  17472. };
  17473. // File:src/extras/curves/ArcCurve.js
  17474. /**************************************************************
  17475. * Arc curve
  17476. **************************************************************/
  17477. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17478. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17479. };
  17480. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  17481. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  17482. // File:src/extras/curves/LineCurve3.js
  17483. /**************************************************************
  17484. * Line3D
  17485. **************************************************************/
  17486. THREE.LineCurve3 = THREE.Curve.create(
  17487. function ( v1, v2 ) {
  17488. this.v1 = v1;
  17489. this.v2 = v2;
  17490. },
  17491. function ( t ) {
  17492. var vector = new THREE.Vector3();
  17493. vector.subVectors( this.v2, this.v1 ); // diff
  17494. vector.multiplyScalar( t );
  17495. vector.add( this.v1 );
  17496. return vector;
  17497. }
  17498. );
  17499. // File:src/extras/curves/QuadraticBezierCurve3.js
  17500. /**************************************************************
  17501. * Quadratic Bezier 3D curve
  17502. **************************************************************/
  17503. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  17504. function ( v0, v1, v2 ) {
  17505. this.v0 = v0;
  17506. this.v1 = v1;
  17507. this.v2 = v2;
  17508. },
  17509. function ( t ) {
  17510. var vector = new THREE.Vector3();
  17511. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17512. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17513. vector.z = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  17514. return vector;
  17515. }
  17516. );
  17517. // File:src/extras/curves/CubicBezierCurve3.js
  17518. /**************************************************************
  17519. * Cubic Bezier 3D curve
  17520. **************************************************************/
  17521. THREE.CubicBezierCurve3 = THREE.Curve.create(
  17522. function ( v0, v1, v2, v3 ) {
  17523. this.v0 = v0;
  17524. this.v1 = v1;
  17525. this.v2 = v2;
  17526. this.v3 = v3;
  17527. },
  17528. function ( t ) {
  17529. var vector = new THREE.Vector3();
  17530. vector.x = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17531. vector.y = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17532. vector.z = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  17533. return vector;
  17534. }
  17535. );
  17536. // File:src/extras/curves/SplineCurve3.js
  17537. /**************************************************************
  17538. * Spline 3D curve
  17539. **************************************************************/
  17540. THREE.SplineCurve3 = THREE.Curve.create(
  17541. function ( points /* array of Vector3 */) {
  17542. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  17543. this.points = ( points == undefined ) ? [] : points;
  17544. },
  17545. function ( t ) {
  17546. var points = this.points;
  17547. var point = ( points.length - 1 ) * t;
  17548. var intPoint = Math.floor( point );
  17549. var weight = point - intPoint;
  17550. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  17551. var point1 = points[ intPoint ];
  17552. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17553. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17554. var vector = new THREE.Vector3();
  17555. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17556. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17557. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17558. return vector;
  17559. }
  17560. );
  17561. // File:src/extras/curves/CatmullRomCurve3.js
  17562. /**
  17563. * @author zz85 https://github.com/zz85
  17564. *
  17565. * Centripetal CatmullRom Curve - which is useful for avoiding
  17566. * cusps and self-intersections in non-uniform catmull rom curves.
  17567. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  17568. *
  17569. * curve.type accepts centripetal(default), chordal and catmullrom
  17570. * curve.tension is used for catmullrom which defaults to 0.5
  17571. */
  17572. THREE.CatmullRomCurve3 = ( function() {
  17573. var
  17574. tmp = new THREE.Vector3(),
  17575. px = new CubicPoly(),
  17576. py = new CubicPoly(),
  17577. pz = new CubicPoly();
  17578. /*
  17579. Based on an optimized c++ solution in
  17580. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  17581. - http://ideone.com/NoEbVM
  17582. This CubicPoly class could be used for reusing some variables and calculations,
  17583. but for three.js curve use, it could be possible inlined and flatten into a single function call
  17584. which can be placed in CurveUtils.
  17585. */
  17586. function CubicPoly() {
  17587. }
  17588. /*
  17589. * Compute coefficients for a cubic polynomial
  17590. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  17591. * such that
  17592. * p(0) = x0, p(1) = x1
  17593. * and
  17594. * p'(0) = t0, p'(1) = t1.
  17595. */
  17596. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  17597. this.c0 = x0;
  17598. this.c1 = t0;
  17599. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  17600. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  17601. };
  17602. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  17603. // compute tangents when parameterized in [t1,t2]
  17604. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  17605. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  17606. // rescale tangents for parametrization in [0,1]
  17607. t1 *= dt1;
  17608. t2 *= dt1;
  17609. // initCubicPoly
  17610. this.init( x1, x2, t1, t2 );
  17611. };
  17612. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  17613. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  17614. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  17615. };
  17616. CubicPoly.prototype.calc = function( t ) {
  17617. var t2 = t * t;
  17618. var t3 = t2 * t;
  17619. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  17620. };
  17621. // Subclass Three.js curve
  17622. return THREE.Curve.create(
  17623. function ( p /* array of Vector3 */ ) {
  17624. this.points = p || [];
  17625. },
  17626. function ( t ) {
  17627. var points = this.points,
  17628. point, intPoint, weight, l;
  17629. l = points.length;
  17630. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  17631. point = ( l - 1 ) * t;
  17632. intPoint = Math.floor( point );
  17633. weight = point - intPoint;
  17634. if ( weight === 0 && intPoint === l - 1 ) {
  17635. intPoint = l - 2;
  17636. weight = 1;
  17637. }
  17638. var p0, p1, p2, p3;
  17639. if ( intPoint === 0 ) {
  17640. // extrapolate first point
  17641. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  17642. p0 = tmp;
  17643. } else {
  17644. p0 = points[ intPoint - 1 ];
  17645. }
  17646. p1 = points[ intPoint ];
  17647. p2 = points[ intPoint + 1 ];
  17648. if ( intPoint + 2 < l ) {
  17649. p3 = points[ intPoint + 2 ]
  17650. } else {
  17651. // extrapolate last point
  17652. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  17653. p3 = tmp;
  17654. }
  17655. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  17656. // init Centripetal / Chordal Catmull-Rom
  17657. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  17658. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  17659. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  17660. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  17661. // safety check for repeated points
  17662. if ( dt1 < 1e-4 ) dt1 = 1.0;
  17663. if ( dt0 < 1e-4 ) dt0 = dt1;
  17664. if ( dt2 < 1e-4 ) dt2 = dt1;
  17665. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  17666. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  17667. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  17668. } else if ( this.type === 'catmullrom' ) {
  17669. var tension = this.tension !== undefined ? this.tension : 0.5;
  17670. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  17671. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  17672. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  17673. }
  17674. var v = new THREE.Vector3(
  17675. px.calc( weight ),
  17676. py.calc( weight ),
  17677. pz.calc( weight )
  17678. );
  17679. return v;
  17680. }
  17681. );
  17682. } )();
  17683. // File:src/extras/curves/ClosedSplineCurve3.js
  17684. /**************************************************************
  17685. * Closed Spline 3D curve
  17686. **************************************************************/
  17687. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  17688. function ( points /* array of Vector3 */) {
  17689. this.points = ( points == undefined ) ? [] : points;
  17690. },
  17691. function ( t ) {
  17692. var points = this.points;
  17693. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  17694. var intPoint = Math.floor( point );
  17695. var weight = point - intPoint;
  17696. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  17697. var point0 = points[ ( intPoint - 1 ) % points.length ];
  17698. var point1 = points[ ( intPoint ) % points.length ];
  17699. var point2 = points[ ( intPoint + 1 ) % points.length ];
  17700. var point3 = points[ ( intPoint + 2 ) % points.length ];
  17701. var vector = new THREE.Vector3();
  17702. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17703. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17704. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17705. return vector;
  17706. }
  17707. );
  17708. // File:src/extras/animation/AnimationHandler.js
  17709. /**
  17710. * @author mikael emtinger / http://gomo.se/
  17711. */
  17712. THREE.AnimationHandler = {
  17713. LINEAR: 0,
  17714. CATMULLROM: 1,
  17715. CATMULLROM_FORWARD: 2,
  17716. //
  17717. add: function () { console.warn( 'THREE.AnimationHandler.add() has been deprecated.' ); },
  17718. get: function () { console.warn( 'THREE.AnimationHandler.get() has been deprecated.' ); },
  17719. remove: function () { console.warn( 'THREE.AnimationHandler.remove() has been deprecated.' ); },
  17720. //
  17721. animations: [],
  17722. init: function ( data ) {
  17723. if ( data.initialized === true ) return data;
  17724. // loop through all keys
  17725. for ( var h = 0; h < data.hierarchy.length; h ++ ) {
  17726. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17727. // remove minus times
  17728. if ( data.hierarchy[ h ].keys[ k ].time < 0 ) {
  17729. data.hierarchy[ h ].keys[ k ].time = 0;
  17730. }
  17731. // create quaternions
  17732. if ( data.hierarchy[ h ].keys[ k ].rot !== undefined &&
  17733. ! ( data.hierarchy[ h ].keys[ k ].rot instanceof THREE.Quaternion ) ) {
  17734. var quat = data.hierarchy[ h ].keys[ k ].rot;
  17735. data.hierarchy[ h ].keys[ k ].rot = new THREE.Quaternion().fromArray( quat );
  17736. }
  17737. }
  17738. // prepare morph target keys
  17739. if ( data.hierarchy[ h ].keys.length && data.hierarchy[ h ].keys[ 0 ].morphTargets !== undefined ) {
  17740. // get all used
  17741. var usedMorphTargets = {};
  17742. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17743. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17744. var morphTargetName = data.hierarchy[ h ].keys[ k ].morphTargets[ m ];
  17745. usedMorphTargets[ morphTargetName ] = - 1;
  17746. }
  17747. }
  17748. data.hierarchy[ h ].usedMorphTargets = usedMorphTargets;
  17749. // set all used on all frames
  17750. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17751. var influences = {};
  17752. for ( var morphTargetName in usedMorphTargets ) {
  17753. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17754. if ( data.hierarchy[ h ].keys[ k ].morphTargets[ m ] === morphTargetName ) {
  17755. influences[ morphTargetName ] = data.hierarchy[ h ].keys[ k ].morphTargetsInfluences[ m ];
  17756. break;
  17757. }
  17758. }
  17759. if ( m === data.hierarchy[ h ].keys[ k ].morphTargets.length ) {
  17760. influences[ morphTargetName ] = 0;
  17761. }
  17762. }
  17763. data.hierarchy[ h ].keys[ k ].morphTargetsInfluences = influences;
  17764. }
  17765. }
  17766. // remove all keys that are on the same time
  17767. for ( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17768. if ( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
  17769. data.hierarchy[ h ].keys.splice( k, 1 );
  17770. k --;
  17771. }
  17772. }
  17773. // set index
  17774. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17775. data.hierarchy[ h ].keys[ k ].index = k;
  17776. }
  17777. }
  17778. data.initialized = true;
  17779. return data;
  17780. },
  17781. parse: function ( root ) {
  17782. var parseRecurseHierarchy = function ( root, hierarchy ) {
  17783. hierarchy.push( root );
  17784. for ( var c = 0; c < root.children.length; c ++ )
  17785. parseRecurseHierarchy( root.children[ c ], hierarchy );
  17786. };
  17787. // setup hierarchy
  17788. var hierarchy = [];
  17789. if ( root instanceof THREE.SkinnedMesh ) {
  17790. for ( var b = 0; b < root.skeleton.bones.length; b ++ ) {
  17791. hierarchy.push( root.skeleton.bones[ b ] );
  17792. }
  17793. } else {
  17794. parseRecurseHierarchy( root, hierarchy );
  17795. }
  17796. return hierarchy;
  17797. },
  17798. play: function ( animation ) {
  17799. if ( this.animations.indexOf( animation ) === - 1 ) {
  17800. this.animations.push( animation );
  17801. }
  17802. },
  17803. stop: function ( animation ) {
  17804. var index = this.animations.indexOf( animation );
  17805. if ( index !== - 1 ) {
  17806. this.animations.splice( index, 1 );
  17807. }
  17808. },
  17809. update: function ( deltaTimeMS ) {
  17810. for ( var i = 0; i < this.animations.length; i ++ ) {
  17811. this.animations[ i ].resetBlendWeights( );
  17812. }
  17813. for ( var i = 0; i < this.animations.length; i ++ ) {
  17814. this.animations[ i ].update( deltaTimeMS );
  17815. }
  17816. }
  17817. };
  17818. // File:src/extras/animation/Animation.js
  17819. /**
  17820. * @author mikael emtinger / http://gomo.se/
  17821. * @author mrdoob / http://mrdoob.com/
  17822. * @author alteredq / http://alteredqualia.com/
  17823. */
  17824. THREE.Animation = function ( root, data ) {
  17825. this.root = root;
  17826. this.data = THREE.AnimationHandler.init( data );
  17827. this.hierarchy = THREE.AnimationHandler.parse( root );
  17828. this.currentTime = 0;
  17829. this.timeScale = 1;
  17830. this.isPlaying = false;
  17831. this.loop = true;
  17832. this.weight = 0;
  17833. this.interpolationType = THREE.AnimationHandler.LINEAR;
  17834. };
  17835. THREE.Animation.prototype = {
  17836. constructor: THREE.Animation,
  17837. keyTypes: [ "pos", "rot", "scl" ],
  17838. play: function ( startTime, weight ) {
  17839. this.currentTime = startTime !== undefined ? startTime : 0;
  17840. this.weight = weight !== undefined ? weight : 1;
  17841. this.isPlaying = true;
  17842. this.reset();
  17843. THREE.AnimationHandler.play( this );
  17844. },
  17845. stop: function() {
  17846. this.isPlaying = false;
  17847. THREE.AnimationHandler.stop( this );
  17848. },
  17849. reset: function () {
  17850. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17851. var object = this.hierarchy[ h ];
  17852. if ( object.animationCache === undefined ) {
  17853. object.animationCache = {
  17854. animations: {},
  17855. blending: {
  17856. positionWeight: 0.0,
  17857. quaternionWeight: 0.0,
  17858. scaleWeight: 0.0
  17859. }
  17860. };
  17861. }
  17862. var name = this.data.name;
  17863. var animations = object.animationCache.animations;
  17864. var animationCache = animations[ name ];
  17865. if ( animationCache === undefined ) {
  17866. animationCache = {
  17867. prevKey: { pos: 0, rot: 0, scl: 0 },
  17868. nextKey: { pos: 0, rot: 0, scl: 0 },
  17869. originalMatrix: object.matrix
  17870. };
  17871. animations[ name ] = animationCache;
  17872. }
  17873. // Get keys to match our current time
  17874. for ( var t = 0; t < 3; t ++ ) {
  17875. var type = this.keyTypes[ t ];
  17876. var prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  17877. var nextKey = this.getNextKeyWith( type, h, 1 );
  17878. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  17879. prevKey = nextKey;
  17880. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  17881. }
  17882. animationCache.prevKey[ type ] = prevKey;
  17883. animationCache.nextKey[ type ] = nextKey;
  17884. }
  17885. }
  17886. },
  17887. resetBlendWeights: function () {
  17888. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17889. var object = this.hierarchy[ h ];
  17890. var animationCache = object.animationCache;
  17891. if ( animationCache !== undefined ) {
  17892. var blending = animationCache.blending;
  17893. blending.positionWeight = 0.0;
  17894. blending.quaternionWeight = 0.0;
  17895. blending.scaleWeight = 0.0;
  17896. }
  17897. }
  17898. },
  17899. update: ( function() {
  17900. var points = [];
  17901. var target = new THREE.Vector3();
  17902. var newVector = new THREE.Vector3();
  17903. var newQuat = new THREE.Quaternion();
  17904. // Catmull-Rom spline
  17905. var interpolateCatmullRom = function ( points, scale ) {
  17906. var c = [], v3 = [],
  17907. point, intPoint, weight, w2, w3,
  17908. pa, pb, pc, pd;
  17909. point = ( points.length - 1 ) * scale;
  17910. intPoint = Math.floor( point );
  17911. weight = point - intPoint;
  17912. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  17913. c[ 1 ] = intPoint;
  17914. c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
  17915. c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;
  17916. pa = points[ c[ 0 ] ];
  17917. pb = points[ c[ 1 ] ];
  17918. pc = points[ c[ 2 ] ];
  17919. pd = points[ c[ 3 ] ];
  17920. w2 = weight * weight;
  17921. w3 = weight * w2;
  17922. v3[ 0 ] = interpolate( pa[ 0 ], pb[ 0 ], pc[ 0 ], pd[ 0 ], weight, w2, w3 );
  17923. v3[ 1 ] = interpolate( pa[ 1 ], pb[ 1 ], pc[ 1 ], pd[ 1 ], weight, w2, w3 );
  17924. v3[ 2 ] = interpolate( pa[ 2 ], pb[ 2 ], pc[ 2 ], pd[ 2 ], weight, w2, w3 );
  17925. return v3;
  17926. };
  17927. var interpolate = function ( p0, p1, p2, p3, t, t2, t3 ) {
  17928. var v0 = ( p2 - p0 ) * 0.5,
  17929. v1 = ( p3 - p1 ) * 0.5;
  17930. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  17931. };
  17932. return function ( delta ) {
  17933. if ( this.isPlaying === false ) return;
  17934. this.currentTime += delta * this.timeScale;
  17935. if ( this.weight === 0 )
  17936. return;
  17937. //
  17938. var duration = this.data.length;
  17939. if ( this.currentTime > duration || this.currentTime < 0 ) {
  17940. if ( this.loop ) {
  17941. this.currentTime %= duration;
  17942. if ( this.currentTime < 0 )
  17943. this.currentTime += duration;
  17944. this.reset();
  17945. } else {
  17946. this.stop();
  17947. }
  17948. }
  17949. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17950. var object = this.hierarchy[ h ];
  17951. var animationCache = object.animationCache.animations[this.data.name];
  17952. var blending = object.animationCache.blending;
  17953. // loop through pos/rot/scl
  17954. for ( var t = 0; t < 3; t ++ ) {
  17955. // get keys
  17956. var type = this.keyTypes[ t ];
  17957. var prevKey = animationCache.prevKey[ type ];
  17958. var nextKey = animationCache.nextKey[ type ];
  17959. if ( ( this.timeScale > 0 && nextKey.time <= this.currentTime ) ||
  17960. ( this.timeScale < 0 && prevKey.time >= this.currentTime ) ) {
  17961. prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  17962. nextKey = this.getNextKeyWith( type, h, 1 );
  17963. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  17964. prevKey = nextKey;
  17965. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  17966. }
  17967. animationCache.prevKey[ type ] = prevKey;
  17968. animationCache.nextKey[ type ] = nextKey;
  17969. }
  17970. var scale = ( this.currentTime - prevKey.time ) / ( nextKey.time - prevKey.time );
  17971. var prevXYZ = prevKey[ type ];
  17972. var nextXYZ = nextKey[ type ];
  17973. if ( scale < 0 ) scale = 0;
  17974. if ( scale > 1 ) scale = 1;
  17975. // interpolate
  17976. if ( type === "pos" ) {
  17977. if ( this.interpolationType === THREE.AnimationHandler.LINEAR ) {
  17978. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  17979. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  17980. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  17981. // blend
  17982. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  17983. object.position.lerp( newVector, proportionalWeight );
  17984. blending.positionWeight += this.weight;
  17985. } else if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  17986. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  17987. points[ 0 ] = this.getPrevKeyWith( "pos", h, prevKey.index - 1 )[ "pos" ];
  17988. points[ 1 ] = prevXYZ;
  17989. points[ 2 ] = nextXYZ;
  17990. points[ 3 ] = this.getNextKeyWith( "pos", h, nextKey.index + 1 )[ "pos" ];
  17991. scale = scale * 0.33 + 0.33;
  17992. var currentPoint = interpolateCatmullRom( points, scale );
  17993. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  17994. blending.positionWeight += this.weight;
  17995. // blend
  17996. var vector = object.position;
  17997. vector.x = vector.x + ( currentPoint[ 0 ] - vector.x ) * proportionalWeight;
  17998. vector.y = vector.y + ( currentPoint[ 1 ] - vector.y ) * proportionalWeight;
  17999. vector.z = vector.z + ( currentPoint[ 2 ] - vector.z ) * proportionalWeight;
  18000. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18001. var forwardPoint = interpolateCatmullRom( points, scale * 1.01 );
  18002. target.set( forwardPoint[ 0 ], forwardPoint[ 1 ], forwardPoint[ 2 ] );
  18003. target.sub( vector );
  18004. target.y = 0;
  18005. target.normalize();
  18006. var angle = Math.atan2( target.x, target.z );
  18007. object.rotation.set( 0, angle, 0 );
  18008. }
  18009. }
  18010. } else if ( type === "rot" ) {
  18011. THREE.Quaternion.slerp( prevXYZ, nextXYZ, newQuat, scale );
  18012. // Avoid paying the cost of an additional slerp if we don't have to
  18013. if ( blending.quaternionWeight === 0 ) {
  18014. object.quaternion.copy(newQuat);
  18015. blending.quaternionWeight = this.weight;
  18016. } else {
  18017. var proportionalWeight = this.weight / ( this.weight + blending.quaternionWeight );
  18018. THREE.Quaternion.slerp( object.quaternion, newQuat, object.quaternion, proportionalWeight );
  18019. blending.quaternionWeight += this.weight;
  18020. }
  18021. } else if ( type === "scl" ) {
  18022. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  18023. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  18024. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  18025. var proportionalWeight = this.weight / ( this.weight + blending.scaleWeight );
  18026. object.scale.lerp( newVector, proportionalWeight );
  18027. blending.scaleWeight += this.weight;
  18028. }
  18029. }
  18030. }
  18031. return true;
  18032. };
  18033. } )(),
  18034. getNextKeyWith: function ( type, h, key ) {
  18035. var keys = this.data.hierarchy[ h ].keys;
  18036. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18037. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18038. key = key < keys.length - 1 ? key : keys.length - 1;
  18039. } else {
  18040. key = key % keys.length;
  18041. }
  18042. for ( ; key < keys.length; key ++ ) {
  18043. if ( keys[ key ][ type ] !== undefined ) {
  18044. return keys[ key ];
  18045. }
  18046. }
  18047. return this.data.hierarchy[ h ].keys[ 0 ];
  18048. },
  18049. getPrevKeyWith: function ( type, h, key ) {
  18050. var keys = this.data.hierarchy[ h ].keys;
  18051. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18052. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18053. key = key > 0 ? key : 0;
  18054. } else {
  18055. key = key >= 0 ? key : key + keys.length;
  18056. }
  18057. for ( ; key >= 0; key -- ) {
  18058. if ( keys[ key ][ type ] !== undefined ) {
  18059. return keys[ key ];
  18060. }
  18061. }
  18062. return this.data.hierarchy[ h ].keys[ keys.length - 1 ];
  18063. }
  18064. };
  18065. // File:src/extras/animation/KeyFrameAnimation.js
  18066. /**
  18067. * @author mikael emtinger / http://gomo.se/
  18068. * @author mrdoob / http://mrdoob.com/
  18069. * @author alteredq / http://alteredqualia.com/
  18070. * @author khang duong
  18071. * @author erik kitson
  18072. */
  18073. THREE.KeyFrameAnimation = function ( data ) {
  18074. this.root = data.node;
  18075. this.data = THREE.AnimationHandler.init( data );
  18076. this.hierarchy = THREE.AnimationHandler.parse( this.root );
  18077. this.currentTime = 0;
  18078. this.timeScale = 0.001;
  18079. this.isPlaying = false;
  18080. this.isPaused = true;
  18081. this.loop = true;
  18082. // initialize to first keyframes
  18083. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18084. var keys = this.data.hierarchy[h].keys,
  18085. sids = this.data.hierarchy[h].sids,
  18086. obj = this.hierarchy[h];
  18087. if ( keys.length && sids ) {
  18088. for ( var s = 0; s < sids.length; s ++ ) {
  18089. var sid = sids[ s ],
  18090. next = this.getNextKeyWith( sid, h, 0 );
  18091. if ( next ) {
  18092. next.apply( sid );
  18093. }
  18094. }
  18095. obj.matrixAutoUpdate = false;
  18096. this.data.hierarchy[h].node.updateMatrix();
  18097. obj.matrixWorldNeedsUpdate = true;
  18098. }
  18099. }
  18100. };
  18101. THREE.KeyFrameAnimation.prototype = {
  18102. constructor: THREE.KeyFrameAnimation,
  18103. play: function ( startTime ) {
  18104. this.currentTime = startTime !== undefined ? startTime : 0;
  18105. if ( this.isPlaying === false ) {
  18106. this.isPlaying = true;
  18107. // reset key cache
  18108. var h, hl = this.hierarchy.length,
  18109. object,
  18110. node;
  18111. for ( h = 0; h < hl; h ++ ) {
  18112. object = this.hierarchy[ h ];
  18113. node = this.data.hierarchy[ h ];
  18114. if ( node.animationCache === undefined ) {
  18115. node.animationCache = {};
  18116. node.animationCache.prevKey = null;
  18117. node.animationCache.nextKey = null;
  18118. node.animationCache.originalMatrix = object.matrix;
  18119. }
  18120. var keys = this.data.hierarchy[h].keys;
  18121. if (keys.length) {
  18122. node.animationCache.prevKey = keys[ 0 ];
  18123. node.animationCache.nextKey = keys[ 1 ];
  18124. this.startTime = Math.min( keys[0].time, this.startTime );
  18125. this.endTime = Math.max( keys[keys.length - 1].time, this.endTime );
  18126. }
  18127. }
  18128. this.update( 0 );
  18129. }
  18130. this.isPaused = false;
  18131. THREE.AnimationHandler.play( this );
  18132. },
  18133. stop: function () {
  18134. this.isPlaying = false;
  18135. this.isPaused = false;
  18136. THREE.AnimationHandler.stop( this );
  18137. // reset JIT matrix and remove cache
  18138. for ( var h = 0; h < this.data.hierarchy.length; h ++ ) {
  18139. var obj = this.hierarchy[ h ];
  18140. var node = this.data.hierarchy[ h ];
  18141. if ( node.animationCache !== undefined ) {
  18142. var original = node.animationCache.originalMatrix;
  18143. original.copy( obj.matrix );
  18144. obj.matrix = original;
  18145. delete node.animationCache;
  18146. }
  18147. }
  18148. },
  18149. update: function ( delta ) {
  18150. if ( this.isPlaying === false ) return;
  18151. this.currentTime += delta * this.timeScale;
  18152. //
  18153. var duration = this.data.length;
  18154. if ( this.loop === true && this.currentTime > duration ) {
  18155. this.currentTime %= duration;
  18156. }
  18157. this.currentTime = Math.min( this.currentTime, duration );
  18158. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18159. var object = this.hierarchy[ h ];
  18160. var node = this.data.hierarchy[ h ];
  18161. var keys = node.keys,
  18162. animationCache = node.animationCache;
  18163. if ( keys.length ) {
  18164. var prevKey = animationCache.prevKey;
  18165. var nextKey = animationCache.nextKey;
  18166. if ( nextKey.time <= this.currentTime ) {
  18167. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18168. prevKey = nextKey;
  18169. nextKey = keys[ prevKey.index + 1 ];
  18170. }
  18171. animationCache.prevKey = prevKey;
  18172. animationCache.nextKey = nextKey;
  18173. }
  18174. if ( nextKey.time >= this.currentTime ) {
  18175. prevKey.interpolate( nextKey, this.currentTime );
  18176. } else {
  18177. prevKey.interpolate( nextKey, nextKey.time );
  18178. }
  18179. this.data.hierarchy[ h ].node.updateMatrix();
  18180. object.matrixWorldNeedsUpdate = true;
  18181. }
  18182. }
  18183. },
  18184. getNextKeyWith: function ( sid, h, key ) {
  18185. var keys = this.data.hierarchy[ h ].keys;
  18186. key = key % keys.length;
  18187. for ( ; key < keys.length; key ++ ) {
  18188. if ( keys[ key ].hasTarget( sid ) ) {
  18189. return keys[ key ];
  18190. }
  18191. }
  18192. return keys[ 0 ];
  18193. },
  18194. getPrevKeyWith: function ( sid, h, key ) {
  18195. var keys = this.data.hierarchy[ h ].keys;
  18196. key = key >= 0 ? key : key + keys.length;
  18197. for ( ; key >= 0; key -- ) {
  18198. if ( keys[ key ].hasTarget( sid ) ) {
  18199. return keys[ key ];
  18200. }
  18201. }
  18202. return keys[ keys.length - 1 ];
  18203. }
  18204. };
  18205. // File:src/extras/animation/MorphAnimation.js
  18206. /**
  18207. * @author mrdoob / http://mrdoob.com
  18208. * @author willy-vvu / http://willy-vvu.github.io
  18209. */
  18210. THREE.MorphAnimation = function ( mesh ) {
  18211. this.mesh = mesh;
  18212. this.frames = mesh.morphTargetInfluences.length;
  18213. this.currentTime = 0;
  18214. this.duration = 1000;
  18215. this.loop = true;
  18216. this.lastFrame = 0;
  18217. this.currentFrame = 0;
  18218. this.isPlaying = false;
  18219. };
  18220. THREE.MorphAnimation.prototype = {
  18221. constructor: THREE.MorphAnimation,
  18222. play: function () {
  18223. this.isPlaying = true;
  18224. },
  18225. pause: function () {
  18226. this.isPlaying = false;
  18227. },
  18228. update: function ( delta ) {
  18229. if ( this.isPlaying === false ) return;
  18230. this.currentTime += delta;
  18231. if ( this.loop === true && this.currentTime > this.duration ) {
  18232. this.currentTime %= this.duration;
  18233. }
  18234. this.currentTime = Math.min( this.currentTime, this.duration );
  18235. var interpolation = this.duration / this.frames;
  18236. var frame = Math.floor( this.currentTime / interpolation );
  18237. var influences = this.mesh.morphTargetInfluences;
  18238. if ( frame !== this.currentFrame ) {
  18239. influences[ this.lastFrame ] = 0;
  18240. influences[ this.currentFrame ] = 1;
  18241. influences[ frame ] = 0;
  18242. this.lastFrame = this.currentFrame;
  18243. this.currentFrame = frame;
  18244. }
  18245. influences[ frame ] = ( this.currentTime % interpolation ) / interpolation;
  18246. influences[ this.lastFrame ] = 1 - influences[ frame ];
  18247. }
  18248. };
  18249. // File:src/extras/geometries/BoxGeometry.js
  18250. /**
  18251. * @author mrdoob / http://mrdoob.com/
  18252. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  18253. */
  18254. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  18255. THREE.Geometry.call( this );
  18256. this.type = 'BoxGeometry';
  18257. this.parameters = {
  18258. width: width,
  18259. height: height,
  18260. depth: depth,
  18261. widthSegments: widthSegments,
  18262. heightSegments: heightSegments,
  18263. depthSegments: depthSegments
  18264. };
  18265. this.widthSegments = widthSegments || 1;
  18266. this.heightSegments = heightSegments || 1;
  18267. this.depthSegments = depthSegments || 1;
  18268. var scope = this;
  18269. var width_half = width / 2;
  18270. var height_half = height / 2;
  18271. var depth_half = depth / 2;
  18272. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half ); // px
  18273. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half ); // nx
  18274. buildPlane( 'x', 'z', 1, 1, width, depth, height_half ); // py
  18275. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half ); // ny
  18276. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half ); // pz
  18277. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half ); // nz
  18278. function buildPlane( u, v, udir, vdir, width, height, depth ) {
  18279. var w, ix, iy,
  18280. gridX = scope.widthSegments,
  18281. gridY = scope.heightSegments,
  18282. width_half = width / 2,
  18283. height_half = height / 2,
  18284. offset = scope.vertices.length;
  18285. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  18286. w = 'z';
  18287. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  18288. w = 'y';
  18289. gridY = scope.depthSegments;
  18290. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  18291. w = 'x';
  18292. gridX = scope.depthSegments;
  18293. }
  18294. var gridX1 = gridX + 1,
  18295. gridY1 = gridY + 1,
  18296. segment_width = width / gridX,
  18297. segment_height = height / gridY,
  18298. normal = new THREE.Vector3();
  18299. normal[ w ] = depth > 0 ? 1 : - 1;
  18300. for ( iy = 0; iy < gridY1; iy ++ ) {
  18301. for ( ix = 0; ix < gridX1; ix ++ ) {
  18302. var vector = new THREE.Vector3();
  18303. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  18304. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  18305. vector[ w ] = depth;
  18306. scope.vertices.push( vector );
  18307. }
  18308. }
  18309. for ( iy = 0; iy < gridY; iy ++ ) {
  18310. for ( ix = 0; ix < gridX; ix ++ ) {
  18311. var a = ix + gridX1 * iy;
  18312. var b = ix + gridX1 * ( iy + 1 );
  18313. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  18314. var d = ( ix + 1 ) + gridX1 * iy;
  18315. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  18316. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  18317. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  18318. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  18319. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  18320. face.normal.copy( normal );
  18321. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18322. scope.faces.push( face );
  18323. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  18324. face = new THREE.Face3( b + offset, c + offset, d + offset );
  18325. face.normal.copy( normal );
  18326. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18327. scope.faces.push( face );
  18328. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  18329. }
  18330. }
  18331. }
  18332. this.mergeVertices();
  18333. };
  18334. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18335. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  18336. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  18337. // File:src/extras/geometries/CircleGeometry.js
  18338. /**
  18339. * @author hughes
  18340. */
  18341. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18342. THREE.Geometry.call( this );
  18343. this.type = 'CircleGeometry';
  18344. this.parameters = {
  18345. radius: radius,
  18346. segments: segments,
  18347. thetaStart: thetaStart,
  18348. thetaLength: thetaLength
  18349. };
  18350. radius = radius || 50;
  18351. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18352. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18353. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18354. var i, uvs = [],
  18355. center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
  18356. this.vertices.push(center);
  18357. uvs.push( centerUV );
  18358. for ( i = 0; i <= segments; i ++ ) {
  18359. var vertex = new THREE.Vector3();
  18360. var segment = thetaStart + i / segments * thetaLength;
  18361. vertex.x = radius * Math.cos( segment );
  18362. vertex.y = radius * Math.sin( segment );
  18363. this.vertices.push( vertex );
  18364. uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, ( vertex.y / radius + 1 ) / 2 ) );
  18365. }
  18366. var n = new THREE.Vector3( 0, 0, 1 );
  18367. for ( i = 1; i <= segments; i ++ ) {
  18368. this.faces.push( new THREE.Face3( i, i + 1, 0, [ n.clone(), n.clone(), n.clone() ] ) );
  18369. this.faceVertexUvs[ 0 ].push( [ uvs[ i ].clone(), uvs[ i + 1 ].clone(), centerUV.clone() ] );
  18370. }
  18371. this.computeFaceNormals();
  18372. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18373. };
  18374. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18375. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  18376. // File:src/extras/geometries/CircleBufferGeometry.js
  18377. /**
  18378. * @author benaadams / https://twitter.com/ben_a_adams
  18379. */
  18380. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18381. THREE.BufferGeometry.call( this );
  18382. this.type = 'CircleBufferGeometry';
  18383. this.parameters = {
  18384. radius: radius,
  18385. segments: segments,
  18386. thetaStart: thetaStart,
  18387. thetaLength: thetaLength
  18388. };
  18389. radius = radius || 50;
  18390. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18391. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18392. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18393. var vertices = segments + 2;
  18394. var positions = new Float32Array( vertices * 3 );
  18395. var normals = new Float32Array( vertices * 3 );
  18396. var uvs = new Float32Array( vertices * 2 );
  18397. // center data is already zero, but need to set a few extras
  18398. normals[3] = 1.0;
  18399. uvs[0] = 0.5;
  18400. uvs[1] = 0.5;
  18401. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s++, i += 3, ii += 2 ) {
  18402. var segment = thetaStart + s / segments * thetaLength;
  18403. positions[i] = radius * Math.cos( segment );
  18404. positions[i + 1] = radius * Math.sin( segment );
  18405. normals[i + 2] = 1; // normal z
  18406. uvs[ii] = ( positions[i] / radius + 1 ) / 2;
  18407. uvs[ii + 1] = ( positions[i + 1] / radius + 1 ) / 2;
  18408. }
  18409. var indices = [];
  18410. for ( var i = 1; i <= segments; i ++ ) {
  18411. indices.push( i );
  18412. indices.push( i + 1 );
  18413. indices.push( 0 );
  18414. }
  18415. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  18416. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  18417. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  18418. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  18419. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18420. };
  18421. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18422. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  18423. // File:src/extras/geometries/CylinderGeometry.js
  18424. /**
  18425. * @author mrdoob / http://mrdoob.com/
  18426. */
  18427. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18428. THREE.Geometry.call( this );
  18429. this.type = 'CylinderGeometry';
  18430. this.parameters = {
  18431. radiusTop: radiusTop,
  18432. radiusBottom: radiusBottom,
  18433. height: height,
  18434. radialSegments: radialSegments,
  18435. heightSegments: heightSegments,
  18436. openEnded: openEnded,
  18437. thetaStart: thetaStart,
  18438. thetaLength: thetaLength
  18439. };
  18440. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  18441. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  18442. height = height !== undefined ? height : 100;
  18443. radialSegments = radialSegments || 8;
  18444. heightSegments = heightSegments || 1;
  18445. openEnded = openEnded !== undefined ? openEnded : false;
  18446. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18447. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  18448. var heightHalf = height / 2;
  18449. var x, y, vertices = [], uvs = [];
  18450. for ( y = 0; y <= heightSegments; y ++ ) {
  18451. var verticesRow = [];
  18452. var uvsRow = [];
  18453. var v = y / heightSegments;
  18454. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18455. for ( x = 0; x <= radialSegments; x ++ ) {
  18456. var u = x / radialSegments;
  18457. var vertex = new THREE.Vector3();
  18458. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  18459. vertex.y = - v * height + heightHalf;
  18460. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  18461. this.vertices.push( vertex );
  18462. verticesRow.push( this.vertices.length - 1 );
  18463. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  18464. }
  18465. vertices.push( verticesRow );
  18466. uvs.push( uvsRow );
  18467. }
  18468. var tanTheta = ( radiusBottom - radiusTop ) / height;
  18469. var na, nb;
  18470. for ( x = 0; x < radialSegments; x ++ ) {
  18471. if ( radiusTop !== 0 ) {
  18472. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  18473. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  18474. } else {
  18475. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  18476. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  18477. }
  18478. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  18479. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  18480. for ( y = 0; y < heightSegments; y ++ ) {
  18481. var v1 = vertices[ y ][ x ];
  18482. var v2 = vertices[ y + 1 ][ x ];
  18483. var v3 = vertices[ y + 1 ][ x + 1 ];
  18484. var v4 = vertices[ y ][ x + 1 ];
  18485. var n1 = na.clone();
  18486. var n2 = na.clone();
  18487. var n3 = nb.clone();
  18488. var n4 = nb.clone();
  18489. var uv1 = uvs[ y ][ x ].clone();
  18490. var uv2 = uvs[ y + 1 ][ x ].clone();
  18491. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  18492. var uv4 = uvs[ y ][ x + 1 ].clone();
  18493. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  18494. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  18495. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  18496. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  18497. }
  18498. }
  18499. // top cap
  18500. if ( openEnded === false && radiusTop > 0 ) {
  18501. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  18502. for ( x = 0; x < radialSegments; x ++ ) {
  18503. var v1 = vertices[ 0 ][ x ];
  18504. var v2 = vertices[ 0 ][ x + 1 ];
  18505. var v3 = this.vertices.length - 1;
  18506. var n1 = new THREE.Vector3( 0, 1, 0 );
  18507. var n2 = new THREE.Vector3( 0, 1, 0 );
  18508. var n3 = new THREE.Vector3( 0, 1, 0 );
  18509. var uv1 = uvs[ 0 ][ x ].clone();
  18510. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  18511. var uv3 = new THREE.Vector2( uv2.x, 0 );
  18512. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18513. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18514. }
  18515. }
  18516. // bottom cap
  18517. if ( openEnded === false && radiusBottom > 0 ) {
  18518. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  18519. for ( x = 0; x < radialSegments; x ++ ) {
  18520. var v1 = vertices[ heightSegments ][ x + 1 ];
  18521. var v2 = vertices[ heightSegments ][ x ];
  18522. var v3 = this.vertices.length - 1;
  18523. var n1 = new THREE.Vector3( 0, - 1, 0 );
  18524. var n2 = new THREE.Vector3( 0, - 1, 0 );
  18525. var n3 = new THREE.Vector3( 0, - 1, 0 );
  18526. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  18527. var uv2 = uvs[ heightSegments ][ x ].clone();
  18528. var uv3 = new THREE.Vector2( uv2.x, 1 );
  18529. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18530. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18531. }
  18532. }
  18533. this.computeFaceNormals();
  18534. };
  18535. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18536. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  18537. // File:src/extras/geometries/EdgesGeometry.js
  18538. /**
  18539. * @author WestLangley / http://github.com/WestLangley
  18540. */
  18541. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  18542. THREE.BufferGeometry.call( this );
  18543. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18544. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  18545. var edge = [ 0, 0 ], hash = {};
  18546. var sortFunction = function ( a, b ) { return a - b; };
  18547. var keys = [ 'a', 'b', 'c' ];
  18548. var geometry2;
  18549. if ( geometry instanceof THREE.BufferGeometry ) {
  18550. geometry2 = new THREE.Geometry();
  18551. geometry2.fromBufferGeometry( geometry );
  18552. } else {
  18553. geometry2 = geometry.clone();
  18554. }
  18555. geometry2.mergeVertices();
  18556. geometry2.computeFaceNormals();
  18557. var vertices = geometry2.vertices;
  18558. var faces = geometry2.faces;
  18559. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18560. var face = faces[ i ];
  18561. for ( var j = 0; j < 3; j ++ ) {
  18562. edge[ 0 ] = face[ keys[ j ] ];
  18563. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  18564. edge.sort( sortFunction );
  18565. var key = edge.toString();
  18566. if ( hash[ key ] === undefined ) {
  18567. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  18568. } else {
  18569. hash[ key ].face2 = i;
  18570. }
  18571. }
  18572. }
  18573. var coords = [];
  18574. for ( var key in hash ) {
  18575. var h = hash[ key ];
  18576. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  18577. var vertex = vertices[ h.vert1 ];
  18578. coords.push( vertex.x );
  18579. coords.push( vertex.y );
  18580. coords.push( vertex.z );
  18581. vertex = vertices[ h.vert2 ];
  18582. coords.push( vertex.x );
  18583. coords.push( vertex.y );
  18584. coords.push( vertex.z );
  18585. }
  18586. }
  18587. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  18588. };
  18589. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18590. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  18591. // File:src/extras/geometries/ExtrudeGeometry.js
  18592. /**
  18593. * @author zz85 / http://www.lab4games.net/zz85/blog
  18594. *
  18595. * Creates extruded geometry from a path shape.
  18596. *
  18597. * parameters = {
  18598. *
  18599. * curveSegments: <int>, // number of points on the curves
  18600. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18601. * amount: <int>, // Depth to extrude the shape
  18602. *
  18603. * bevelEnabled: <bool>, // turn on bevel
  18604. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18605. * bevelSize: <float>, // how far from shape outline is bevel
  18606. * bevelSegments: <int>, // number of bevel layers
  18607. *
  18608. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  18609. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  18610. *
  18611. * uvGenerator: <Object> // object that provides UV generator functions
  18612. *
  18613. * }
  18614. **/
  18615. THREE.ExtrudeGeometry = function ( shapes, options ) {
  18616. if ( typeof( shapes ) === "undefined" ) {
  18617. shapes = [];
  18618. return;
  18619. }
  18620. THREE.Geometry.call( this );
  18621. this.type = 'ExtrudeGeometry';
  18622. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18623. this.addShapeList( shapes, options );
  18624. this.computeFaceNormals();
  18625. // can't really use automatic vertex normals
  18626. // as then front and back sides get smoothed too
  18627. // should do separate smoothing just for sides
  18628. //this.computeVertexNormals();
  18629. //console.log( "took", ( Date.now() - startTime ) );
  18630. };
  18631. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18632. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  18633. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  18634. var sl = shapes.length;
  18635. for ( var s = 0; s < sl; s ++ ) {
  18636. var shape = shapes[ s ];
  18637. this.addShape( shape, options );
  18638. }
  18639. };
  18640. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  18641. var amount = options.amount !== undefined ? options.amount : 100;
  18642. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  18643. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  18644. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18645. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  18646. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18647. var steps = options.steps !== undefined ? options.steps : 1;
  18648. var extrudePath = options.extrudePath;
  18649. var extrudePts, extrudeByPath = false;
  18650. // Use default WorldUVGenerator if no UV generators are specified.
  18651. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  18652. var splineTube, binormal, normal, position2;
  18653. if ( extrudePath ) {
  18654. extrudePts = extrudePath.getSpacedPoints( steps );
  18655. extrudeByPath = true;
  18656. bevelEnabled = false; // bevels not supported for path extrusion
  18657. // SETUP TNB variables
  18658. // Reuse TNB from TubeGeomtry for now.
  18659. // TODO1 - have a .isClosed in spline?
  18660. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames(extrudePath, steps, false);
  18661. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18662. binormal = new THREE.Vector3();
  18663. normal = new THREE.Vector3();
  18664. position2 = new THREE.Vector3();
  18665. }
  18666. // Safeguards if bevels are not enabled
  18667. if ( ! bevelEnabled ) {
  18668. bevelSegments = 0;
  18669. bevelThickness = 0;
  18670. bevelSize = 0;
  18671. }
  18672. // Variables initialization
  18673. var ahole, h, hl; // looping of holes
  18674. var scope = this;
  18675. var shapesOffset = this.vertices.length;
  18676. var shapePoints = shape.extractPoints( curveSegments );
  18677. var vertices = shapePoints.shape;
  18678. var holes = shapePoints.holes;
  18679. var reverse = ! THREE.Shape.Utils.isClockWise( vertices ) ;
  18680. if ( reverse ) {
  18681. vertices = vertices.reverse();
  18682. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18683. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18684. ahole = holes[ h ];
  18685. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  18686. holes[ h ] = ahole.reverse();
  18687. }
  18688. }
  18689. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  18690. }
  18691. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  18692. /* Vertices */
  18693. var contour = vertices; // vertices has all points but contour has only points of circumference
  18694. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18695. ahole = holes[ h ];
  18696. vertices = vertices.concat( ahole );
  18697. }
  18698. function scalePt2 ( pt, vec, size ) {
  18699. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  18700. return vec.clone().multiplyScalar( size ).add( pt );
  18701. }
  18702. var b, bs, t, z,
  18703. vert, vlen = vertices.length,
  18704. face, flen = faces.length;
  18705. // Find directions for point movement
  18706. function getBevelVec( inPt, inPrev, inNext ) {
  18707. var EPSILON = 0.0000000001;
  18708. // computes for inPt the corresponding point inPt' on a new contour
  18709. // shifted by 1 unit (length of normalized vector) to the left
  18710. // if we walk along contour clockwise, this new contour is outside the old one
  18711. //
  18712. // inPt' is the intersection of the two lines parallel to the two
  18713. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18714. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  18715. // good reading for geometry algorithms (here: line-line intersection)
  18716. // http://geomalgorithms.com/a05-_intersect-1.html
  18717. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  18718. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  18719. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18720. // check for collinear edges
  18721. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18722. if ( Math.abs( collinear0 ) > EPSILON ) { // not collinear
  18723. // length of vectors for normalizing
  18724. var v_prev_len = Math.sqrt( v_prev_lensq );
  18725. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18726. // shift adjacent points by unit vectors to the left
  18727. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18728. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18729. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18730. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18731. // scaling factor for v_prev to intersection point
  18732. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18733. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18734. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18735. // vector from inPt to intersection point
  18736. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18737. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18738. // Don't normalize!, otherwise sharp corners become ugly
  18739. // but prevent crazy spikes
  18740. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18741. if ( v_trans_lensq <= 2 ) {
  18742. return new THREE.Vector2( v_trans_x, v_trans_y );
  18743. } else {
  18744. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18745. }
  18746. } else { // handle special case of collinear edges
  18747. var direction_eq = false; // assumes: opposite
  18748. if ( v_prev_x > EPSILON ) {
  18749. if ( v_next_x > EPSILON ) { direction_eq = true; }
  18750. } else {
  18751. if ( v_prev_x < - EPSILON ) {
  18752. if ( v_next_x < - EPSILON ) { direction_eq = true; }
  18753. } else {
  18754. if ( Math.sign(v_prev_y) === Math.sign(v_next_y) ) { direction_eq = true; }
  18755. }
  18756. }
  18757. if ( direction_eq ) {
  18758. // console.log("Warning: lines are a straight sequence");
  18759. v_trans_x = - v_prev_y;
  18760. v_trans_y = v_prev_x;
  18761. shrink_by = Math.sqrt( v_prev_lensq );
  18762. } else {
  18763. // console.log("Warning: lines are a straight spike");
  18764. v_trans_x = v_prev_x;
  18765. v_trans_y = v_prev_y;
  18766. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18767. }
  18768. }
  18769. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18770. }
  18771. var contourMovements = [];
  18772. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18773. if ( j === il ) j = 0;
  18774. if ( k === il ) k = 0;
  18775. // (j)---(i)---(k)
  18776. // console.log('i,j,k', i, j , k)
  18777. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18778. }
  18779. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  18780. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18781. ahole = holes[ h ];
  18782. oneHoleMovements = [];
  18783. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18784. if ( j === il ) j = 0;
  18785. if ( k === il ) k = 0;
  18786. // (j)---(i)---(k)
  18787. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  18788. }
  18789. holesMovements.push( oneHoleMovements );
  18790. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18791. }
  18792. // Loop bevelSegments, 1 for the front, 1 for the back
  18793. for ( b = 0; b < bevelSegments; b ++ ) {
  18794. //for ( b = bevelSegments; b > 0; b -- ) {
  18795. t = b / bevelSegments;
  18796. z = bevelThickness * ( 1 - t );
  18797. //z = bevelThickness * t;
  18798. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ) ; // curved
  18799. //bs = bevelSize * t ; // linear
  18800. // contract shape
  18801. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18802. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18803. v( vert.x, vert.y, - z );
  18804. }
  18805. // expand holes
  18806. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18807. ahole = holes[ h ];
  18808. oneHoleMovements = holesMovements[ h ];
  18809. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18810. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18811. v( vert.x, vert.y, - z );
  18812. }
  18813. }
  18814. }
  18815. bs = bevelSize;
  18816. // Back facing vertices
  18817. for ( i = 0; i < vlen; i ++ ) {
  18818. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18819. if ( ! extrudeByPath ) {
  18820. v( vert.x, vert.y, 0 );
  18821. } else {
  18822. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18823. normal.copy( splineTube.normals[0] ).multiplyScalar(vert.x);
  18824. binormal.copy( splineTube.binormals[0] ).multiplyScalar(vert.y);
  18825. position2.copy( extrudePts[0] ).add(normal).add(binormal);
  18826. v( position2.x, position2.y, position2.z );
  18827. }
  18828. }
  18829. // Add stepped vertices...
  18830. // Including front facing vertices
  18831. var s;
  18832. for ( s = 1; s <= steps; s ++ ) {
  18833. for ( i = 0; i < vlen; i ++ ) {
  18834. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18835. if ( ! extrudeByPath ) {
  18836. v( vert.x, vert.y, amount / steps * s );
  18837. } else {
  18838. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18839. normal.copy( splineTube.normals[s] ).multiplyScalar( vert.x );
  18840. binormal.copy( splineTube.binormals[s] ).multiplyScalar( vert.y );
  18841. position2.copy( extrudePts[s] ).add( normal ).add( binormal );
  18842. v( position2.x, position2.y, position2.z );
  18843. }
  18844. }
  18845. }
  18846. // Add bevel segments planes
  18847. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18848. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  18849. t = b / bevelSegments;
  18850. z = bevelThickness * ( 1 - t );
  18851. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  18852. bs = bevelSize * Math.sin ( t * Math.PI / 2 ) ;
  18853. // contract shape
  18854. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18855. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18856. v( vert.x, vert.y, amount + z );
  18857. }
  18858. // expand holes
  18859. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18860. ahole = holes[ h ];
  18861. oneHoleMovements = holesMovements[ h ];
  18862. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18863. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18864. if ( ! extrudeByPath ) {
  18865. v( vert.x, vert.y, amount + z );
  18866. } else {
  18867. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18868. }
  18869. }
  18870. }
  18871. }
  18872. /* Faces */
  18873. // Top and bottom faces
  18874. buildLidFaces();
  18875. // Sides faces
  18876. buildSideFaces();
  18877. ///// Internal functions
  18878. function buildLidFaces() {
  18879. if ( bevelEnabled ) {
  18880. var layer = 0 ; // steps + 1
  18881. var offset = vlen * layer;
  18882. // Bottom faces
  18883. for ( i = 0; i < flen; i ++ ) {
  18884. face = faces[ i ];
  18885. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18886. }
  18887. layer = steps + bevelSegments * 2;
  18888. offset = vlen * layer;
  18889. // Top faces
  18890. for ( i = 0; i < flen; i ++ ) {
  18891. face = faces[ i ];
  18892. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18893. }
  18894. } else {
  18895. // Bottom faces
  18896. for ( i = 0; i < flen; i ++ ) {
  18897. face = faces[ i ];
  18898. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18899. }
  18900. // Top faces
  18901. for ( i = 0; i < flen; i ++ ) {
  18902. face = faces[ i ];
  18903. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18904. }
  18905. }
  18906. }
  18907. // Create faces for the z-sides of the shape
  18908. function buildSideFaces() {
  18909. var layeroffset = 0;
  18910. sidewalls( contour, layeroffset );
  18911. layeroffset += contour.length;
  18912. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18913. ahole = holes[ h ];
  18914. sidewalls( ahole, layeroffset );
  18915. //, true
  18916. layeroffset += ahole.length;
  18917. }
  18918. }
  18919. function sidewalls( contour, layeroffset ) {
  18920. var j, k;
  18921. i = contour.length;
  18922. while ( -- i >= 0 ) {
  18923. j = i;
  18924. k = i - 1;
  18925. if ( k < 0 ) k = contour.length - 1;
  18926. //console.log('b', i,j, i-1, k,vertices.length);
  18927. var s = 0, sl = steps + bevelSegments * 2;
  18928. for ( s = 0; s < sl; s ++ ) {
  18929. var slen1 = vlen * s;
  18930. var slen2 = vlen * ( s + 1 );
  18931. var a = layeroffset + j + slen1,
  18932. b = layeroffset + k + slen1,
  18933. c = layeroffset + k + slen2,
  18934. d = layeroffset + j + slen2;
  18935. f4( a, b, c, d, contour, s, sl, j, k );
  18936. }
  18937. }
  18938. }
  18939. function v( x, y, z ) {
  18940. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  18941. }
  18942. function f3( a, b, c ) {
  18943. a += shapesOffset;
  18944. b += shapesOffset;
  18945. c += shapesOffset;
  18946. scope.faces.push( new THREE.Face3( a, b, c ) );
  18947. var uvs = uvgen.generateTopUV( scope, a, b, c );
  18948. scope.faceVertexUvs[ 0 ].push( uvs );
  18949. }
  18950. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  18951. a += shapesOffset;
  18952. b += shapesOffset;
  18953. c += shapesOffset;
  18954. d += shapesOffset;
  18955. scope.faces.push( new THREE.Face3( a, b, d ) );
  18956. scope.faces.push( new THREE.Face3( b, c, d ) );
  18957. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  18958. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  18959. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  18960. }
  18961. };
  18962. THREE.ExtrudeGeometry.WorldUVGenerator = {
  18963. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  18964. var vertices = geometry.vertices;
  18965. var a = vertices[ indexA ];
  18966. var b = vertices[ indexB ];
  18967. var c = vertices[ indexC ];
  18968. return [
  18969. new THREE.Vector2( a.x, a.y ),
  18970. new THREE.Vector2( b.x, b.y ),
  18971. new THREE.Vector2( c.x, c.y )
  18972. ];
  18973. },
  18974. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  18975. var vertices = geometry.vertices;
  18976. var a = vertices[ indexA ];
  18977. var b = vertices[ indexB ];
  18978. var c = vertices[ indexC ];
  18979. var d = vertices[ indexD ];
  18980. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  18981. return [
  18982. new THREE.Vector2( a.x, 1 - a.z ),
  18983. new THREE.Vector2( b.x, 1 - b.z ),
  18984. new THREE.Vector2( c.x, 1 - c.z ),
  18985. new THREE.Vector2( d.x, 1 - d.z )
  18986. ];
  18987. } else {
  18988. return [
  18989. new THREE.Vector2( a.y, 1 - a.z ),
  18990. new THREE.Vector2( b.y, 1 - b.z ),
  18991. new THREE.Vector2( c.y, 1 - c.z ),
  18992. new THREE.Vector2( d.y, 1 - d.z )
  18993. ];
  18994. }
  18995. }
  18996. };
  18997. // File:src/extras/geometries/ShapeGeometry.js
  18998. /**
  18999. * @author jonobr1 / http://jonobr1.com
  19000. *
  19001. * Creates a one-sided polygonal geometry from a path shape. Similar to
  19002. * ExtrudeGeometry.
  19003. *
  19004. * parameters = {
  19005. *
  19006. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  19007. *
  19008. * material: <int> // material index for front and back faces
  19009. * uvGenerator: <Object> // object that provides UV generator functions
  19010. *
  19011. * }
  19012. **/
  19013. THREE.ShapeGeometry = function ( shapes, options ) {
  19014. THREE.Geometry.call( this );
  19015. this.type = 'ShapeGeometry';
  19016. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  19017. this.addShapeList( shapes, options );
  19018. this.computeFaceNormals();
  19019. };
  19020. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19021. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  19022. /**
  19023. * Add an array of shapes to THREE.ShapeGeometry.
  19024. */
  19025. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19026. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19027. this.addShape( shapes[ i ], options );
  19028. }
  19029. return this;
  19030. };
  19031. /**
  19032. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  19033. */
  19034. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  19035. if ( options === undefined ) options = {};
  19036. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19037. var material = options.material;
  19038. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  19039. //
  19040. var i, l, hole;
  19041. var shapesOffset = this.vertices.length;
  19042. var shapePoints = shape.extractPoints( curveSegments );
  19043. var vertices = shapePoints.shape;
  19044. var holes = shapePoints.holes;
  19045. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19046. if ( reverse ) {
  19047. vertices = vertices.reverse();
  19048. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  19049. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19050. hole = holes[ i ];
  19051. if ( THREE.Shape.Utils.isClockWise( hole ) ) {
  19052. holes[ i ] = hole.reverse();
  19053. }
  19054. }
  19055. reverse = false;
  19056. }
  19057. var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
  19058. // Vertices
  19059. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19060. hole = holes[ i ];
  19061. vertices = vertices.concat( hole );
  19062. }
  19063. //
  19064. var vert, vlen = vertices.length;
  19065. var face, flen = faces.length;
  19066. for ( i = 0; i < vlen; i ++ ) {
  19067. vert = vertices[ i ];
  19068. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  19069. }
  19070. for ( i = 0; i < flen; i ++ ) {
  19071. face = faces[ i ];
  19072. var a = face[ 0 ] + shapesOffset;
  19073. var b = face[ 1 ] + shapesOffset;
  19074. var c = face[ 2 ] + shapesOffset;
  19075. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  19076. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  19077. }
  19078. };
  19079. // File:src/extras/geometries/LatheGeometry.js
  19080. /**
  19081. * @author astrodud / http://astrodud.isgreat.org/
  19082. * @author zz85 / https://github.com/zz85
  19083. * @author bhouston / http://exocortex.com
  19084. */
  19085. // points - to create a closed torus, one must use a set of points
  19086. // like so: [ a, b, c, d, a ], see first is the same as last.
  19087. // segments - the number of circumference segments to create
  19088. // phiStart - the starting radian
  19089. // phiLength - the radian (0 to 2*PI) range of the lathed section
  19090. // 2*pi is a closed lathe, less than 2PI is a portion.
  19091. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  19092. THREE.Geometry.call( this );
  19093. this.type = 'LatheGeometry';
  19094. this.parameters = {
  19095. points: points,
  19096. segments: segments,
  19097. phiStart: phiStart,
  19098. phiLength: phiLength
  19099. };
  19100. segments = segments || 12;
  19101. phiStart = phiStart || 0;
  19102. phiLength = phiLength || 2 * Math.PI;
  19103. var inversePointLength = 1.0 / ( points.length - 1 );
  19104. var inverseSegments = 1.0 / segments;
  19105. for ( var i = 0, il = segments; i <= il; i ++ ) {
  19106. var phi = phiStart + i * inverseSegments * phiLength;
  19107. var c = Math.cos( phi ),
  19108. s = Math.sin( phi );
  19109. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  19110. var pt = points[ j ];
  19111. var vertex = new THREE.Vector3();
  19112. vertex.x = c * pt.x - s * pt.y;
  19113. vertex.y = s * pt.x + c * pt.y;
  19114. vertex.z = pt.z;
  19115. this.vertices.push( vertex );
  19116. }
  19117. }
  19118. var np = points.length;
  19119. for ( var i = 0, il = segments; i < il; i ++ ) {
  19120. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  19121. var base = j + np * i;
  19122. var a = base;
  19123. var b = base + np;
  19124. var c = base + 1 + np;
  19125. var d = base + 1;
  19126. var u0 = i * inverseSegments;
  19127. var v0 = j * inversePointLength;
  19128. var u1 = u0 + inverseSegments;
  19129. var v1 = v0 + inversePointLength;
  19130. this.faces.push( new THREE.Face3( a, b, d ) );
  19131. this.faceVertexUvs[ 0 ].push( [
  19132. new THREE.Vector2( u0, v0 ),
  19133. new THREE.Vector2( u1, v0 ),
  19134. new THREE.Vector2( u0, v1 )
  19135. ] );
  19136. this.faces.push( new THREE.Face3( b, c, d ) );
  19137. this.faceVertexUvs[ 0 ].push( [
  19138. new THREE.Vector2( u1, v0 ),
  19139. new THREE.Vector2( u1, v1 ),
  19140. new THREE.Vector2( u0, v1 )
  19141. ] );
  19142. }
  19143. }
  19144. this.mergeVertices();
  19145. this.computeFaceNormals();
  19146. this.computeVertexNormals();
  19147. };
  19148. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19149. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  19150. // File:src/extras/geometries/PlaneGeometry.js
  19151. /**
  19152. * @author mrdoob / http://mrdoob.com/
  19153. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19154. */
  19155. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  19156. THREE.Geometry.call( this );
  19157. this.type = 'PlaneGeometry';
  19158. this.parameters = {
  19159. width: width,
  19160. height: height,
  19161. widthSegments: widthSegments,
  19162. heightSegments: heightSegments
  19163. };
  19164. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  19165. };
  19166. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19167. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  19168. // File:src/extras/geometries/PlaneBufferGeometry.js
  19169. /**
  19170. * @author mrdoob / http://mrdoob.com/
  19171. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19172. */
  19173. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  19174. THREE.BufferGeometry.call( this );
  19175. this.type = 'PlaneBufferGeometry';
  19176. this.parameters = {
  19177. width: width,
  19178. height: height,
  19179. widthSegments: widthSegments,
  19180. heightSegments: heightSegments
  19181. };
  19182. var width_half = width / 2;
  19183. var height_half = height / 2;
  19184. var gridX = Math.floor( widthSegments ) || 1;
  19185. var gridY = Math.floor( heightSegments ) || 1;
  19186. var gridX1 = gridX + 1;
  19187. var gridY1 = gridY + 1;
  19188. var segment_width = width / gridX;
  19189. var segment_height = height / gridY;
  19190. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  19191. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  19192. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  19193. var offset = 0;
  19194. var offset2 = 0;
  19195. for ( var iy = 0; iy < gridY1; iy ++ ) {
  19196. var y = iy * segment_height - height_half;
  19197. for ( var ix = 0; ix < gridX1; ix ++ ) {
  19198. var x = ix * segment_width - width_half;
  19199. vertices[ offset ] = x;
  19200. vertices[ offset + 1 ] = - y;
  19201. normals[ offset + 2 ] = 1;
  19202. uvs[ offset2 ] = ix / gridX;
  19203. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  19204. offset += 3;
  19205. offset2 += 2;
  19206. }
  19207. }
  19208. offset = 0;
  19209. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  19210. for ( var iy = 0; iy < gridY; iy ++ ) {
  19211. for ( var ix = 0; ix < gridX; ix ++ ) {
  19212. var a = ix + gridX1 * iy;
  19213. var b = ix + gridX1 * ( iy + 1 );
  19214. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  19215. var d = ( ix + 1 ) + gridX1 * iy;
  19216. indices[ offset ] = a;
  19217. indices[ offset + 1 ] = b;
  19218. indices[ offset + 2 ] = d;
  19219. indices[ offset + 3 ] = b;
  19220. indices[ offset + 4 ] = c;
  19221. indices[ offset + 5 ] = d;
  19222. offset += 6;
  19223. }
  19224. }
  19225. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  19226. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  19227. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  19228. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  19229. };
  19230. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19231. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  19232. // File:src/extras/geometries/RingGeometry.js
  19233. /**
  19234. * @author Kaleb Murphy
  19235. */
  19236. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19237. THREE.Geometry.call( this );
  19238. this.type = 'RingGeometry';
  19239. this.parameters = {
  19240. innerRadius: innerRadius,
  19241. outerRadius: outerRadius,
  19242. thetaSegments: thetaSegments,
  19243. phiSegments: phiSegments,
  19244. thetaStart: thetaStart,
  19245. thetaLength: thetaLength
  19246. };
  19247. innerRadius = innerRadius || 0;
  19248. outerRadius = outerRadius || 50;
  19249. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19250. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19251. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  19252. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  19253. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19254. for ( i = 0; i < phiSegments + 1; i ++ ) { // concentric circles inside ring
  19255. for ( o = 0; o < thetaSegments + 1; o ++ ) { // number of segments per circle
  19256. var vertex = new THREE.Vector3();
  19257. var segment = thetaStart + o / thetaSegments * thetaLength;
  19258. vertex.x = radius * Math.cos( segment );
  19259. vertex.y = radius * Math.sin( segment );
  19260. this.vertices.push( vertex );
  19261. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  19262. }
  19263. radius += radiusStep;
  19264. }
  19265. var n = new THREE.Vector3( 0, 0, 1 );
  19266. for ( i = 0; i < phiSegments; i ++ ) { // concentric circles inside ring
  19267. var thetaSegment = i * (thetaSegments + 1);
  19268. for ( o = 0; o < thetaSegments ; o ++ ) { // number of segments per circle
  19269. var segment = o + thetaSegment;
  19270. var v1 = segment;
  19271. var v2 = segment + thetaSegments + 1;
  19272. var v3 = segment + thetaSegments + 2;
  19273. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19274. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ]);
  19275. v1 = segment;
  19276. v2 = segment + thetaSegments + 2;
  19277. v3 = segment + 1;
  19278. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19279. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ]);
  19280. }
  19281. }
  19282. this.computeFaceNormals();
  19283. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19284. };
  19285. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19286. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  19287. // File:src/extras/geometries/SphereGeometry.js
  19288. /**
  19289. * @author mrdoob / http://mrdoob.com/
  19290. */
  19291. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19292. console.log( 'THREE.SphereGeometry: Consider using THREE.SphereBufferGeometry for lower memory footprint.' );
  19293. THREE.Geometry.call( this );
  19294. this.type = 'SphereGeometry';
  19295. this.parameters = {
  19296. radius: radius,
  19297. widthSegments: widthSegments,
  19298. heightSegments: heightSegments,
  19299. phiStart: phiStart,
  19300. phiLength: phiLength,
  19301. thetaStart: thetaStart,
  19302. thetaLength: thetaLength
  19303. };
  19304. radius = radius || 50;
  19305. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19306. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19307. phiStart = phiStart !== undefined ? phiStart : 0;
  19308. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19309. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19310. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19311. var x, y, vertices = [], uvs = [];
  19312. for ( y = 0; y <= heightSegments; y ++ ) {
  19313. var verticesRow = [];
  19314. var uvsRow = [];
  19315. for ( x = 0; x <= widthSegments; x ++ ) {
  19316. var u = x / widthSegments;
  19317. var v = y / heightSegments;
  19318. var vertex = new THREE.Vector3();
  19319. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19320. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  19321. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19322. this.vertices.push( vertex );
  19323. verticesRow.push( this.vertices.length - 1 );
  19324. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  19325. }
  19326. vertices.push( verticesRow );
  19327. uvs.push( uvsRow );
  19328. }
  19329. for ( y = 0; y < heightSegments; y ++ ) {
  19330. for ( x = 0; x < widthSegments; x ++ ) {
  19331. var v1 = vertices[ y ][ x + 1 ];
  19332. var v2 = vertices[ y ][ x ];
  19333. var v3 = vertices[ y + 1 ][ x ];
  19334. var v4 = vertices[ y + 1 ][ x + 1 ];
  19335. var n1 = this.vertices[ v1 ].clone().normalize();
  19336. var n2 = this.vertices[ v2 ].clone().normalize();
  19337. var n3 = this.vertices[ v3 ].clone().normalize();
  19338. var n4 = this.vertices[ v4 ].clone().normalize();
  19339. var uv1 = uvs[ y ][ x + 1 ].clone();
  19340. var uv2 = uvs[ y ][ x ].clone();
  19341. var uv3 = uvs[ y + 1 ][ x ].clone();
  19342. var uv4 = uvs[ y + 1 ][ x + 1 ].clone();
  19343. if ( Math.abs( this.vertices[ v1 ].y ) === radius ) {
  19344. uv1.x = ( uv1.x + uv2.x ) / 2;
  19345. this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
  19346. this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
  19347. } else if ( Math.abs( this.vertices[ v3 ].y ) === radius ) {
  19348. uv3.x = ( uv3.x + uv4.x ) / 2;
  19349. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  19350. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19351. } else {
  19352. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  19353. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  19354. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  19355. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  19356. }
  19357. }
  19358. }
  19359. this.computeFaceNormals();
  19360. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19361. };
  19362. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19363. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  19364. // File:src/extras/geometries/SphereBufferGeometry.js
  19365. /**
  19366. * @author benaadams / https://twitter.com/ben_a_adams
  19367. * based on THREE.SphereGeometry
  19368. */
  19369. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19370. THREE.BufferGeometry.call( this );
  19371. this.type = 'SphereBufferGeometry';
  19372. this.parameters = {
  19373. radius: radius,
  19374. widthSegments: widthSegments,
  19375. heightSegments: heightSegments,
  19376. phiStart: phiStart,
  19377. phiLength: phiLength,
  19378. thetaStart: thetaStart,
  19379. thetaLength: thetaLength
  19380. };
  19381. radius = radius || 50;
  19382. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19383. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19384. phiStart = phiStart !== undefined ? phiStart : 0;
  19385. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19386. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19387. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19388. var thetaEnd = thetaStart + thetaLength;
  19389. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  19390. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19391. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19392. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  19393. var index = 0, vertices = [], normal = new THREE.Vector3();
  19394. for ( var y = 0; y <= heightSegments; y ++ ) {
  19395. var verticesRow = [];
  19396. var v = y / heightSegments;
  19397. for ( var x = 0; x <= widthSegments; x ++ ) {
  19398. var u = x / widthSegments;
  19399. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19400. var py = radius * Math.cos( thetaStart + v * thetaLength );
  19401. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19402. normal.set( px, py, pz ).normalize();
  19403. positions.setXYZ( index, px, py, pz );
  19404. normals.setXYZ( index, normal.x, normal.y, normal.z );
  19405. uvs.setXY( index, u, 1 - v );
  19406. verticesRow.push( index );
  19407. index ++;
  19408. }
  19409. vertices.push( verticesRow );
  19410. }
  19411. var indices = [];
  19412. for ( var y = 0; y < heightSegments; y ++ ) {
  19413. for ( var x = 0; x < widthSegments; x ++ ) {
  19414. var v1 = vertices[ y ][ x + 1 ];
  19415. var v2 = vertices[ y ][ x ];
  19416. var v3 = vertices[ y + 1 ][ x ];
  19417. var v4 = vertices[ y + 1 ][ x + 1 ];
  19418. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  19419. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  19420. }
  19421. }
  19422. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  19423. this.addAttribute( 'position', positions );
  19424. this.addAttribute( 'normal', normals );
  19425. this.addAttribute( 'uv', uvs );
  19426. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19427. };
  19428. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19429. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  19430. // File:src/extras/geometries/TextGeometry.js
  19431. /**
  19432. * @author zz85 / http://www.lab4games.net/zz85/blog
  19433. * @author alteredq / http://alteredqualia.com/
  19434. *
  19435. * For creating 3D text geometry in three.js
  19436. *
  19437. * Text = 3D Text
  19438. *
  19439. * parameters = {
  19440. * size: <float>, // size of the text
  19441. * height: <float>, // thickness to extrude text
  19442. * curveSegments: <int>, // number of points on the curves
  19443. *
  19444. * font: <string>, // font name
  19445. * weight: <string>, // font weight (normal, bold)
  19446. * style: <string>, // font style (normal, italics)
  19447. *
  19448. * bevelEnabled: <bool>, // turn on bevel
  19449. * bevelThickness: <float>, // how deep into text bevel goes
  19450. * bevelSize: <float>, // how far from text outline is bevel
  19451. * }
  19452. *
  19453. */
  19454. /* Usage Examples
  19455. // TextGeometry wrapper
  19456. var text3d = new TextGeometry( text, options );
  19457. // Complete manner
  19458. var textShapes = THREE.FontUtils.generateShapes( text, options );
  19459. var text3d = new ExtrudeGeometry( textShapes, options );
  19460. */
  19461. THREE.TextGeometry = function ( text, parameters ) {
  19462. parameters = parameters || {};
  19463. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  19464. // translate parameters to ExtrudeGeometry API
  19465. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  19466. // defaults
  19467. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  19468. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  19469. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  19470. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  19471. this.type = 'TextGeometry';
  19472. };
  19473. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  19474. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  19475. // File:src/extras/geometries/TorusGeometry.js
  19476. /**
  19477. * @author oosmoxiecode
  19478. * @author mrdoob / http://mrdoob.com/
  19479. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  19480. */
  19481. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  19482. THREE.Geometry.call( this );
  19483. this.type = 'TorusGeometry';
  19484. this.parameters = {
  19485. radius: radius,
  19486. tube: tube,
  19487. radialSegments: radialSegments,
  19488. tubularSegments: tubularSegments,
  19489. arc: arc
  19490. };
  19491. radius = radius || 100;
  19492. tube = tube || 40;
  19493. radialSegments = radialSegments || 8;
  19494. tubularSegments = tubularSegments || 6;
  19495. arc = arc || Math.PI * 2;
  19496. var center = new THREE.Vector3(), uvs = [], normals = [];
  19497. for ( var j = 0; j <= radialSegments; j ++ ) {
  19498. for ( var i = 0; i <= tubularSegments; i ++ ) {
  19499. var u = i / tubularSegments * arc;
  19500. var v = j / radialSegments * Math.PI * 2;
  19501. center.x = radius * Math.cos( u );
  19502. center.y = radius * Math.sin( u );
  19503. var vertex = new THREE.Vector3();
  19504. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  19505. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  19506. vertex.z = tube * Math.sin( v );
  19507. this.vertices.push( vertex );
  19508. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  19509. normals.push( vertex.clone().sub( center ).normalize() );
  19510. }
  19511. }
  19512. for ( var j = 1; j <= radialSegments; j ++ ) {
  19513. for ( var i = 1; i <= tubularSegments; i ++ ) {
  19514. var a = ( tubularSegments + 1 ) * j + i - 1;
  19515. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  19516. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  19517. var d = ( tubularSegments + 1 ) * j + i;
  19518. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  19519. this.faces.push( face );
  19520. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  19521. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  19522. this.faces.push( face );
  19523. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  19524. }
  19525. }
  19526. this.computeFaceNormals();
  19527. };
  19528. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19529. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  19530. // File:src/extras/geometries/TorusKnotGeometry.js
  19531. /**
  19532. * @author oosmoxiecode
  19533. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  19534. */
  19535. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  19536. THREE.Geometry.call( this );
  19537. this.type = 'TorusKnotGeometry';
  19538. this.parameters = {
  19539. radius: radius,
  19540. tube: tube,
  19541. radialSegments: radialSegments,
  19542. tubularSegments: tubularSegments,
  19543. p: p,
  19544. q: q,
  19545. heightScale: heightScale
  19546. };
  19547. radius = radius || 100;
  19548. tube = tube || 40;
  19549. radialSegments = radialSegments || 64;
  19550. tubularSegments = tubularSegments || 8;
  19551. p = p || 2;
  19552. q = q || 3;
  19553. heightScale = heightScale || 1;
  19554. var grid = new Array( radialSegments );
  19555. var tang = new THREE.Vector3();
  19556. var n = new THREE.Vector3();
  19557. var bitan = new THREE.Vector3();
  19558. for ( var i = 0; i < radialSegments; ++ i ) {
  19559. grid[ i ] = new Array( tubularSegments );
  19560. var u = i / radialSegments * 2 * p * Math.PI;
  19561. var p1 = getPos( u, q, p, radius, heightScale );
  19562. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  19563. tang.subVectors( p2, p1 );
  19564. n.addVectors( p2, p1 );
  19565. bitan.crossVectors( tang, n );
  19566. n.crossVectors( bitan, tang );
  19567. bitan.normalize();
  19568. n.normalize();
  19569. for ( var j = 0; j < tubularSegments; ++ j ) {
  19570. var v = j / tubularSegments * 2 * Math.PI;
  19571. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19572. var cy = tube * Math.sin( v );
  19573. var pos = new THREE.Vector3();
  19574. pos.x = p1.x + cx * n.x + cy * bitan.x;
  19575. pos.y = p1.y + cx * n.y + cy * bitan.y;
  19576. pos.z = p1.z + cx * n.z + cy * bitan.z;
  19577. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  19578. }
  19579. }
  19580. for ( var i = 0; i < radialSegments; ++ i ) {
  19581. for ( var j = 0; j < tubularSegments; ++ j ) {
  19582. var ip = ( i + 1 ) % radialSegments;
  19583. var jp = ( j + 1 ) % tubularSegments;
  19584. var a = grid[ i ][ j ];
  19585. var b = grid[ ip ][ j ];
  19586. var c = grid[ ip ][ jp ];
  19587. var d = grid[ i ][ jp ];
  19588. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  19589. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  19590. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  19591. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  19592. this.faces.push( new THREE.Face3( a, b, d ) );
  19593. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19594. this.faces.push( new THREE.Face3( b, c, d ) );
  19595. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19596. }
  19597. }
  19598. this.computeFaceNormals();
  19599. this.computeVertexNormals();
  19600. function getPos( u, in_q, in_p, radius, heightScale ) {
  19601. var cu = Math.cos( u );
  19602. var su = Math.sin( u );
  19603. var quOverP = in_q / in_p * u;
  19604. var cs = Math.cos( quOverP );
  19605. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  19606. var ty = radius * ( 2 + cs ) * su * 0.5;
  19607. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  19608. return new THREE.Vector3( tx, ty, tz );
  19609. }
  19610. };
  19611. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19612. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  19613. // File:src/extras/geometries/TubeGeometry.js
  19614. /**
  19615. * @author WestLangley / https://github.com/WestLangley
  19616. * @author zz85 / https://github.com/zz85
  19617. * @author miningold / https://github.com/miningold
  19618. * @author jonobr1 / https://github.com/jonobr1
  19619. *
  19620. * Modified from the TorusKnotGeometry by @oosmoxiecode
  19621. *
  19622. * Creates a tube which extrudes along a 3d spline
  19623. *
  19624. * Uses parallel transport frames as described in
  19625. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  19626. */
  19627. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  19628. THREE.Geometry.call( this );
  19629. this.type = 'TubeGeometry';
  19630. this.parameters = {
  19631. path: path,
  19632. segments: segments,
  19633. radius: radius,
  19634. radialSegments: radialSegments,
  19635. closed: closed
  19636. };
  19637. segments = segments || 64;
  19638. radius = radius || 1;
  19639. radialSegments = radialSegments || 8;
  19640. closed = closed || false;
  19641. taper = taper || THREE.TubeGeometry.NoTaper;
  19642. var grid = [];
  19643. var scope = this,
  19644. tangent,
  19645. normal,
  19646. binormal,
  19647. numpoints = segments + 1,
  19648. u, v, r,
  19649. cx, cy,
  19650. pos, pos2 = new THREE.Vector3(),
  19651. i, j,
  19652. ip, jp,
  19653. a, b, c, d,
  19654. uva, uvb, uvc, uvd;
  19655. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  19656. tangents = frames.tangents,
  19657. normals = frames.normals,
  19658. binormals = frames.binormals;
  19659. // proxy internals
  19660. this.tangents = tangents;
  19661. this.normals = normals;
  19662. this.binormals = binormals;
  19663. function vert( x, y, z ) {
  19664. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  19665. }
  19666. // construct the grid
  19667. for ( i = 0; i < numpoints; i ++ ) {
  19668. grid[ i ] = [];
  19669. u = i / ( numpoints - 1 );
  19670. pos = path.getPointAt( u );
  19671. tangent = tangents[ i ];
  19672. normal = normals[ i ];
  19673. binormal = binormals[ i ];
  19674. r = radius * taper( u );
  19675. for ( j = 0; j < radialSegments; j ++ ) {
  19676. v = j / radialSegments * 2 * Math.PI;
  19677. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19678. cy = r * Math.sin( v );
  19679. pos2.copy( pos );
  19680. pos2.x += cx * normal.x + cy * binormal.x;
  19681. pos2.y += cx * normal.y + cy * binormal.y;
  19682. pos2.z += cx * normal.z + cy * binormal.z;
  19683. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  19684. }
  19685. }
  19686. // construct the mesh
  19687. for ( i = 0; i < segments; i ++ ) {
  19688. for ( j = 0; j < radialSegments; j ++ ) {
  19689. ip = ( closed ) ? (i + 1) % segments : i + 1;
  19690. jp = (j + 1) % radialSegments;
  19691. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  19692. b = grid[ ip ][ j ];
  19693. c = grid[ ip ][ jp ];
  19694. d = grid[ i ][ jp ];
  19695. uva = new THREE.Vector2( i / segments, j / radialSegments );
  19696. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  19697. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  19698. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  19699. this.faces.push( new THREE.Face3( a, b, d ) );
  19700. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19701. this.faces.push( new THREE.Face3( b, c, d ) );
  19702. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19703. }
  19704. }
  19705. this.computeFaceNormals();
  19706. this.computeVertexNormals();
  19707. };
  19708. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19709. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  19710. THREE.TubeGeometry.NoTaper = function ( u ) {
  19711. return 1;
  19712. };
  19713. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  19714. return Math.sin( Math.PI * u );
  19715. };
  19716. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  19717. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  19718. var normal = new THREE.Vector3(),
  19719. tangents = [],
  19720. normals = [],
  19721. binormals = [],
  19722. vec = new THREE.Vector3(),
  19723. mat = new THREE.Matrix4(),
  19724. numpoints = segments + 1,
  19725. theta,
  19726. epsilon = 0.0001,
  19727. smallest,
  19728. tx, ty, tz,
  19729. i, u;
  19730. // expose internals
  19731. this.tangents = tangents;
  19732. this.normals = normals;
  19733. this.binormals = binormals;
  19734. // compute the tangent vectors for each segment on the path
  19735. for ( i = 0; i < numpoints; i ++ ) {
  19736. u = i / ( numpoints - 1 );
  19737. tangents[ i ] = path.getTangentAt( u );
  19738. tangents[ i ].normalize();
  19739. }
  19740. initialNormal3();
  19741. /*
  19742. function initialNormal1(lastBinormal) {
  19743. // fixed start binormal. Has dangers of 0 vectors
  19744. normals[ 0 ] = new THREE.Vector3();
  19745. binormals[ 0 ] = new THREE.Vector3();
  19746. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  19747. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  19748. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  19749. }
  19750. function initialNormal2() {
  19751. // This uses the Frenet-Serret formula for deriving binormal
  19752. var t2 = path.getTangentAt( epsilon );
  19753. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  19754. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  19755. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  19756. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  19757. }
  19758. */
  19759. function initialNormal3() {
  19760. // select an initial normal vector perpendicular to the first tangent vector,
  19761. // and in the direction of the smallest tangent xyz component
  19762. normals[ 0 ] = new THREE.Vector3();
  19763. binormals[ 0 ] = new THREE.Vector3();
  19764. smallest = Number.MAX_VALUE;
  19765. tx = Math.abs( tangents[ 0 ].x );
  19766. ty = Math.abs( tangents[ 0 ].y );
  19767. tz = Math.abs( tangents[ 0 ].z );
  19768. if ( tx <= smallest ) {
  19769. smallest = tx;
  19770. normal.set( 1, 0, 0 );
  19771. }
  19772. if ( ty <= smallest ) {
  19773. smallest = ty;
  19774. normal.set( 0, 1, 0 );
  19775. }
  19776. if ( tz <= smallest ) {
  19777. normal.set( 0, 0, 1 );
  19778. }
  19779. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  19780. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  19781. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  19782. }
  19783. // compute the slowly-varying normal and binormal vectors for each segment on the path
  19784. for ( i = 1; i < numpoints; i ++ ) {
  19785. normals[ i ] = normals[ i - 1 ].clone();
  19786. binormals[ i ] = binormals[ i - 1 ].clone();
  19787. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  19788. if ( vec.length() > epsilon ) {
  19789. vec.normalize();
  19790. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  19791. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  19792. }
  19793. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  19794. }
  19795. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  19796. if ( closed ) {
  19797. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  19798. theta /= ( numpoints - 1 );
  19799. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  19800. theta = - theta;
  19801. }
  19802. for ( i = 1; i < numpoints; i ++ ) {
  19803. // twist a little...
  19804. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  19805. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  19806. }
  19807. }
  19808. };
  19809. // File:src/extras/geometries/PolyhedronGeometry.js
  19810. /**
  19811. * @author clockworkgeek / https://github.com/clockworkgeek
  19812. * @author timothypratley / https://github.com/timothypratley
  19813. * @author WestLangley / http://github.com/WestLangley
  19814. */
  19815. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  19816. THREE.Geometry.call( this );
  19817. this.type = 'PolyhedronGeometry';
  19818. this.parameters = {
  19819. vertices: vertices,
  19820. indices: indices,
  19821. radius: radius,
  19822. detail: detail
  19823. };
  19824. radius = radius || 1;
  19825. detail = detail || 0;
  19826. var that = this;
  19827. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  19828. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  19829. }
  19830. var p = this.vertices;
  19831. var faces = [];
  19832. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  19833. var v1 = p[ indices[ i ] ];
  19834. var v2 = p[ indices[ i + 1 ] ];
  19835. var v3 = p[ indices[ i + 2 ] ];
  19836. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  19837. }
  19838. var centroid = new THREE.Vector3();
  19839. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19840. subdivide( faces[ i ], detail );
  19841. }
  19842. // Handle case when face straddles the seam
  19843. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  19844. var uvs = this.faceVertexUvs[ 0 ][ i ];
  19845. var x0 = uvs[ 0 ].x;
  19846. var x1 = uvs[ 1 ].x;
  19847. var x2 = uvs[ 2 ].x;
  19848. var max = Math.max( x0, Math.max( x1, x2 ) );
  19849. var min = Math.min( x0, Math.min( x1, x2 ) );
  19850. if ( max > 0.9 && min < 0.1 ) { // 0.9 is somewhat arbitrary
  19851. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  19852. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  19853. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  19854. }
  19855. }
  19856. // Apply radius
  19857. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  19858. this.vertices[ i ].multiplyScalar( radius );
  19859. }
  19860. // Merge vertices
  19861. this.mergeVertices();
  19862. this.computeFaceNormals();
  19863. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19864. // Project vector onto sphere's surface
  19865. function prepare( vector ) {
  19866. var vertex = vector.normalize().clone();
  19867. vertex.index = that.vertices.push( vertex ) - 1;
  19868. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  19869. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  19870. var v = inclination( vector ) / Math.PI + 0.5;
  19871. vertex.uv = new THREE.Vector2( u, 1 - v );
  19872. return vertex;
  19873. }
  19874. // Approximate a curved face with recursively sub-divided triangles.
  19875. function make( v1, v2, v3 ) {
  19876. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  19877. that.faces.push( face );
  19878. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  19879. var azi = azimuth( centroid );
  19880. that.faceVertexUvs[ 0 ].push( [
  19881. correctUV( v1.uv, v1, azi ),
  19882. correctUV( v2.uv, v2, azi ),
  19883. correctUV( v3.uv, v3, azi )
  19884. ] );
  19885. }
  19886. // Analytically subdivide a face to the required detail level.
  19887. function subdivide( face, detail ) {
  19888. var cols = Math.pow(2, detail);
  19889. var a = prepare( that.vertices[ face.a ] );
  19890. var b = prepare( that.vertices[ face.b ] );
  19891. var c = prepare( that.vertices[ face.c ] );
  19892. var v = [];
  19893. // Construct all of the vertices for this subdivision.
  19894. for ( var i = 0 ; i <= cols; i ++ ) {
  19895. v[ i ] = [];
  19896. var aj = prepare( a.clone().lerp( c, i / cols ) );
  19897. var bj = prepare( b.clone().lerp( c, i / cols ) );
  19898. var rows = cols - i;
  19899. for ( var j = 0; j <= rows; j ++) {
  19900. if ( j === 0 && i === cols ) {
  19901. v[ i ][ j ] = aj;
  19902. } else {
  19903. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  19904. }
  19905. }
  19906. }
  19907. // Construct all of the faces.
  19908. for ( var i = 0; i < cols ; i ++ ) {
  19909. for ( var j = 0; j < 2 * (cols - i) - 1; j ++ ) {
  19910. var k = Math.floor( j / 2 );
  19911. if ( j % 2 === 0 ) {
  19912. make(
  19913. v[ i ][ k + 1],
  19914. v[ i + 1 ][ k ],
  19915. v[ i ][ k ]
  19916. );
  19917. } else {
  19918. make(
  19919. v[ i ][ k + 1 ],
  19920. v[ i + 1][ k + 1],
  19921. v[ i + 1 ][ k ]
  19922. );
  19923. }
  19924. }
  19925. }
  19926. }
  19927. // Angle around the Y axis, counter-clockwise when looking from above.
  19928. function azimuth( vector ) {
  19929. return Math.atan2( vector.z, - vector.x );
  19930. }
  19931. // Angle above the XZ plane.
  19932. function inclination( vector ) {
  19933. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  19934. }
  19935. // Texture fixing helper. Spheres have some odd behaviours.
  19936. function correctUV( uv, vector, azimuth ) {
  19937. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  19938. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  19939. return uv.clone();
  19940. }
  19941. };
  19942. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19943. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  19944. // File:src/extras/geometries/DodecahedronGeometry.js
  19945. /**
  19946. * @author Abe Pazos / https://hamoid.com
  19947. */
  19948. THREE.DodecahedronGeometry = function ( radius, detail ) {
  19949. this.parameters = {
  19950. radius: radius,
  19951. detail: detail
  19952. };
  19953. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  19954. var r = 1 / t;
  19955. var vertices = [
  19956. // (±1, ±1, ±1)
  19957. -1, -1, -1, -1, -1, 1,
  19958. -1, 1, -1, -1, 1, 1,
  19959. 1, -1, -1, 1, -1, 1,
  19960. 1, 1, -1, 1, 1, 1,
  19961. // (0, ±1/φ, ±φ)
  19962. 0, -r, -t, 0, -r, t,
  19963. 0, r, -t, 0, r, t,
  19964. // (±1/φ, ±φ, 0)
  19965. -r, -t, 0, -r, t, 0,
  19966. r, -t, 0, r, t, 0,
  19967. // (±φ, 0, ±1/φ)
  19968. -t, 0, -r, t, 0, -r,
  19969. -t, 0, r, t, 0, r
  19970. ];
  19971. var indices = [
  19972. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  19973. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  19974. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  19975. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  19976. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  19977. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  19978. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  19979. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  19980. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  19981. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  19982. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  19983. 1, 12, 14, 1, 14, 5, 1, 5, 9
  19984. ];
  19985. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  19986. };
  19987. THREE.DodecahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19988. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  19989. // File:src/extras/geometries/IcosahedronGeometry.js
  19990. /**
  19991. * @author timothypratley / https://github.com/timothypratley
  19992. */
  19993. THREE.IcosahedronGeometry = function ( radius, detail ) {
  19994. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  19995. var vertices = [
  19996. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  19997. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  19998. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  19999. ];
  20000. var indices = [
  20001. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  20002. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  20003. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  20004. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  20005. ];
  20006. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20007. this.type = 'IcosahedronGeometry';
  20008. this.parameters = {
  20009. radius: radius,
  20010. detail: detail
  20011. };
  20012. };
  20013. THREE.IcosahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20014. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  20015. // File:src/extras/geometries/OctahedronGeometry.js
  20016. /**
  20017. * @author timothypratley / https://github.com/timothypratley
  20018. */
  20019. THREE.OctahedronGeometry = function ( radius, detail ) {
  20020. this.parameters = {
  20021. radius: radius,
  20022. detail: detail
  20023. };
  20024. var vertices = [
  20025. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0,- 1, 0, 0, 0, 1, 0, 0,- 1
  20026. ];
  20027. var indices = [
  20028. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  20029. ];
  20030. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20031. this.type = 'OctahedronGeometry';
  20032. this.parameters = {
  20033. radius: radius,
  20034. detail: detail
  20035. };
  20036. };
  20037. THREE.OctahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20038. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  20039. // File:src/extras/geometries/TetrahedronGeometry.js
  20040. /**
  20041. * @author timothypratley / https://github.com/timothypratley
  20042. */
  20043. THREE.TetrahedronGeometry = function ( radius, detail ) {
  20044. var vertices = [
  20045. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20046. ];
  20047. var indices = [
  20048. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20049. ];
  20050. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20051. this.type = 'TetrahedronGeometry';
  20052. this.parameters = {
  20053. radius: radius,
  20054. detail: detail
  20055. };
  20056. };
  20057. THREE.TetrahedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20058. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  20059. // File:src/extras/geometries/ParametricGeometry.js
  20060. /**
  20061. * @author zz85 / https://github.com/zz85
  20062. * Parametric Surfaces Geometry
  20063. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  20064. *
  20065. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  20066. *
  20067. */
  20068. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  20069. THREE.Geometry.call( this );
  20070. this.type = 'ParametricGeometry';
  20071. this.parameters = {
  20072. func: func,
  20073. slices: slices,
  20074. stacks: stacks
  20075. };
  20076. var verts = this.vertices;
  20077. var faces = this.faces;
  20078. var uvs = this.faceVertexUvs[ 0 ];
  20079. var i, j, p;
  20080. var u, v;
  20081. var sliceCount = slices + 1;
  20082. for ( i = 0; i <= stacks; i ++ ) {
  20083. v = i / stacks;
  20084. for ( j = 0; j <= slices; j ++ ) {
  20085. u = j / slices;
  20086. p = func( u, v );
  20087. verts.push( p );
  20088. }
  20089. }
  20090. var a, b, c, d;
  20091. var uva, uvb, uvc, uvd;
  20092. for ( i = 0; i < stacks; i ++ ) {
  20093. for ( j = 0; j < slices; j ++ ) {
  20094. a = i * sliceCount + j;
  20095. b = i * sliceCount + j + 1;
  20096. c = (i + 1) * sliceCount + j + 1;
  20097. d = (i + 1) * sliceCount + j;
  20098. uva = new THREE.Vector2( j / slices, i / stacks );
  20099. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  20100. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  20101. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  20102. faces.push( new THREE.Face3( a, b, d ) );
  20103. uvs.push( [ uva, uvb, uvd ] );
  20104. faces.push( new THREE.Face3( b, c, d ) );
  20105. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  20106. }
  20107. }
  20108. // console.log(this);
  20109. // magic bullet
  20110. // var diff = this.mergeVertices();
  20111. // console.log('removed ', diff, ' vertices by merging');
  20112. this.computeFaceNormals();
  20113. this.computeVertexNormals();
  20114. };
  20115. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20116. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  20117. // File:src/extras/geometries/WireframeGeometry.js
  20118. /**
  20119. * @author mrdoob / http://mrdoob.com/
  20120. */
  20121. THREE.WireframeGeometry = function ( geometry ) {
  20122. THREE.BufferGeometry.call( this );
  20123. var edge = [ 0, 0 ], hash = {};
  20124. var sortFunction = function ( a, b ) { return a - b };
  20125. var keys = [ 'a', 'b', 'c' ];
  20126. if ( geometry instanceof THREE.Geometry ) {
  20127. var vertices = geometry.vertices;
  20128. var faces = geometry.faces;
  20129. var numEdges = 0;
  20130. // allocate maximal size
  20131. var edges = new Uint32Array( 6 * faces.length );
  20132. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20133. var face = faces[ i ];
  20134. for ( var j = 0; j < 3; j ++ ) {
  20135. edge[ 0 ] = face[ keys[ j ] ];
  20136. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  20137. edge.sort( sortFunction );
  20138. var key = edge.toString();
  20139. if ( hash[ key ] === undefined ) {
  20140. edges[ 2 * numEdges ] = edge[ 0 ];
  20141. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20142. hash[ key ] = true;
  20143. numEdges ++;
  20144. }
  20145. }
  20146. }
  20147. var coords = new Float32Array( numEdges * 2 * 3 );
  20148. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20149. for ( var j = 0; j < 2; j ++ ) {
  20150. var vertex = vertices[ edges [ 2 * i + j] ];
  20151. var index = 6 * i + 3 * j;
  20152. coords[ index + 0 ] = vertex.x;
  20153. coords[ index + 1 ] = vertex.y;
  20154. coords[ index + 2 ] = vertex.z;
  20155. }
  20156. }
  20157. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20158. } else if ( geometry instanceof THREE.BufferGeometry ) {
  20159. if ( geometry.attributes.index !== undefined ) { // Indexed BufferGeometry
  20160. var vertices = geometry.attributes.position;
  20161. var indices = geometry.attributes.index.array;
  20162. var drawcalls = geometry.drawcalls;
  20163. var numEdges = 0;
  20164. if ( drawcalls.length === 0 ) {
  20165. drawcalls = [ { count : indices.length, index : 0, start : 0 } ];
  20166. }
  20167. // allocate maximal size
  20168. var edges = new Uint32Array( 2 * indices.length );
  20169. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  20170. var start = drawcalls[ o ].start;
  20171. var count = drawcalls[ o ].count;
  20172. var index = drawcalls[ o ].index;
  20173. for ( var i = start, il = start + count; i < il; i += 3 ) {
  20174. for ( var j = 0; j < 3; j ++ ) {
  20175. edge[ 0 ] = index + indices[ i + j ];
  20176. edge[ 1 ] = index + indices[ i + ( j + 1 ) % 3 ];
  20177. edge.sort( sortFunction );
  20178. var key = edge.toString();
  20179. if ( hash[ key ] === undefined ) {
  20180. edges[ 2 * numEdges ] = edge[ 0 ];
  20181. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20182. hash[ key ] = true;
  20183. numEdges ++;
  20184. }
  20185. }
  20186. }
  20187. }
  20188. var coords = new Float32Array( numEdges * 2 * 3 );
  20189. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20190. for ( var j = 0; j < 2; j ++ ) {
  20191. var index = 6 * i + 3 * j;
  20192. var index2 = edges[2 * i + j];
  20193. coords[ index + 0 ] = vertices.getX( index2 );
  20194. coords[ index + 1 ] = vertices.getY( index2 );
  20195. coords[ index + 2 ] = vertices.getZ( index2 );
  20196. }
  20197. }
  20198. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20199. } else { // non-indexed BufferGeometry
  20200. var vertices = geometry.attributes.position.array;
  20201. var numEdges = vertices.length / 3;
  20202. var numTris = numEdges / 3;
  20203. var coords = new Float32Array( numEdges * 2 * 3 );
  20204. for ( var i = 0, l = numTris; i < l; i ++ ) {
  20205. for ( var j = 0; j < 3; j ++ ) {
  20206. var index = 18 * i + 6 * j;
  20207. var index1 = 9 * i + 3 * j;
  20208. coords[ index + 0 ] = vertices[ index1 ];
  20209. coords[ index + 1 ] = vertices[ index1 + 1 ];
  20210. coords[ index + 2 ] = vertices[ index1 + 2 ];
  20211. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  20212. coords[ index + 3 ] = vertices[ index2 ];
  20213. coords[ index + 4 ] = vertices[ index2 + 1 ];
  20214. coords[ index + 5 ] = vertices[ index2 + 2 ];
  20215. }
  20216. }
  20217. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20218. }
  20219. }
  20220. };
  20221. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20222. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  20223. // File:src/extras/helpers/AxisHelper.js
  20224. /**
  20225. * @author sroucheray / http://sroucheray.org/
  20226. * @author mrdoob / http://mrdoob.com/
  20227. */
  20228. THREE.AxisHelper = function ( size ) {
  20229. size = size || 1;
  20230. var vertices = new Float32Array( [
  20231. 0, 0, 0, size, 0, 0,
  20232. 0, 0, 0, 0, size, 0,
  20233. 0, 0, 0, 0, 0, size
  20234. ] );
  20235. var colors = new Float32Array( [
  20236. 1, 0, 0, 1, 0.6, 0,
  20237. 0, 1, 0, 0.6, 1, 0,
  20238. 0, 0, 1, 0, 0.6, 1
  20239. ] );
  20240. var geometry = new THREE.BufferGeometry();
  20241. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  20242. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  20243. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20244. THREE.LineSegments.call( this, geometry, material );
  20245. };
  20246. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20247. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  20248. // File:src/extras/helpers/ArrowHelper.js
  20249. /**
  20250. * @author WestLangley / http://github.com/WestLangley
  20251. * @author zz85 / http://github.com/zz85
  20252. * @author bhouston / http://exocortex.com
  20253. *
  20254. * Creates an arrow for visualizing directions
  20255. *
  20256. * Parameters:
  20257. * dir - Vector3
  20258. * origin - Vector3
  20259. * length - Number
  20260. * color - color in hex value
  20261. * headLength - Number
  20262. * headWidth - Number
  20263. */
  20264. THREE.ArrowHelper = ( function () {
  20265. var lineGeometry = new THREE.Geometry();
  20266. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  20267. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  20268. coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  20269. return function ( dir, origin, length, color, headLength, headWidth ) {
  20270. // dir is assumed to be normalized
  20271. THREE.Object3D.call( this );
  20272. if ( color === undefined ) color = 0xffff00;
  20273. if ( length === undefined ) length = 1;
  20274. if ( headLength === undefined ) headLength = 0.2 * length;
  20275. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20276. this.position.copy( origin );
  20277. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  20278. this.line.matrixAutoUpdate = false;
  20279. this.add( this.line );
  20280. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  20281. this.cone.matrixAutoUpdate = false;
  20282. this.add( this.cone );
  20283. this.setDirection( dir );
  20284. this.setLength( length, headLength, headWidth );
  20285. }
  20286. }() );
  20287. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  20288. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  20289. THREE.ArrowHelper.prototype.setDirection = ( function () {
  20290. var axis = new THREE.Vector3();
  20291. var radians;
  20292. return function ( dir ) {
  20293. // dir is assumed to be normalized
  20294. if ( dir.y > 0.99999 ) {
  20295. this.quaternion.set( 0, 0, 0, 1 );
  20296. } else if ( dir.y < - 0.99999 ) {
  20297. this.quaternion.set( 1, 0, 0, 0 );
  20298. } else {
  20299. axis.set( dir.z, 0, - dir.x ).normalize();
  20300. radians = Math.acos( dir.y );
  20301. this.quaternion.setFromAxisAngle( axis, radians );
  20302. }
  20303. };
  20304. }() );
  20305. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  20306. if ( headLength === undefined ) headLength = 0.2 * length;
  20307. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20308. this.line.scale.set( 1, length - headLength, 1 );
  20309. this.line.updateMatrix();
  20310. this.cone.scale.set( headWidth, headLength, headWidth );
  20311. this.cone.position.y = length;
  20312. this.cone.updateMatrix();
  20313. };
  20314. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  20315. this.line.material.color.set( color );
  20316. this.cone.material.color.set( color );
  20317. };
  20318. // File:src/extras/helpers/BoxHelper.js
  20319. /**
  20320. * @author mrdoob / http://mrdoob.com/
  20321. */
  20322. THREE.BoxHelper = function ( object ) {
  20323. var geometry = new THREE.BufferGeometry();
  20324. geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( 72 ), 3 ) );
  20325. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  20326. if ( object !== undefined ) {
  20327. this.update( object );
  20328. }
  20329. };
  20330. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20331. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  20332. THREE.BoxHelper.prototype.update = ( function () {
  20333. var box = new THREE.Box3();
  20334. return function ( object ) {
  20335. box.setFromObject( object );
  20336. var min = box.min;
  20337. var max = box.max;
  20338. /*
  20339. 5____4
  20340. 1/___0/|
  20341. | 6__|_7
  20342. 2/___3/
  20343. 0: max.x, max.y, max.z
  20344. 1: min.x, max.y, max.z
  20345. 2: min.x, min.y, max.z
  20346. 3: max.x, min.y, max.z
  20347. 4: max.x, max.y, min.z
  20348. 5: min.x, max.y, min.z
  20349. 6: min.x, min.y, min.z
  20350. 7: max.x, min.y, min.z
  20351. */
  20352. var vertices = this.geometry.attributes.position.array;
  20353. vertices[ 0 ] = max.x; vertices[ 1 ] = max.y; vertices[ 2 ] = max.z;
  20354. vertices[ 3 ] = min.x; vertices[ 4 ] = max.y; vertices[ 5 ] = max.z;
  20355. vertices[ 6 ] = min.x; vertices[ 7 ] = max.y; vertices[ 8 ] = max.z;
  20356. vertices[ 9 ] = min.x; vertices[ 10 ] = min.y; vertices[ 11 ] = max.z;
  20357. vertices[ 12 ] = min.x; vertices[ 13 ] = min.y; vertices[ 14 ] = max.z;
  20358. vertices[ 15 ] = max.x; vertices[ 16 ] = min.y; vertices[ 17 ] = max.z;
  20359. vertices[ 18 ] = max.x; vertices[ 19 ] = min.y; vertices[ 20 ] = max.z;
  20360. vertices[ 21 ] = max.x; vertices[ 22 ] = max.y; vertices[ 23 ] = max.z;
  20361. //
  20362. vertices[ 24 ] = max.x; vertices[ 25 ] = max.y; vertices[ 26 ] = min.z;
  20363. vertices[ 27 ] = min.x; vertices[ 28 ] = max.y; vertices[ 29 ] = min.z;
  20364. vertices[ 30 ] = min.x; vertices[ 31 ] = max.y; vertices[ 32 ] = min.z;
  20365. vertices[ 33 ] = min.x; vertices[ 34 ] = min.y; vertices[ 35 ] = min.z;
  20366. vertices[ 36 ] = min.x; vertices[ 37 ] = min.y; vertices[ 38 ] = min.z;
  20367. vertices[ 39 ] = max.x; vertices[ 40 ] = min.y; vertices[ 41 ] = min.z;
  20368. vertices[ 42 ] = max.x; vertices[ 43 ] = min.y; vertices[ 44 ] = min.z;
  20369. vertices[ 45 ] = max.x; vertices[ 46 ] = max.y; vertices[ 47 ] = min.z;
  20370. //
  20371. vertices[ 48 ] = max.x; vertices[ 49 ] = max.y; vertices[ 50 ] = max.z;
  20372. vertices[ 51 ] = max.x; vertices[ 52 ] = max.y; vertices[ 53 ] = min.z;
  20373. vertices[ 54 ] = min.x; vertices[ 55 ] = max.y; vertices[ 56 ] = max.z;
  20374. vertices[ 57 ] = min.x; vertices[ 58 ] = max.y; vertices[ 59 ] = min.z;
  20375. vertices[ 60 ] = min.x; vertices[ 61 ] = min.y; vertices[ 62 ] = max.z;
  20376. vertices[ 63 ] = min.x; vertices[ 64 ] = min.y; vertices[ 65 ] = min.z;
  20377. vertices[ 66 ] = max.x; vertices[ 67 ] = min.y; vertices[ 68 ] = max.z;
  20378. vertices[ 69 ] = max.x; vertices[ 70 ] = min.y; vertices[ 71 ] = min.z;
  20379. this.geometry.attributes.position.needsUpdate = true;
  20380. this.geometry.computeBoundingSphere();
  20381. }
  20382. } )();
  20383. // File:src/extras/helpers/BoundingBoxHelper.js
  20384. /**
  20385. * @author WestLangley / http://github.com/WestLangley
  20386. */
  20387. // a helper to show the world-axis-aligned bounding box for an object
  20388. THREE.BoundingBoxHelper = function ( object, hex ) {
  20389. var color = ( hex !== undefined ) ? hex : 0x888888;
  20390. this.object = object;
  20391. this.box = new THREE.Box3();
  20392. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  20393. };
  20394. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  20395. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  20396. THREE.BoundingBoxHelper.prototype.update = function () {
  20397. this.box.setFromObject( this.object );
  20398. this.box.size( this.scale );
  20399. this.box.center( this.position );
  20400. };
  20401. // File:src/extras/helpers/CameraHelper.js
  20402. /**
  20403. * @author alteredq / http://alteredqualia.com/
  20404. *
  20405. * - shows frustum, line of sight and up of the camera
  20406. * - suitable for fast updates
  20407. * - based on frustum visualization in lightgl.js shadowmap example
  20408. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  20409. */
  20410. THREE.CameraHelper = function ( camera ) {
  20411. var geometry = new THREE.Geometry();
  20412. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  20413. var pointMap = {};
  20414. // colors
  20415. var hexFrustum = 0xffaa00;
  20416. var hexCone = 0xff0000;
  20417. var hexUp = 0x00aaff;
  20418. var hexTarget = 0xffffff;
  20419. var hexCross = 0x333333;
  20420. // near
  20421. addLine( "n1", "n2", hexFrustum );
  20422. addLine( "n2", "n4", hexFrustum );
  20423. addLine( "n4", "n3", hexFrustum );
  20424. addLine( "n3", "n1", hexFrustum );
  20425. // far
  20426. addLine( "f1", "f2", hexFrustum );
  20427. addLine( "f2", "f4", hexFrustum );
  20428. addLine( "f4", "f3", hexFrustum );
  20429. addLine( "f3", "f1", hexFrustum );
  20430. // sides
  20431. addLine( "n1", "f1", hexFrustum );
  20432. addLine( "n2", "f2", hexFrustum );
  20433. addLine( "n3", "f3", hexFrustum );
  20434. addLine( "n4", "f4", hexFrustum );
  20435. // cone
  20436. addLine( "p", "n1", hexCone );
  20437. addLine( "p", "n2", hexCone );
  20438. addLine( "p", "n3", hexCone );
  20439. addLine( "p", "n4", hexCone );
  20440. // up
  20441. addLine( "u1", "u2", hexUp );
  20442. addLine( "u2", "u3", hexUp );
  20443. addLine( "u3", "u1", hexUp );
  20444. // target
  20445. addLine( "c", "t", hexTarget );
  20446. addLine( "p", "c", hexCross );
  20447. // cross
  20448. addLine( "cn1", "cn2", hexCross );
  20449. addLine( "cn3", "cn4", hexCross );
  20450. addLine( "cf1", "cf2", hexCross );
  20451. addLine( "cf3", "cf4", hexCross );
  20452. function addLine( a, b, hex ) {
  20453. addPoint( a, hex );
  20454. addPoint( b, hex );
  20455. }
  20456. function addPoint( id, hex ) {
  20457. geometry.vertices.push( new THREE.Vector3() );
  20458. geometry.colors.push( new THREE.Color( hex ) );
  20459. if ( pointMap[ id ] === undefined ) {
  20460. pointMap[ id ] = [];
  20461. }
  20462. pointMap[ id ].push( geometry.vertices.length - 1 );
  20463. }
  20464. THREE.LineSegments.call( this, geometry, material );
  20465. this.camera = camera;
  20466. this.matrix = camera.matrixWorld;
  20467. this.matrixAutoUpdate = false;
  20468. this.pointMap = pointMap;
  20469. this.update();
  20470. };
  20471. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20472. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  20473. THREE.CameraHelper.prototype.update = function () {
  20474. var geometry, pointMap;
  20475. var vector = new THREE.Vector3();
  20476. var camera = new THREE.Camera();
  20477. var setPoint = function ( point, x, y, z ) {
  20478. vector.set( x, y, z ).unproject( camera );
  20479. var points = pointMap[ point ];
  20480. if ( points !== undefined ) {
  20481. for ( var i = 0, il = points.length; i < il; i ++ ) {
  20482. geometry.vertices[ points[ i ] ].copy( vector );
  20483. }
  20484. }
  20485. };
  20486. return function () {
  20487. geometry = this.geometry;
  20488. pointMap = this.pointMap;
  20489. var w = 1, h = 1;
  20490. // we need just camera projection matrix
  20491. // world matrix must be identity
  20492. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  20493. // center / target
  20494. setPoint( "c", 0, 0, - 1 );
  20495. setPoint( "t", 0, 0, 1 );
  20496. // near
  20497. setPoint( "n1", - w, - h, - 1 );
  20498. setPoint( "n2", w, - h, - 1 );
  20499. setPoint( "n3", - w, h, - 1 );
  20500. setPoint( "n4", w, h, - 1 );
  20501. // far
  20502. setPoint( "f1", - w, - h, 1 );
  20503. setPoint( "f2", w, - h, 1 );
  20504. setPoint( "f3", - w, h, 1 );
  20505. setPoint( "f4", w, h, 1 );
  20506. // up
  20507. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  20508. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  20509. setPoint( "u3", 0, h * 2, - 1 );
  20510. // cross
  20511. setPoint( "cf1", - w, 0, 1 );
  20512. setPoint( "cf2", w, 0, 1 );
  20513. setPoint( "cf3", 0, - h, 1 );
  20514. setPoint( "cf4", 0, h, 1 );
  20515. setPoint( "cn1", - w, 0, - 1 );
  20516. setPoint( "cn2", w, 0, - 1 );
  20517. setPoint( "cn3", 0, - h, - 1 );
  20518. setPoint( "cn4", 0, h, - 1 );
  20519. geometry.verticesNeedUpdate = true;
  20520. };
  20521. }();
  20522. // File:src/extras/helpers/DirectionalLightHelper.js
  20523. /**
  20524. * @author alteredq / http://alteredqualia.com/
  20525. * @author mrdoob / http://mrdoob.com/
  20526. * @author WestLangley / http://github.com/WestLangley
  20527. */
  20528. THREE.DirectionalLightHelper = function ( light, size ) {
  20529. THREE.Object3D.call( this );
  20530. this.light = light;
  20531. this.light.updateMatrixWorld();
  20532. this.matrix = light.matrixWorld;
  20533. this.matrixAutoUpdate = false;
  20534. size = size || 1;
  20535. var geometry = new THREE.Geometry();
  20536. geometry.vertices.push(
  20537. new THREE.Vector3( - size, size, 0 ),
  20538. new THREE.Vector3( size, size, 0 ),
  20539. new THREE.Vector3( size, - size, 0 ),
  20540. new THREE.Vector3( - size, - size, 0 ),
  20541. new THREE.Vector3( - size, size, 0 )
  20542. );
  20543. var material = new THREE.LineBasicMaterial( { fog: false } );
  20544. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20545. this.lightPlane = new THREE.Line( geometry, material );
  20546. this.add( this.lightPlane );
  20547. geometry = new THREE.Geometry();
  20548. geometry.vertices.push(
  20549. new THREE.Vector3(),
  20550. new THREE.Vector3()
  20551. );
  20552. material = new THREE.LineBasicMaterial( { fog: false } );
  20553. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20554. this.targetLine = new THREE.Line( geometry, material );
  20555. this.add( this.targetLine );
  20556. this.update();
  20557. };
  20558. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20559. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  20560. THREE.DirectionalLightHelper.prototype.dispose = function () {
  20561. this.lightPlane.geometry.dispose();
  20562. this.lightPlane.material.dispose();
  20563. this.targetLine.geometry.dispose();
  20564. this.targetLine.material.dispose();
  20565. };
  20566. THREE.DirectionalLightHelper.prototype.update = function () {
  20567. var v1 = new THREE.Vector3();
  20568. var v2 = new THREE.Vector3();
  20569. var v3 = new THREE.Vector3();
  20570. return function () {
  20571. v1.setFromMatrixPosition( this.light.matrixWorld );
  20572. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  20573. v3.subVectors( v2, v1 );
  20574. this.lightPlane.lookAt( v3 );
  20575. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20576. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  20577. this.targetLine.geometry.verticesNeedUpdate = true;
  20578. this.targetLine.material.color.copy( this.lightPlane.material.color );
  20579. };
  20580. }();
  20581. // File:src/extras/helpers/EdgesHelper.js
  20582. /**
  20583. * @author WestLangley / http://github.com/WestLangley
  20584. * @param object THREE.Mesh whose geometry will be used
  20585. * @param hex line color
  20586. * @param thresholdAngle the minimum angle (in degrees),
  20587. * between the face normals of adjacent faces,
  20588. * that is required to render an edge. A value of 10 means
  20589. * an edge is only rendered if the angle is at least 10 degrees.
  20590. */
  20591. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  20592. var color = ( hex !== undefined ) ? hex : 0xffffff;
  20593. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  20594. this.matrix = object.matrixWorld;
  20595. this.matrixAutoUpdate = false;
  20596. };
  20597. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20598. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  20599. // File:src/extras/helpers/FaceNormalsHelper.js
  20600. /**
  20601. * @author mrdoob / http://mrdoob.com/
  20602. * @author WestLangley / http://github.com/WestLangley
  20603. */
  20604. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  20605. // FaceNormalsHelper only supports THREE.Geometry
  20606. this.object = object;
  20607. this.size = ( size !== undefined ) ? size : 1;
  20608. var color = ( hex !== undefined ) ? hex : 0xffff00;
  20609. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20610. //
  20611. var nNormals = 0;
  20612. var objGeometry = this.object.geometry;
  20613. if ( objGeometry instanceof THREE.Geometry ) {
  20614. nNormals = objGeometry.faces.length;
  20615. } else {
  20616. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  20617. }
  20618. //
  20619. var geometry = new THREE.BufferGeometry();
  20620. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  20621. geometry.addAttribute( 'position', positions );
  20622. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20623. //
  20624. this.matrixAutoUpdate = false;
  20625. this.normalMatrix = new THREE.Matrix3();
  20626. this.update();
  20627. };
  20628. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20629. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  20630. THREE.FaceNormalsHelper.prototype.update = ( function () {
  20631. var v1 = new THREE.Vector3();
  20632. var v2 = new THREE.Vector3();
  20633. return function() {
  20634. this.object.updateMatrixWorld( true );
  20635. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  20636. var matrixWorld = this.object.matrixWorld;
  20637. var position = this.geometry.attributes.position;
  20638. //
  20639. var objGeometry = this.object.geometry;
  20640. var vertices = objGeometry.vertices;
  20641. var faces = objGeometry.faces;
  20642. var idx = 0;
  20643. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20644. var face = faces[ i ];
  20645. var normal = face.normal;
  20646. v1.copy( vertices[ face.a ] )
  20647. .add( vertices[ face.b ] )
  20648. .add( vertices[ face.c ] )
  20649. .divideScalar( 3 )
  20650. .applyMatrix4( matrixWorld );
  20651. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  20652. position.setXYZ( idx, v1.x, v1.y, v1.z );
  20653. idx = idx + 1;
  20654. position.setXYZ( idx, v2.x, v2.y, v2.z );
  20655. idx = idx + 1;
  20656. }
  20657. position.needsUpdate = true;
  20658. return this;
  20659. }
  20660. }());
  20661. // File:src/extras/helpers/GridHelper.js
  20662. /**
  20663. * @author mrdoob / http://mrdoob.com/
  20664. */
  20665. THREE.GridHelper = function ( size, step ) {
  20666. var geometry = new THREE.Geometry();
  20667. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20668. this.color1 = new THREE.Color( 0x444444 );
  20669. this.color2 = new THREE.Color( 0x888888 );
  20670. for ( var i = - size; i <= size; i += step ) {
  20671. geometry.vertices.push(
  20672. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  20673. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  20674. );
  20675. var color = i === 0 ? this.color1 : this.color2;
  20676. geometry.colors.push( color, color, color, color );
  20677. }
  20678. THREE.LineSegments.call( this, geometry, material );
  20679. };
  20680. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20681. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  20682. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  20683. this.color1.set( colorCenterLine );
  20684. this.color2.set( colorGrid );
  20685. this.geometry.colorsNeedUpdate = true;
  20686. };
  20687. // File:src/extras/helpers/HemisphereLightHelper.js
  20688. /**
  20689. * @author alteredq / http://alteredqualia.com/
  20690. * @author mrdoob / http://mrdoob.com/
  20691. */
  20692. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  20693. THREE.Object3D.call( this );
  20694. this.light = light;
  20695. this.light.updateMatrixWorld();
  20696. this.matrix = light.matrixWorld;
  20697. this.matrixAutoUpdate = false;
  20698. this.colors = [ new THREE.Color(), new THREE.Color() ];
  20699. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  20700. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  20701. for ( var i = 0, il = 8; i < il; i ++ ) {
  20702. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  20703. }
  20704. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  20705. this.lightSphere = new THREE.Mesh( geometry, material );
  20706. this.add( this.lightSphere );
  20707. this.update();
  20708. };
  20709. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20710. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  20711. THREE.HemisphereLightHelper.prototype.dispose = function () {
  20712. this.lightSphere.geometry.dispose();
  20713. this.lightSphere.material.dispose();
  20714. };
  20715. THREE.HemisphereLightHelper.prototype.update = function () {
  20716. var vector = new THREE.Vector3();
  20717. return function () {
  20718. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  20719. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  20720. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  20721. this.lightSphere.geometry.colorsNeedUpdate = true;
  20722. }
  20723. }();
  20724. // File:src/extras/helpers/PointLightHelper.js
  20725. /**
  20726. * @author alteredq / http://alteredqualia.com/
  20727. * @author mrdoob / http://mrdoob.com/
  20728. */
  20729. THREE.PointLightHelper = function ( light, sphereSize ) {
  20730. this.light = light;
  20731. this.light.updateMatrixWorld();
  20732. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  20733. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  20734. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20735. THREE.Mesh.call( this, geometry, material );
  20736. this.matrix = this.light.matrixWorld;
  20737. this.matrixAutoUpdate = false;
  20738. /*
  20739. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  20740. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  20741. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  20742. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  20743. var d = light.distance;
  20744. if ( d === 0.0 ) {
  20745. this.lightDistance.visible = false;
  20746. } else {
  20747. this.lightDistance.scale.set( d, d, d );
  20748. }
  20749. this.add( this.lightDistance );
  20750. */
  20751. };
  20752. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  20753. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  20754. THREE.PointLightHelper.prototype.dispose = function () {
  20755. this.geometry.dispose();
  20756. this.material.dispose();
  20757. };
  20758. THREE.PointLightHelper.prototype.update = function () {
  20759. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20760. /*
  20761. var d = this.light.distance;
  20762. if ( d === 0.0 ) {
  20763. this.lightDistance.visible = false;
  20764. } else {
  20765. this.lightDistance.visible = true;
  20766. this.lightDistance.scale.set( d, d, d );
  20767. }
  20768. */
  20769. };
  20770. // File:src/extras/helpers/SkeletonHelper.js
  20771. /**
  20772. * @author Sean Griffin / http://twitter.com/sgrif
  20773. * @author Michael Guerrero / http://realitymeltdown.com
  20774. * @author mrdoob / http://mrdoob.com/
  20775. * @author ikerr / http://verold.com
  20776. */
  20777. THREE.SkeletonHelper = function ( object ) {
  20778. this.bones = this.getBoneList( object );
  20779. var geometry = new THREE.Geometry();
  20780. for ( var i = 0; i < this.bones.length; i ++ ) {
  20781. var bone = this.bones[ i ];
  20782. if ( bone.parent instanceof THREE.Bone ) {
  20783. geometry.vertices.push( new THREE.Vector3() );
  20784. geometry.vertices.push( new THREE.Vector3() );
  20785. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  20786. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  20787. }
  20788. }
  20789. geometry.dynamic = true;
  20790. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  20791. THREE.LineSegments.call( this, geometry, material );
  20792. this.root = object;
  20793. this.matrix = object.matrixWorld;
  20794. this.matrixAutoUpdate = false;
  20795. this.update();
  20796. };
  20797. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20798. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  20799. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  20800. var boneList = [];
  20801. if ( object instanceof THREE.Bone ) {
  20802. boneList.push( object );
  20803. }
  20804. for ( var i = 0; i < object.children.length; i ++ ) {
  20805. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  20806. }
  20807. return boneList;
  20808. };
  20809. THREE.SkeletonHelper.prototype.update = function () {
  20810. var geometry = this.geometry;
  20811. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  20812. var boneMatrix = new THREE.Matrix4();
  20813. var j = 0;
  20814. for ( var i = 0; i < this.bones.length; i ++ ) {
  20815. var bone = this.bones[ i ];
  20816. if ( bone.parent instanceof THREE.Bone ) {
  20817. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  20818. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  20819. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  20820. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  20821. j += 2;
  20822. }
  20823. }
  20824. geometry.verticesNeedUpdate = true;
  20825. geometry.computeBoundingSphere();
  20826. };
  20827. // File:src/extras/helpers/SpotLightHelper.js
  20828. /**
  20829. * @author alteredq / http://alteredqualia.com/
  20830. * @author mrdoob / http://mrdoob.com/
  20831. * @author WestLangley / http://github.com/WestLangley
  20832. */
  20833. THREE.SpotLightHelper = function ( light ) {
  20834. THREE.Object3D.call( this );
  20835. this.light = light;
  20836. this.light.updateMatrixWorld();
  20837. this.matrix = light.matrixWorld;
  20838. this.matrixAutoUpdate = false;
  20839. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  20840. geometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  20841. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  20842. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  20843. this.cone = new THREE.Mesh( geometry, material );
  20844. this.add( this.cone );
  20845. this.update();
  20846. };
  20847. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20848. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  20849. THREE.SpotLightHelper.prototype.dispose = function () {
  20850. this.cone.geometry.dispose();
  20851. this.cone.material.dispose();
  20852. };
  20853. THREE.SpotLightHelper.prototype.update = function () {
  20854. var vector = new THREE.Vector3();
  20855. var vector2 = new THREE.Vector3();
  20856. return function () {
  20857. var coneLength = this.light.distance ? this.light.distance : 10000;
  20858. var coneWidth = coneLength * Math.tan( this.light.angle );
  20859. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  20860. vector.setFromMatrixPosition( this.light.matrixWorld );
  20861. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  20862. this.cone.lookAt( vector2.sub( vector ) );
  20863. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20864. };
  20865. }();
  20866. // File:src/extras/helpers/VertexNormalsHelper.js
  20867. /**
  20868. * @author mrdoob / http://mrdoob.com/
  20869. * @author WestLangley / http://github.com/WestLangley
  20870. */
  20871. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  20872. this.object = object;
  20873. this.size = ( size !== undefined ) ? size : 1;
  20874. var color = ( hex !== undefined ) ? hex : 0xff0000;
  20875. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20876. //
  20877. var nNormals = 0;
  20878. var objGeometry = this.object.geometry;
  20879. if ( objGeometry instanceof THREE.Geometry ) {
  20880. nNormals = objGeometry.faces.length * 3;
  20881. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  20882. nNormals = objGeometry.attributes.normal.count
  20883. }
  20884. //
  20885. var geometry = new THREE.BufferGeometry();
  20886. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  20887. geometry.addAttribute( 'position', positions );
  20888. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20889. //
  20890. this.matrixAutoUpdate = false;
  20891. this.normalMatrix = new THREE.Matrix3();
  20892. this.update();
  20893. };
  20894. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20895. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  20896. THREE.VertexNormalsHelper.prototype.update = ( function () {
  20897. var v1 = new THREE.Vector3();
  20898. var v2 = new THREE.Vector3();
  20899. return function() {
  20900. var keys = [ 'a', 'b', 'c' ];
  20901. this.object.updateMatrixWorld( true );
  20902. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  20903. var matrixWorld = this.object.matrixWorld;
  20904. var position = this.geometry.attributes.position;
  20905. //
  20906. var objGeometry = this.object.geometry;
  20907. if ( objGeometry instanceof THREE.Geometry ) {
  20908. var vertices = objGeometry.vertices;
  20909. var faces = objGeometry.faces;
  20910. var idx = 0;
  20911. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20912. var face = faces[ i ];
  20913. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  20914. var vertex = vertices[ face[ keys[ j ] ] ];
  20915. var normal = face.vertexNormals[ j ];
  20916. v1.copy( vertex ).applyMatrix4( matrixWorld );
  20917. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  20918. position.setXYZ( idx, v1.x, v1.y, v1.z );
  20919. idx = idx + 1;
  20920. position.setXYZ( idx, v2.x, v2.y, v2.z );
  20921. idx = idx + 1;
  20922. }
  20923. }
  20924. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  20925. var objPos = objGeometry.attributes.position;
  20926. var objNorm = objGeometry.attributes.normal;
  20927. var idx = 0;
  20928. // for simplicity, ignore index and drawcalls, and render every normal
  20929. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  20930. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  20931. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  20932. v2.applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  20933. position.setXYZ( idx, v1.x, v1.y, v1.z );
  20934. idx = idx + 1;
  20935. position.setXYZ( idx, v2.x, v2.y, v2.z );
  20936. idx = idx + 1;
  20937. }
  20938. }
  20939. position.needsUpdate = true;
  20940. return this;
  20941. }
  20942. }());
  20943. // File:src/extras/helpers/VertexTangentsHelper.js
  20944. /**
  20945. * @author mrdoob / http://mrdoob.com/
  20946. * @author WestLangley / http://github.com/WestLangley
  20947. */
  20948. THREE.VertexTangentsHelper = function ( object, size, hex, linewidth ) {
  20949. this.object = object;
  20950. this.size = ( size !== undefined ) ? size : 1;
  20951. var color = ( hex !== undefined ) ? hex : 0x0000ff;
  20952. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20953. //
  20954. var nTangents = 0;
  20955. var objGeometry = this.object.geometry;
  20956. if ( objGeometry instanceof THREE.Geometry ) {
  20957. nTangents = objGeometry.faces.length * 3;
  20958. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  20959. nTangents = objGeometry.attributes.tangent.count
  20960. }
  20961. //
  20962. var geometry = new THREE.BufferGeometry();
  20963. var positions = new THREE.Float32Attribute( nTangents * 2 * 3, 3 );
  20964. geometry.addAttribute( 'position', positions );
  20965. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20966. //
  20967. this.matrixAutoUpdate = false;
  20968. this.update();
  20969. };
  20970. THREE.VertexTangentsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20971. THREE.VertexTangentsHelper.prototype.constructor = THREE.VertexTangentsHelper;
  20972. THREE.VertexTangentsHelper.prototype.update = ( function ( object ) {
  20973. var v1 = new THREE.Vector3();
  20974. var v2 = new THREE.Vector3();
  20975. return function() {
  20976. var keys = [ 'a', 'b', 'c' ];
  20977. this.object.updateMatrixWorld( true );
  20978. var matrixWorld = this.object.matrixWorld;
  20979. var position = this.geometry.attributes.position;
  20980. //
  20981. var objGeometry = this.object.geometry;
  20982. if ( objGeometry instanceof THREE.Geometry ) {
  20983. var vertices = objGeometry.vertices;
  20984. var faces = objGeometry.faces;
  20985. var idx = 0;
  20986. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20987. var face = faces[ i ];
  20988. for ( var j = 0, jl = face.vertexTangents.length; j < jl; j ++ ) {
  20989. var vertex = vertices[ face[ keys[ j ] ] ];
  20990. var tangent = face.vertexTangents[ j ];
  20991. v1.copy( vertex ).applyMatrix4( matrixWorld );
  20992. v2.set( tangent.x, tangent.y, tangent.z ); // tangent.w used for bitangents only
  20993. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  20994. position.setXYZ( idx, v1.x, v1.y, v1.z );
  20995. idx = idx + 1;
  20996. position.setXYZ( idx, v2.x, v2.y, v2.z );
  20997. idx = idx + 1;
  20998. }
  20999. }
  21000. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21001. var objPos = objGeometry.attributes.position;
  21002. var objTan = objGeometry.attributes.tangent;
  21003. var idx = 0;
  21004. // for simplicity, ignore index and drawcalls, and render every tangent
  21005. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21006. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21007. v2.set( objTan.getX( j ), objTan.getY( j ), objTan.getZ( j ) ); // tangent.w used for bitangents only
  21008. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  21009. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21010. idx = idx + 1;
  21011. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21012. idx = idx + 1;
  21013. }
  21014. }
  21015. position.needsUpdate = true;
  21016. return this;
  21017. }
  21018. }());
  21019. // File:src/extras/helpers/WireframeHelper.js
  21020. /**
  21021. * @author mrdoob / http://mrdoob.com/
  21022. */
  21023. THREE.WireframeHelper = function ( object, hex ) {
  21024. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21025. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  21026. this.matrix = object.matrixWorld;
  21027. this.matrixAutoUpdate = false;
  21028. };
  21029. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21030. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  21031. // File:src/extras/objects/ImmediateRenderObject.js
  21032. /**
  21033. * @author alteredq / http://alteredqualia.com/
  21034. */
  21035. THREE.ImmediateRenderObject = function () {
  21036. THREE.Object3D.call( this );
  21037. this.render = function ( renderCallback ) {};
  21038. };
  21039. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  21040. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  21041. // File:src/extras/objects/MorphBlendMesh.js
  21042. /**
  21043. * @author alteredq / http://alteredqualia.com/
  21044. */
  21045. THREE.MorphBlendMesh = function( geometry, material ) {
  21046. THREE.Mesh.call( this, geometry, material );
  21047. this.animationsMap = {};
  21048. this.animationsList = [];
  21049. // prepare default animation
  21050. // (all frames played together in 1 second)
  21051. var numFrames = this.geometry.morphTargets.length;
  21052. var name = "__default";
  21053. var startFrame = 0;
  21054. var endFrame = numFrames - 1;
  21055. var fps = numFrames / 1;
  21056. this.createAnimation( name, startFrame, endFrame, fps );
  21057. this.setAnimationWeight( name, 1 );
  21058. };
  21059. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  21060. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21061. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21062. var animation = {
  21063. startFrame: start,
  21064. endFrame: end,
  21065. length: end - start + 1,
  21066. fps: fps,
  21067. duration: ( end - start ) / fps,
  21068. lastFrame: 0,
  21069. currentFrame: 0,
  21070. active: false,
  21071. time: 0,
  21072. direction: 1,
  21073. weight: 1,
  21074. directionBackwards: false,
  21075. mirroredLoop: false
  21076. };
  21077. this.animationsMap[ name ] = animation;
  21078. this.animationsList.push( animation );
  21079. };
  21080. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21081. var pattern = /([a-z]+)_?(\d+)/;
  21082. var firstAnimation, frameRanges = {};
  21083. var geometry = this.geometry;
  21084. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21085. var morph = geometry.morphTargets[ i ];
  21086. var chunks = morph.name.match( pattern );
  21087. if ( chunks && chunks.length > 1 ) {
  21088. var name = chunks[ 1 ];
  21089. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  21090. var range = frameRanges[ name ];
  21091. if ( i < range.start ) range.start = i;
  21092. if ( i > range.end ) range.end = i;
  21093. if ( ! firstAnimation ) firstAnimation = name;
  21094. }
  21095. }
  21096. for ( var name in frameRanges ) {
  21097. var range = frameRanges[ name ];
  21098. this.createAnimation( name, range.start, range.end, fps );
  21099. }
  21100. this.firstAnimation = firstAnimation;
  21101. };
  21102. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21103. var animation = this.animationsMap[ name ];
  21104. if ( animation ) {
  21105. animation.direction = 1;
  21106. animation.directionBackwards = false;
  21107. }
  21108. };
  21109. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21110. var animation = this.animationsMap[ name ];
  21111. if ( animation ) {
  21112. animation.direction = - 1;
  21113. animation.directionBackwards = true;
  21114. }
  21115. };
  21116. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21117. var animation = this.animationsMap[ name ];
  21118. if ( animation ) {
  21119. animation.fps = fps;
  21120. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21121. }
  21122. };
  21123. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21124. var animation = this.animationsMap[ name ];
  21125. if ( animation ) {
  21126. animation.duration = duration;
  21127. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21128. }
  21129. };
  21130. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21131. var animation = this.animationsMap[ name ];
  21132. if ( animation ) {
  21133. animation.weight = weight;
  21134. }
  21135. };
  21136. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  21137. var animation = this.animationsMap[ name ];
  21138. if ( animation ) {
  21139. animation.time = time;
  21140. }
  21141. };
  21142. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  21143. var time = 0;
  21144. var animation = this.animationsMap[ name ];
  21145. if ( animation ) {
  21146. time = animation.time;
  21147. }
  21148. return time;
  21149. };
  21150. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  21151. var duration = - 1;
  21152. var animation = this.animationsMap[ name ];
  21153. if ( animation ) {
  21154. duration = animation.duration;
  21155. }
  21156. return duration;
  21157. };
  21158. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  21159. var animation = this.animationsMap[ name ];
  21160. if ( animation ) {
  21161. animation.time = 0;
  21162. animation.active = true;
  21163. } else {
  21164. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  21165. }
  21166. };
  21167. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  21168. var animation = this.animationsMap[ name ];
  21169. if ( animation ) {
  21170. animation.active = false;
  21171. }
  21172. };
  21173. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  21174. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  21175. var animation = this.animationsList[ i ];
  21176. if ( ! animation.active ) continue;
  21177. var frameTime = animation.duration / animation.length;
  21178. animation.time += animation.direction * delta;
  21179. if ( animation.mirroredLoop ) {
  21180. if ( animation.time > animation.duration || animation.time < 0 ) {
  21181. animation.direction *= - 1;
  21182. if ( animation.time > animation.duration ) {
  21183. animation.time = animation.duration;
  21184. animation.directionBackwards = true;
  21185. }
  21186. if ( animation.time < 0 ) {
  21187. animation.time = 0;
  21188. animation.directionBackwards = false;
  21189. }
  21190. }
  21191. } else {
  21192. animation.time = animation.time % animation.duration;
  21193. if ( animation.time < 0 ) animation.time += animation.duration;
  21194. }
  21195. var keyframe = animation.startFrame + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  21196. var weight = animation.weight;
  21197. if ( keyframe !== animation.currentFrame ) {
  21198. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  21199. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  21200. this.morphTargetInfluences[ keyframe ] = 0;
  21201. animation.lastFrame = animation.currentFrame;
  21202. animation.currentFrame = keyframe;
  21203. }
  21204. var mix = ( animation.time % frameTime ) / frameTime;
  21205. if ( animation.directionBackwards ) mix = 1 - mix;
  21206. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  21207. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  21208. }
  21209. };