three.js 792 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321
  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 () {
  22. callback( currTime + timeToCall );
  23. }, timeToCall );
  24. lastTime = currTime + timeToCall;
  25. return id;
  26. };
  27. }
  28. if ( self.cancelAnimationFrame === undefined && self.clearTimeout !== undefined ) {
  29. self.cancelAnimationFrame = function ( id ) {
  30. self.clearTimeout( id );
  31. };
  32. }
  33. }() );
  34. if ( Math.sign === undefined ) {
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  36. Math.sign = function ( x ) {
  37. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  38. };
  39. }
  40. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  41. // Missing in IE9-11.
  42. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  43. Object.defineProperty( Function.prototype, 'name', {
  44. get: function () {
  45. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  46. }
  47. } );
  48. }
  49. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  50. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  51. // GL STATE CONSTANTS
  52. THREE.CullFaceNone = 0;
  53. THREE.CullFaceBack = 1;
  54. THREE.CullFaceFront = 2;
  55. THREE.CullFaceFrontBack = 3;
  56. THREE.FrontFaceDirectionCW = 0;
  57. THREE.FrontFaceDirectionCCW = 1;
  58. // SHADOWING TYPES
  59. THREE.BasicShadowMap = 0;
  60. THREE.PCFShadowMap = 1;
  61. THREE.PCFSoftShadowMap = 2;
  62. // MATERIAL CONSTANTS
  63. // side
  64. THREE.FrontSide = 0;
  65. THREE.BackSide = 1;
  66. THREE.DoubleSide = 2;
  67. // shading
  68. THREE.NoShading = 0;
  69. THREE.FlatShading = 1;
  70. THREE.SmoothShading = 2;
  71. // colors
  72. THREE.NoColors = 0;
  73. THREE.FaceColors = 1;
  74. THREE.VertexColors = 2;
  75. // blending modes
  76. THREE.NoBlending = 0;
  77. THREE.NormalBlending = 1;
  78. THREE.AdditiveBlending = 2;
  79. THREE.SubtractiveBlending = 3;
  80. THREE.MultiplyBlending = 4;
  81. THREE.CustomBlending = 5;
  82. // custom blending equations
  83. // (numbers start from 100 not to clash with other
  84. // mappings to OpenGL constants defined in Texture.js)
  85. THREE.AddEquation = 100;
  86. THREE.SubtractEquation = 101;
  87. THREE.ReverseSubtractEquation = 102;
  88. THREE.MinEquation = 103;
  89. THREE.MaxEquation = 104;
  90. // custom blending destination factors
  91. THREE.ZeroFactor = 200;
  92. THREE.OneFactor = 201;
  93. THREE.SrcColorFactor = 202;
  94. THREE.OneMinusSrcColorFactor = 203;
  95. THREE.SrcAlphaFactor = 204;
  96. THREE.OneMinusSrcAlphaFactor = 205;
  97. THREE.DstAlphaFactor = 206;
  98. THREE.OneMinusDstAlphaFactor = 207;
  99. // custom blending source factors
  100. //THREE.ZeroFactor = 200;
  101. //THREE.OneFactor = 201;
  102. //THREE.SrcAlphaFactor = 204;
  103. //THREE.OneMinusSrcAlphaFactor = 205;
  104. //THREE.DstAlphaFactor = 206;
  105. //THREE.OneMinusDstAlphaFactor = 207;
  106. THREE.DstColorFactor = 208;
  107. THREE.OneMinusDstColorFactor = 209;
  108. THREE.SrcAlphaSaturateFactor = 210;
  109. // depth modes
  110. THREE.NeverDepth = 0;
  111. THREE.AlwaysDepth = 1;
  112. THREE.LessDepth = 2;
  113. THREE.LessEqualDepth = 3;
  114. THREE.EqualDepth = 4;
  115. THREE.GreaterEqualDepth = 5;
  116. THREE.GreaterDepth = 6;
  117. THREE.NotEqualDepth = 7;
  118. // TEXTURE CONSTANTS
  119. THREE.MultiplyOperation = 0;
  120. THREE.MixOperation = 1;
  121. THREE.AddOperation = 2;
  122. // Mapping modes
  123. THREE.UVMapping = 300;
  124. THREE.CubeReflectionMapping = 301;
  125. THREE.CubeRefractionMapping = 302;
  126. THREE.EquirectangularReflectionMapping = 303;
  127. THREE.EquirectangularRefractionMapping = 304;
  128. THREE.SphericalReflectionMapping = 305;
  129. // Wrapping modes
  130. THREE.RepeatWrapping = 1000;
  131. THREE.ClampToEdgeWrapping = 1001;
  132. THREE.MirroredRepeatWrapping = 1002;
  133. // Filters
  134. THREE.NearestFilter = 1003;
  135. THREE.NearestMipMapNearestFilter = 1004;
  136. THREE.NearestMipMapLinearFilter = 1005;
  137. THREE.LinearFilter = 1006;
  138. THREE.LinearMipMapNearestFilter = 1007;
  139. THREE.LinearMipMapLinearFilter = 1008;
  140. // Data types
  141. THREE.UnsignedByteType = 1009;
  142. THREE.ByteType = 1010;
  143. THREE.ShortType = 1011;
  144. THREE.UnsignedShortType = 1012;
  145. THREE.IntType = 1013;
  146. THREE.UnsignedIntType = 1014;
  147. THREE.FloatType = 1015;
  148. THREE.HalfFloatType = 1025;
  149. // Pixel types
  150. //THREE.UnsignedByteType = 1009;
  151. THREE.UnsignedShort4444Type = 1016;
  152. THREE.UnsignedShort5551Type = 1017;
  153. THREE.UnsignedShort565Type = 1018;
  154. // Pixel formats
  155. THREE.AlphaFormat = 1019;
  156. THREE.RGBFormat = 1020;
  157. THREE.RGBAFormat = 1021;
  158. THREE.LuminanceFormat = 1022;
  159. THREE.LuminanceAlphaFormat = 1023;
  160. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  161. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  162. // DDS / ST3C Compressed texture formats
  163. THREE.RGB_S3TC_DXT1_Format = 2001;
  164. THREE.RGBA_S3TC_DXT1_Format = 2002;
  165. THREE.RGBA_S3TC_DXT3_Format = 2003;
  166. THREE.RGBA_S3TC_DXT5_Format = 2004;
  167. // PVRTC compressed texture formats
  168. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  169. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  170. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  171. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  172. // DEPRECATED
  173. THREE.Projector = function () {
  174. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  175. this.projectVector = function ( vector, camera ) {
  176. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  177. vector.project( camera );
  178. };
  179. this.unprojectVector = function ( vector, camera ) {
  180. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  181. vector.unproject( camera );
  182. };
  183. this.pickingRay = function ( vector, camera ) {
  184. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  185. };
  186. };
  187. THREE.CanvasRenderer = function () {
  188. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  189. this.domElement = document.createElement( 'canvas' );
  190. this.clear = function () {};
  191. this.render = function () {};
  192. this.setClearColor = function () {};
  193. this.setSize = function () {};
  194. };
  195. // File:src/math/Color.js
  196. /**
  197. * @author mrdoob / http://mrdoob.com/
  198. */
  199. THREE.Color = function ( color ) {
  200. if ( arguments.length === 3 ) {
  201. return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
  202. }
  203. return this.set( color );
  204. };
  205. THREE.Color.prototype = {
  206. constructor: THREE.Color,
  207. r: 1, g: 1, b: 1,
  208. set: function ( value ) {
  209. if ( value instanceof THREE.Color ) {
  210. this.copy( value );
  211. } else if ( typeof value === 'number' ) {
  212. this.setHex( value );
  213. } else if ( typeof value === 'string' ) {
  214. this.setStyle( value );
  215. }
  216. return this;
  217. },
  218. setHex: function ( hex ) {
  219. hex = Math.floor( hex );
  220. this.r = ( hex >> 16 & 255 ) / 255;
  221. this.g = ( hex >> 8 & 255 ) / 255;
  222. this.b = ( hex & 255 ) / 255;
  223. return this;
  224. },
  225. setRGB: function ( r, g, b ) {
  226. this.r = r;
  227. this.g = g;
  228. this.b = b;
  229. return this;
  230. },
  231. setHSL: function () {
  232. function hue2rgb ( p, q, t ) {
  233. if ( t < 0 ) t += 1;
  234. if ( t > 1 ) t -= 1;
  235. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  236. if ( t < 1 / 2 ) return q;
  237. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  238. return p;
  239. }
  240. return function ( h, s, l ) {
  241. // h,s,l ranges are in 0.0 - 1.0
  242. h = THREE.Math.euclideanModulo( h, 1 );
  243. s = THREE.Math.clamp( s, 0, 1 );
  244. l = THREE.Math.clamp( l, 0, 1 );
  245. if ( s === 0 ) {
  246. this.r = this.g = this.b = l;
  247. } else {
  248. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  249. var q = ( 2 * l ) - p;
  250. this.r = hue2rgb( q, p, h + 1 / 3 );
  251. this.g = hue2rgb( q, p, h );
  252. this.b = hue2rgb( q, p, h - 1 / 3 );
  253. }
  254. return this;
  255. };
  256. }(),
  257. setStyle: function ( style ) {
  258. var parseAlpha = function ( strAlpha ) {
  259. var alpha = parseFloat( strAlpha );
  260. if ( alpha < 1 ) {
  261. console.warn( 'THREE.Color: Alpha component of color ' + style + ' will be ignored.' );
  262. }
  263. return alpha;
  264. }
  265. var m;
  266. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  267. // rgb / hsl
  268. var color;
  269. var name = m[ 1 ];
  270. var components = m[ 2 ];
  271. switch ( name ) {
  272. case 'rgb':
  273. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*$/.exec( components ) ) {
  274. // rgb(255,0,0)
  275. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  276. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  277. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  278. return this;
  279. }
  280. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  281. // rgb(100%,0%,0%)
  282. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  283. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  284. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  285. return this;
  286. }
  287. break;
  288. case 'rgba':
  289. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  290. // rgba(255,0,0,0.5)
  291. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  292. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  293. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  294. parseAlpha( color[ 4 ] );
  295. return this;
  296. }
  297. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  298. // rgba(100%,0%,0%,0.5)
  299. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  300. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  301. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  302. parseAlpha( color[ 4 ] );
  303. return this;
  304. }
  305. break;
  306. case 'hsl':
  307. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  308. // hsl(120,50%,50%)
  309. var h = parseFloat( color[ 1 ] );
  310. var s = parseInt( color[ 2 ], 10 ) / 100;
  311. var l = parseInt( color[ 3 ], 10 ) / 100;
  312. return this.setHSL( h, s, l );
  313. }
  314. break;
  315. case 'hsla':
  316. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  317. // hsla(120,50%,50%,0.5)
  318. var h = parseFloat( color[ 1 ] );
  319. var s = parseInt( color[ 2 ], 10 ) / 100;
  320. var l = parseInt( color[ 3 ], 10 ) / 100;
  321. parseAlpha( color[ 4 ] );
  322. return this.setHSL( h, s, l );
  323. }
  324. break;
  325. }
  326. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  327. // hex color
  328. var hex = m[ 1 ];
  329. var size = hex.length;
  330. if ( size === 3 ) {
  331. // #ff0
  332. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  333. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  334. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  335. return this;
  336. } else if ( size === 6 ) {
  337. // #ff0000
  338. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  339. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  340. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  341. return this;
  342. }
  343. }
  344. if ( style && style.length > 0 ) {
  345. // color keywords
  346. var hex = THREE.ColorKeywords[ style ];
  347. if ( hex !== undefined ) {
  348. // red
  349. this.setHex( hex );
  350. } else {
  351. // unknown color
  352. console.warn( 'THREE.Color: Unknown color ' + style );
  353. }
  354. }
  355. return this;
  356. },
  357. copy: function ( color ) {
  358. this.r = color.r;
  359. this.g = color.g;
  360. this.b = color.b;
  361. return this;
  362. },
  363. copyGammaToLinear: function ( color, gammaFactor ) {
  364. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  365. this.r = Math.pow( color.r, gammaFactor );
  366. this.g = Math.pow( color.g, gammaFactor );
  367. this.b = Math.pow( color.b, gammaFactor );
  368. return this;
  369. },
  370. copyLinearToGamma: function ( color, gammaFactor ) {
  371. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  372. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  373. this.r = Math.pow( color.r, safeInverse );
  374. this.g = Math.pow( color.g, safeInverse );
  375. this.b = Math.pow( color.b, safeInverse );
  376. return this;
  377. },
  378. convertGammaToLinear: function () {
  379. var r = this.r, g = this.g, b = this.b;
  380. this.r = r * r;
  381. this.g = g * g;
  382. this.b = b * b;
  383. return this;
  384. },
  385. convertLinearToGamma: function () {
  386. this.r = Math.sqrt( this.r );
  387. this.g = Math.sqrt( this.g );
  388. this.b = Math.sqrt( this.b );
  389. return this;
  390. },
  391. getHex: function () {
  392. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  393. },
  394. getHexString: function () {
  395. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  396. },
  397. getHSL: function ( optionalTarget ) {
  398. // h,s,l ranges are in 0.0 - 1.0
  399. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  400. var r = this.r, g = this.g, b = this.b;
  401. var max = Math.max( r, g, b );
  402. var min = Math.min( r, g, b );
  403. var hue, saturation;
  404. var lightness = ( min + max ) / 2.0;
  405. if ( min === max ) {
  406. hue = 0;
  407. saturation = 0;
  408. } else {
  409. var delta = max - min;
  410. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  411. switch ( max ) {
  412. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  413. case g: hue = ( b - r ) / delta + 2; break;
  414. case b: hue = ( r - g ) / delta + 4; break;
  415. }
  416. hue /= 6;
  417. }
  418. hsl.h = hue;
  419. hsl.s = saturation;
  420. hsl.l = lightness;
  421. return hsl;
  422. },
  423. getStyle: function () {
  424. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  425. },
  426. offsetHSL: function ( h, s, l ) {
  427. var hsl = this.getHSL();
  428. hsl.h += h; hsl.s += s; hsl.l += l;
  429. this.setHSL( hsl.h, hsl.s, hsl.l );
  430. return this;
  431. },
  432. add: function ( color ) {
  433. this.r += color.r;
  434. this.g += color.g;
  435. this.b += color.b;
  436. return this;
  437. },
  438. addColors: function ( color1, color2 ) {
  439. this.r = color1.r + color2.r;
  440. this.g = color1.g + color2.g;
  441. this.b = color1.b + color2.b;
  442. return this;
  443. },
  444. addScalar: function ( s ) {
  445. this.r += s;
  446. this.g += s;
  447. this.b += s;
  448. return this;
  449. },
  450. multiply: function ( color ) {
  451. this.r *= color.r;
  452. this.g *= color.g;
  453. this.b *= color.b;
  454. return this;
  455. },
  456. multiplyScalar: function ( s ) {
  457. this.r *= s;
  458. this.g *= s;
  459. this.b *= s;
  460. return this;
  461. },
  462. lerp: function ( color, alpha ) {
  463. this.r += ( color.r - this.r ) * alpha;
  464. this.g += ( color.g - this.g ) * alpha;
  465. this.b += ( color.b - this.b ) * alpha;
  466. return this;
  467. },
  468. equals: function ( c ) {
  469. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  470. },
  471. fromArray: function ( array ) {
  472. this.r = array[ 0 ];
  473. this.g = array[ 1 ];
  474. this.b = array[ 2 ];
  475. return this;
  476. },
  477. toArray: function ( array, offset ) {
  478. if ( array === undefined ) array = [];
  479. if ( offset === undefined ) offset = 0;
  480. array[ offset ] = this.r;
  481. array[ offset + 1 ] = this.g;
  482. array[ offset + 2 ] = this.b;
  483. return array;
  484. },
  485. clone: function () {
  486. return new THREE.Color().copy( this );
  487. }
  488. };
  489. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  490. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  491. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  492. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  493. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  494. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  495. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  496. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  497. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  498. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  499. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  500. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  501. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  502. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  503. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  504. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  505. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  506. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  507. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  508. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  509. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  510. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  511. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  512. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  513. // File:src/math/Quaternion.js
  514. /**
  515. * @author mikael emtinger / http://gomo.se/
  516. * @author alteredq / http://alteredqualia.com/
  517. * @author WestLangley / http://github.com/WestLangley
  518. * @author bhouston / http://exocortex.com
  519. */
  520. THREE.Quaternion = function ( x, y, z, w ) {
  521. this._x = x || 0;
  522. this._y = y || 0;
  523. this._z = z || 0;
  524. this._w = ( w !== undefined ) ? w : 1;
  525. };
  526. THREE.Quaternion.prototype = {
  527. constructor: THREE.Quaternion,
  528. get x () {
  529. return this._x;
  530. },
  531. set x ( value ) {
  532. this._x = value;
  533. this.onChangeCallback();
  534. },
  535. get y () {
  536. return this._y;
  537. },
  538. set y ( value ) {
  539. this._y = value;
  540. this.onChangeCallback();
  541. },
  542. get z () {
  543. return this._z;
  544. },
  545. set z ( value ) {
  546. this._z = value;
  547. this.onChangeCallback();
  548. },
  549. get w () {
  550. return this._w;
  551. },
  552. set w ( value ) {
  553. this._w = value;
  554. this.onChangeCallback();
  555. },
  556. set: function ( x, y, z, w ) {
  557. this._x = x;
  558. this._y = y;
  559. this._z = z;
  560. this._w = w;
  561. this.onChangeCallback();
  562. return this;
  563. },
  564. copy: function ( quaternion ) {
  565. this._x = quaternion.x;
  566. this._y = quaternion.y;
  567. this._z = quaternion.z;
  568. this._w = quaternion.w;
  569. this.onChangeCallback();
  570. return this;
  571. },
  572. setFromEuler: function ( euler, update ) {
  573. if ( euler instanceof THREE.Euler === false ) {
  574. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  575. }
  576. // http://www.mathworks.com/matlabcentral/fileexchange/
  577. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  578. // content/SpinCalc.m
  579. var c1 = Math.cos( euler._x / 2 );
  580. var c2 = Math.cos( euler._y / 2 );
  581. var c3 = Math.cos( euler._z / 2 );
  582. var s1 = Math.sin( euler._x / 2 );
  583. var s2 = Math.sin( euler._y / 2 );
  584. var s3 = Math.sin( euler._z / 2 );
  585. if ( euler.order === 'XYZ' ) {
  586. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  587. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  588. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  589. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  590. } else if ( euler.order === 'YXZ' ) {
  591. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  592. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  593. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  594. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  595. } else if ( euler.order === 'ZXY' ) {
  596. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  597. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  598. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  599. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  600. } else if ( euler.order === 'ZYX' ) {
  601. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  602. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  603. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  604. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  605. } else if ( euler.order === 'YZX' ) {
  606. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  607. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  608. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  609. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  610. } else if ( euler.order === 'XZY' ) {
  611. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  612. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  613. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  614. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  615. }
  616. if ( update !== false ) this.onChangeCallback();
  617. return this;
  618. },
  619. setFromAxisAngle: function ( axis, angle ) {
  620. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  621. // assumes axis is normalized
  622. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  623. this._x = axis.x * s;
  624. this._y = axis.y * s;
  625. this._z = axis.z * s;
  626. this._w = Math.cos( halfAngle );
  627. this.onChangeCallback();
  628. return this;
  629. },
  630. setFromRotationMatrix: function ( m ) {
  631. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  632. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  633. var te = m.elements,
  634. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  635. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  636. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  637. trace = m11 + m22 + m33,
  638. s;
  639. if ( trace > 0 ) {
  640. s = 0.5 / Math.sqrt( trace + 1.0 );
  641. this._w = 0.25 / s;
  642. this._x = ( m32 - m23 ) * s;
  643. this._y = ( m13 - m31 ) * s;
  644. this._z = ( m21 - m12 ) * s;
  645. } else if ( m11 > m22 && m11 > m33 ) {
  646. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  647. this._w = ( m32 - m23 ) / s;
  648. this._x = 0.25 * s;
  649. this._y = ( m12 + m21 ) / s;
  650. this._z = ( m13 + m31 ) / s;
  651. } else if ( m22 > m33 ) {
  652. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  653. this._w = ( m13 - m31 ) / s;
  654. this._x = ( m12 + m21 ) / s;
  655. this._y = 0.25 * s;
  656. this._z = ( m23 + m32 ) / s;
  657. } else {
  658. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  659. this._w = ( m21 - m12 ) / s;
  660. this._x = ( m13 + m31 ) / s;
  661. this._y = ( m23 + m32 ) / s;
  662. this._z = 0.25 * s;
  663. }
  664. this.onChangeCallback();
  665. return this;
  666. },
  667. setFromUnitVectors: function () {
  668. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  669. // assumes direction vectors vFrom and vTo are normalized
  670. var v1, r;
  671. var EPS = 0.000001;
  672. return function ( vFrom, vTo ) {
  673. if ( v1 === undefined ) v1 = new THREE.Vector3();
  674. r = vFrom.dot( vTo ) + 1;
  675. if ( r < EPS ) {
  676. r = 0;
  677. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  678. v1.set( - vFrom.y, vFrom.x, 0 );
  679. } else {
  680. v1.set( 0, - vFrom.z, vFrom.y );
  681. }
  682. } else {
  683. v1.crossVectors( vFrom, vTo );
  684. }
  685. this._x = v1.x;
  686. this._y = v1.y;
  687. this._z = v1.z;
  688. this._w = r;
  689. this.normalize();
  690. return this;
  691. }
  692. }(),
  693. inverse: function () {
  694. this.conjugate().normalize();
  695. return this;
  696. },
  697. conjugate: function () {
  698. this._x *= - 1;
  699. this._y *= - 1;
  700. this._z *= - 1;
  701. this.onChangeCallback();
  702. return this;
  703. },
  704. dot: function ( v ) {
  705. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  706. },
  707. lengthSq: function () {
  708. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  709. },
  710. length: function () {
  711. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  712. },
  713. normalize: function () {
  714. var l = this.length();
  715. if ( l === 0 ) {
  716. this._x = 0;
  717. this._y = 0;
  718. this._z = 0;
  719. this._w = 1;
  720. } else {
  721. l = 1 / l;
  722. this._x = this._x * l;
  723. this._y = this._y * l;
  724. this._z = this._z * l;
  725. this._w = this._w * l;
  726. }
  727. this.onChangeCallback();
  728. return this;
  729. },
  730. multiply: function ( q, p ) {
  731. if ( p !== undefined ) {
  732. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  733. return this.multiplyQuaternions( q, p );
  734. }
  735. return this.multiplyQuaternions( this, q );
  736. },
  737. multiplyQuaternions: function ( a, b ) {
  738. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  739. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  740. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  741. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  742. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  743. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  744. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  745. this.onChangeCallback();
  746. return this;
  747. },
  748. multiplyVector3: function ( vector ) {
  749. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  750. return vector.applyQuaternion( this );
  751. },
  752. slerp: function ( qb, t ) {
  753. if ( t === 0 ) return this;
  754. if ( t === 1 ) return this.copy( qb );
  755. var x = this._x, y = this._y, z = this._z, w = this._w;
  756. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  757. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  758. if ( cosHalfTheta < 0 ) {
  759. this._w = - qb._w;
  760. this._x = - qb._x;
  761. this._y = - qb._y;
  762. this._z = - qb._z;
  763. cosHalfTheta = - cosHalfTheta;
  764. } else {
  765. this.copy( qb );
  766. }
  767. if ( cosHalfTheta >= 1.0 ) {
  768. this._w = w;
  769. this._x = x;
  770. this._y = y;
  771. this._z = z;
  772. return this;
  773. }
  774. var halfTheta = Math.acos( cosHalfTheta );
  775. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  776. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  777. this._w = 0.5 * ( w + this._w );
  778. this._x = 0.5 * ( x + this._x );
  779. this._y = 0.5 * ( y + this._y );
  780. this._z = 0.5 * ( z + this._z );
  781. return this;
  782. }
  783. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  784. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  785. this._w = ( w * ratioA + this._w * ratioB );
  786. this._x = ( x * ratioA + this._x * ratioB );
  787. this._y = ( y * ratioA + this._y * ratioB );
  788. this._z = ( z * ratioA + this._z * ratioB );
  789. this.onChangeCallback();
  790. return this;
  791. },
  792. equals: function ( quaternion ) {
  793. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  794. },
  795. fromArray: function ( array, offset ) {
  796. if ( offset === undefined ) offset = 0;
  797. this._x = array[ offset ];
  798. this._y = array[ offset + 1 ];
  799. this._z = array[ offset + 2 ];
  800. this._w = array[ offset + 3 ];
  801. this.onChangeCallback();
  802. return this;
  803. },
  804. toArray: function ( array, offset ) {
  805. if ( array === undefined ) array = [];
  806. if ( offset === undefined ) offset = 0;
  807. array[ offset ] = this._x;
  808. array[ offset + 1 ] = this._y;
  809. array[ offset + 2 ] = this._z;
  810. array[ offset + 3 ] = this._w;
  811. return array;
  812. },
  813. onChange: function ( callback ) {
  814. this.onChangeCallback = callback;
  815. return this;
  816. },
  817. onChangeCallback: function () {},
  818. clone: function () {
  819. return new THREE.Quaternion( this._x, this._y, this._z, this._w );
  820. }
  821. };
  822. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  823. return qm.copy( qa ).slerp( qb, t );
  824. };
  825. // File:src/math/Vector2.js
  826. /**
  827. * @author mrdoob / http://mrdoob.com/
  828. * @author philogb / http://blog.thejit.org/
  829. * @author egraether / http://egraether.com/
  830. * @author zz85 / http://www.lab4games.net/zz85/blog
  831. */
  832. THREE.Vector2 = function ( x, y ) {
  833. this.x = x || 0;
  834. this.y = y || 0;
  835. };
  836. THREE.Vector2.prototype = {
  837. constructor: THREE.Vector2,
  838. set: function ( x, y ) {
  839. this.x = x;
  840. this.y = y;
  841. return this;
  842. },
  843. setX: function ( x ) {
  844. this.x = x;
  845. return this;
  846. },
  847. setY: function ( y ) {
  848. this.y = y;
  849. return this;
  850. },
  851. setComponent: function ( index, value ) {
  852. switch ( index ) {
  853. case 0: this.x = value; break;
  854. case 1: this.y = value; break;
  855. default: throw new Error( 'index is out of range: ' + index );
  856. }
  857. },
  858. getComponent: function ( index ) {
  859. switch ( index ) {
  860. case 0: return this.x;
  861. case 1: return this.y;
  862. default: throw new Error( 'index is out of range: ' + index );
  863. }
  864. },
  865. copy: function ( v ) {
  866. this.x = v.x;
  867. this.y = v.y;
  868. return this;
  869. },
  870. add: function ( v, w ) {
  871. if ( w !== undefined ) {
  872. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  873. return this.addVectors( v, w );
  874. }
  875. this.x += v.x;
  876. this.y += v.y;
  877. return this;
  878. },
  879. addScalar: function ( s ) {
  880. this.x += s;
  881. this.y += s;
  882. return this;
  883. },
  884. addVectors: function ( a, b ) {
  885. this.x = a.x + b.x;
  886. this.y = a.y + b.y;
  887. return this;
  888. },
  889. addScaledVector: function ( v, s ) {
  890. this.x += v.x * s;
  891. this.y += v.y * s;
  892. return this;
  893. },
  894. sub: function ( v, w ) {
  895. if ( w !== undefined ) {
  896. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  897. return this.subVectors( v, w );
  898. }
  899. this.x -= v.x;
  900. this.y -= v.y;
  901. return this;
  902. },
  903. subScalar: function ( s ) {
  904. this.x -= s;
  905. this.y -= s;
  906. return this;
  907. },
  908. subVectors: function ( a, b ) {
  909. this.x = a.x - b.x;
  910. this.y = a.y - b.y;
  911. return this;
  912. },
  913. multiply: function ( v ) {
  914. this.x *= v.x;
  915. this.y *= v.y;
  916. return this;
  917. },
  918. multiplyScalar: function ( s ) {
  919. this.x *= s;
  920. this.y *= s;
  921. return this;
  922. },
  923. divide: function ( v ) {
  924. this.x /= v.x;
  925. this.y /= v.y;
  926. return this;
  927. },
  928. divideScalar: function ( scalar ) {
  929. if ( scalar !== 0 ) {
  930. var invScalar = 1 / scalar;
  931. this.x *= invScalar;
  932. this.y *= invScalar;
  933. } else {
  934. this.x = 0;
  935. this.y = 0;
  936. }
  937. return this;
  938. },
  939. min: function ( v ) {
  940. if ( this.x > v.x ) {
  941. this.x = v.x;
  942. }
  943. if ( this.y > v.y ) {
  944. this.y = v.y;
  945. }
  946. return this;
  947. },
  948. max: function ( v ) {
  949. if ( this.x < v.x ) {
  950. this.x = v.x;
  951. }
  952. if ( this.y < v.y ) {
  953. this.y = v.y;
  954. }
  955. return this;
  956. },
  957. clamp: function ( min, max ) {
  958. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  959. if ( this.x < min.x ) {
  960. this.x = min.x;
  961. } else if ( this.x > max.x ) {
  962. this.x = max.x;
  963. }
  964. if ( this.y < min.y ) {
  965. this.y = min.y;
  966. } else if ( this.y > max.y ) {
  967. this.y = max.y;
  968. }
  969. return this;
  970. },
  971. clampScalar: function () {
  972. var min, max;
  973. return function clampScalar( minVal, maxVal ) {
  974. if ( min === undefined ) {
  975. min = new THREE.Vector2();
  976. max = new THREE.Vector2();
  977. }
  978. min.set( minVal, minVal );
  979. max.set( maxVal, maxVal );
  980. return this.clamp( min, max );
  981. };
  982. }(),
  983. floor: function () {
  984. this.x = Math.floor( this.x );
  985. this.y = Math.floor( this.y );
  986. return this;
  987. },
  988. ceil: function () {
  989. this.x = Math.ceil( this.x );
  990. this.y = Math.ceil( this.y );
  991. return this;
  992. },
  993. round: function () {
  994. this.x = Math.round( this.x );
  995. this.y = Math.round( this.y );
  996. return this;
  997. },
  998. roundToZero: function () {
  999. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1000. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1001. return this;
  1002. },
  1003. negate: function () {
  1004. this.x = - this.x;
  1005. this.y = - this.y;
  1006. return this;
  1007. },
  1008. dot: function ( v ) {
  1009. return this.x * v.x + this.y * v.y;
  1010. },
  1011. lengthSq: function () {
  1012. return this.x * this.x + this.y * this.y;
  1013. },
  1014. length: function () {
  1015. return Math.sqrt( this.x * this.x + this.y * this.y );
  1016. },
  1017. lengthManhattan: function() {
  1018. return Math.abs( this.x ) + Math.abs( this.y );
  1019. },
  1020. normalize: function () {
  1021. return this.divideScalar( this.length() );
  1022. },
  1023. distanceTo: function ( v ) {
  1024. return Math.sqrt( this.distanceToSquared( v ) );
  1025. },
  1026. distanceToSquared: function ( v ) {
  1027. var dx = this.x - v.x, dy = this.y - v.y;
  1028. return dx * dx + dy * dy;
  1029. },
  1030. setLength: function ( l ) {
  1031. var oldLength = this.length();
  1032. if ( oldLength !== 0 && l !== oldLength ) {
  1033. this.multiplyScalar( l / oldLength );
  1034. }
  1035. return this;
  1036. },
  1037. lerp: function ( v, alpha ) {
  1038. this.x += ( v.x - this.x ) * alpha;
  1039. this.y += ( v.y - this.y ) * alpha;
  1040. return this;
  1041. },
  1042. lerpVectors: function ( v1, v2, alpha ) {
  1043. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1044. return this;
  1045. },
  1046. equals: function ( v ) {
  1047. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1048. },
  1049. fromArray: function ( array, offset ) {
  1050. if ( offset === undefined ) offset = 0;
  1051. this.x = array[ offset ];
  1052. this.y = array[ offset + 1 ];
  1053. return this;
  1054. },
  1055. toArray: function ( array, offset ) {
  1056. if ( array === undefined ) array = [];
  1057. if ( offset === undefined ) offset = 0;
  1058. array[ offset ] = this.x;
  1059. array[ offset + 1 ] = this.y;
  1060. return array;
  1061. },
  1062. fromAttribute: function ( attribute, index, offset ) {
  1063. if ( offset === undefined ) offset = 0;
  1064. index = index * attribute.itemSize + offset;
  1065. this.x = attribute.array[ index ];
  1066. this.y = attribute.array[ index + 1 ];
  1067. return this;
  1068. },
  1069. clone: function () {
  1070. return new THREE.Vector2( this.x, this.y );
  1071. }
  1072. };
  1073. // File:src/math/Vector3.js
  1074. /**
  1075. * @author mrdoob / http://mrdoob.com/
  1076. * @author *kile / http://kile.stravaganza.org/
  1077. * @author philogb / http://blog.thejit.org/
  1078. * @author mikael emtinger / http://gomo.se/
  1079. * @author egraether / http://egraether.com/
  1080. * @author WestLangley / http://github.com/WestLangley
  1081. */
  1082. THREE.Vector3 = function ( x, y, z ) {
  1083. this.x = x || 0;
  1084. this.y = y || 0;
  1085. this.z = z || 0;
  1086. };
  1087. THREE.Vector3.prototype = {
  1088. constructor: THREE.Vector3,
  1089. set: function ( x, y, z ) {
  1090. this.x = x;
  1091. this.y = y;
  1092. this.z = z;
  1093. return this;
  1094. },
  1095. setX: function ( x ) {
  1096. this.x = x;
  1097. return this;
  1098. },
  1099. setY: function ( y ) {
  1100. this.y = y;
  1101. return this;
  1102. },
  1103. setZ: function ( z ) {
  1104. this.z = z;
  1105. return this;
  1106. },
  1107. setComponent: function ( index, value ) {
  1108. switch ( index ) {
  1109. case 0: this.x = value; break;
  1110. case 1: this.y = value; break;
  1111. case 2: this.z = value; break;
  1112. default: throw new Error( 'index is out of range: ' + index );
  1113. }
  1114. },
  1115. getComponent: function ( index ) {
  1116. switch ( index ) {
  1117. case 0: return this.x;
  1118. case 1: return this.y;
  1119. case 2: return this.z;
  1120. default: throw new Error( 'index is out of range: ' + index );
  1121. }
  1122. },
  1123. copy: function ( v ) {
  1124. this.x = v.x;
  1125. this.y = v.y;
  1126. this.z = v.z;
  1127. return this;
  1128. },
  1129. add: function ( v, w ) {
  1130. if ( w !== undefined ) {
  1131. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1132. return this.addVectors( v, w );
  1133. }
  1134. this.x += v.x;
  1135. this.y += v.y;
  1136. this.z += v.z;
  1137. return this;
  1138. },
  1139. addScalar: function ( s ) {
  1140. this.x += s;
  1141. this.y += s;
  1142. this.z += s;
  1143. return this;
  1144. },
  1145. addVectors: function ( a, b ) {
  1146. this.x = a.x + b.x;
  1147. this.y = a.y + b.y;
  1148. this.z = a.z + b.z;
  1149. return this;
  1150. },
  1151. addScaledVector: function ( v, s ) {
  1152. this.x += v.x * s;
  1153. this.y += v.y * s;
  1154. this.z += v.z * s;
  1155. return this;
  1156. },
  1157. sub: function ( v, w ) {
  1158. if ( w !== undefined ) {
  1159. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1160. return this.subVectors( v, w );
  1161. }
  1162. this.x -= v.x;
  1163. this.y -= v.y;
  1164. this.z -= v.z;
  1165. return this;
  1166. },
  1167. subScalar: function ( s ) {
  1168. this.x -= s;
  1169. this.y -= s;
  1170. this.z -= s;
  1171. return this;
  1172. },
  1173. subVectors: function ( a, b ) {
  1174. this.x = a.x - b.x;
  1175. this.y = a.y - b.y;
  1176. this.z = a.z - b.z;
  1177. return this;
  1178. },
  1179. multiply: function ( v, w ) {
  1180. if ( w !== undefined ) {
  1181. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1182. return this.multiplyVectors( v, w );
  1183. }
  1184. this.x *= v.x;
  1185. this.y *= v.y;
  1186. this.z *= v.z;
  1187. return this;
  1188. },
  1189. multiplyScalar: function ( scalar ) {
  1190. this.x *= scalar;
  1191. this.y *= scalar;
  1192. this.z *= scalar;
  1193. return this;
  1194. },
  1195. multiplyVectors: function ( a, b ) {
  1196. this.x = a.x * b.x;
  1197. this.y = a.y * b.y;
  1198. this.z = a.z * b.z;
  1199. return this;
  1200. },
  1201. applyEuler: function () {
  1202. var quaternion;
  1203. return function applyEuler( euler ) {
  1204. if ( euler instanceof THREE.Euler === false ) {
  1205. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1206. }
  1207. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1208. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1209. return this;
  1210. };
  1211. }(),
  1212. applyAxisAngle: function () {
  1213. var quaternion;
  1214. return function applyAxisAngle( axis, angle ) {
  1215. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1216. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1217. return this;
  1218. };
  1219. }(),
  1220. applyMatrix3: function ( m ) {
  1221. var x = this.x;
  1222. var y = this.y;
  1223. var z = this.z;
  1224. var e = m.elements;
  1225. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1226. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1227. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1228. return this;
  1229. },
  1230. applyMatrix4: function ( m ) {
  1231. // input: THREE.Matrix4 affine matrix
  1232. var x = this.x, y = this.y, z = this.z;
  1233. var e = m.elements;
  1234. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1235. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1236. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1237. return this;
  1238. },
  1239. applyProjection: function ( m ) {
  1240. // input: THREE.Matrix4 projection matrix
  1241. var x = this.x, y = this.y, z = this.z;
  1242. var e = m.elements;
  1243. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1244. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1245. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1246. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1247. return this;
  1248. },
  1249. applyQuaternion: function ( q ) {
  1250. var x = this.x;
  1251. var y = this.y;
  1252. var z = this.z;
  1253. var qx = q.x;
  1254. var qy = q.y;
  1255. var qz = q.z;
  1256. var qw = q.w;
  1257. // calculate quat * vector
  1258. var ix = qw * x + qy * z - qz * y;
  1259. var iy = qw * y + qz * x - qx * z;
  1260. var iz = qw * z + qx * y - qy * x;
  1261. var iw = - qx * x - qy * y - qz * z;
  1262. // calculate result * inverse quat
  1263. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1264. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1265. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1266. return this;
  1267. },
  1268. project: function () {
  1269. var matrix;
  1270. return function project( camera ) {
  1271. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1272. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1273. return this.applyProjection( matrix );
  1274. };
  1275. }(),
  1276. unproject: function () {
  1277. var matrix;
  1278. return function unproject( camera ) {
  1279. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1280. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1281. return this.applyProjection( matrix );
  1282. };
  1283. }(),
  1284. transformDirection: function ( m ) {
  1285. // input: THREE.Matrix4 affine matrix
  1286. // vector interpreted as a direction
  1287. var x = this.x, y = this.y, z = this.z;
  1288. var e = m.elements;
  1289. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1290. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1291. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1292. this.normalize();
  1293. return this;
  1294. },
  1295. divide: function ( v ) {
  1296. this.x /= v.x;
  1297. this.y /= v.y;
  1298. this.z /= v.z;
  1299. return this;
  1300. },
  1301. divideScalar: function ( scalar ) {
  1302. if ( scalar !== 0 ) {
  1303. var invScalar = 1 / scalar;
  1304. this.x *= invScalar;
  1305. this.y *= invScalar;
  1306. this.z *= invScalar;
  1307. } else {
  1308. this.x = 0;
  1309. this.y = 0;
  1310. this.z = 0;
  1311. }
  1312. return this;
  1313. },
  1314. min: function ( v ) {
  1315. if ( this.x > v.x ) {
  1316. this.x = v.x;
  1317. }
  1318. if ( this.y > v.y ) {
  1319. this.y = v.y;
  1320. }
  1321. if ( this.z > v.z ) {
  1322. this.z = v.z;
  1323. }
  1324. return this;
  1325. },
  1326. max: function ( v ) {
  1327. if ( this.x < v.x ) {
  1328. this.x = v.x;
  1329. }
  1330. if ( this.y < v.y ) {
  1331. this.y = v.y;
  1332. }
  1333. if ( this.z < v.z ) {
  1334. this.z = v.z;
  1335. }
  1336. return this;
  1337. },
  1338. clamp: function ( min, max ) {
  1339. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1340. if ( this.x < min.x ) {
  1341. this.x = min.x;
  1342. } else if ( this.x > max.x ) {
  1343. this.x = max.x;
  1344. }
  1345. if ( this.y < min.y ) {
  1346. this.y = min.y;
  1347. } else if ( this.y > max.y ) {
  1348. this.y = max.y;
  1349. }
  1350. if ( this.z < min.z ) {
  1351. this.z = min.z;
  1352. } else if ( this.z > max.z ) {
  1353. this.z = max.z;
  1354. }
  1355. return this;
  1356. },
  1357. clampScalar: function () {
  1358. var min, max;
  1359. return function clampScalar( minVal, maxVal ) {
  1360. if ( min === undefined ) {
  1361. min = new THREE.Vector3();
  1362. max = new THREE.Vector3();
  1363. }
  1364. min.set( minVal, minVal, minVal );
  1365. max.set( maxVal, maxVal, maxVal );
  1366. return this.clamp( min, max );
  1367. };
  1368. }(),
  1369. floor: function () {
  1370. this.x = Math.floor( this.x );
  1371. this.y = Math.floor( this.y );
  1372. this.z = Math.floor( this.z );
  1373. return this;
  1374. },
  1375. ceil: function () {
  1376. this.x = Math.ceil( this.x );
  1377. this.y = Math.ceil( this.y );
  1378. this.z = Math.ceil( this.z );
  1379. return this;
  1380. },
  1381. round: function () {
  1382. this.x = Math.round( this.x );
  1383. this.y = Math.round( this.y );
  1384. this.z = Math.round( this.z );
  1385. return this;
  1386. },
  1387. roundToZero: function () {
  1388. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1389. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1390. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1391. return this;
  1392. },
  1393. negate: function () {
  1394. this.x = - this.x;
  1395. this.y = - this.y;
  1396. this.z = - this.z;
  1397. return this;
  1398. },
  1399. dot: function ( v ) {
  1400. return this.x * v.x + this.y * v.y + this.z * v.z;
  1401. },
  1402. lengthSq: function () {
  1403. return this.x * this.x + this.y * this.y + this.z * this.z;
  1404. },
  1405. length: function () {
  1406. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1407. },
  1408. lengthManhattan: function () {
  1409. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1410. },
  1411. normalize: function () {
  1412. return this.divideScalar( this.length() );
  1413. },
  1414. setLength: function ( l ) {
  1415. var oldLength = this.length();
  1416. if ( oldLength !== 0 && l !== oldLength ) {
  1417. this.multiplyScalar( l / oldLength );
  1418. }
  1419. return this;
  1420. },
  1421. lerp: function ( v, alpha ) {
  1422. this.x += ( v.x - this.x ) * alpha;
  1423. this.y += ( v.y - this.y ) * alpha;
  1424. this.z += ( v.z - this.z ) * alpha;
  1425. return this;
  1426. },
  1427. lerpVectors: function ( v1, v2, alpha ) {
  1428. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1429. return this;
  1430. },
  1431. cross: function ( v, w ) {
  1432. if ( w !== undefined ) {
  1433. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1434. return this.crossVectors( v, w );
  1435. }
  1436. var x = this.x, y = this.y, z = this.z;
  1437. this.x = y * v.z - z * v.y;
  1438. this.y = z * v.x - x * v.z;
  1439. this.z = x * v.y - y * v.x;
  1440. return this;
  1441. },
  1442. crossVectors: function ( a, b ) {
  1443. var ax = a.x, ay = a.y, az = a.z;
  1444. var bx = b.x, by = b.y, bz = b.z;
  1445. this.x = ay * bz - az * by;
  1446. this.y = az * bx - ax * bz;
  1447. this.z = ax * by - ay * bx;
  1448. return this;
  1449. },
  1450. projectOnVector: function () {
  1451. var v1, dot;
  1452. return function projectOnVector( vector ) {
  1453. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1454. v1.copy( vector ).normalize();
  1455. dot = this.dot( v1 );
  1456. return this.copy( v1 ).multiplyScalar( dot );
  1457. };
  1458. }(),
  1459. projectOnPlane: function () {
  1460. var v1;
  1461. return function projectOnPlane( planeNormal ) {
  1462. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1463. v1.copy( this ).projectOnVector( planeNormal );
  1464. return this.sub( v1 );
  1465. }
  1466. }(),
  1467. reflect: function () {
  1468. // reflect incident vector off plane orthogonal to normal
  1469. // normal is assumed to have unit length
  1470. var v1;
  1471. return function reflect( normal ) {
  1472. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1473. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1474. }
  1475. }(),
  1476. angleTo: function ( v ) {
  1477. var theta = this.dot( v ) / ( this.length() * v.length() );
  1478. // clamp, to handle numerical problems
  1479. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1480. },
  1481. distanceTo: function ( v ) {
  1482. return Math.sqrt( this.distanceToSquared( v ) );
  1483. },
  1484. distanceToSquared: function ( v ) {
  1485. var dx = this.x - v.x;
  1486. var dy = this.y - v.y;
  1487. var dz = this.z - v.z;
  1488. return dx * dx + dy * dy + dz * dz;
  1489. },
  1490. setEulerFromRotationMatrix: function ( m, order ) {
  1491. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1492. },
  1493. setEulerFromQuaternion: function ( q, order ) {
  1494. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1495. },
  1496. getPositionFromMatrix: function ( m ) {
  1497. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1498. return this.setFromMatrixPosition( m );
  1499. },
  1500. getScaleFromMatrix: function ( m ) {
  1501. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1502. return this.setFromMatrixScale( m );
  1503. },
  1504. getColumnFromMatrix: function ( index, matrix ) {
  1505. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1506. return this.setFromMatrixColumn( index, matrix );
  1507. },
  1508. setFromMatrixPosition: function ( m ) {
  1509. this.x = m.elements[ 12 ];
  1510. this.y = m.elements[ 13 ];
  1511. this.z = m.elements[ 14 ];
  1512. return this;
  1513. },
  1514. setFromMatrixScale: function ( m ) {
  1515. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1516. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1517. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1518. this.x = sx;
  1519. this.y = sy;
  1520. this.z = sz;
  1521. return this;
  1522. },
  1523. setFromMatrixColumn: function ( index, matrix ) {
  1524. var offset = index * 4;
  1525. var me = matrix.elements;
  1526. this.x = me[ offset ];
  1527. this.y = me[ offset + 1 ];
  1528. this.z = me[ offset + 2 ];
  1529. return this;
  1530. },
  1531. equals: function ( v ) {
  1532. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1533. },
  1534. fromArray: function ( array, offset ) {
  1535. if ( offset === undefined ) offset = 0;
  1536. this.x = array[ offset ];
  1537. this.y = array[ offset + 1 ];
  1538. this.z = array[ offset + 2 ];
  1539. return this;
  1540. },
  1541. toArray: function ( array, offset ) {
  1542. if ( array === undefined ) array = [];
  1543. if ( offset === undefined ) offset = 0;
  1544. array[ offset ] = this.x;
  1545. array[ offset + 1 ] = this.y;
  1546. array[ offset + 2 ] = this.z;
  1547. return array;
  1548. },
  1549. fromAttribute: function ( attribute, index, offset ) {
  1550. if ( offset === undefined ) offset = 0;
  1551. index = index * attribute.itemSize + offset;
  1552. this.x = attribute.array[ index ];
  1553. this.y = attribute.array[ index + 1 ];
  1554. this.z = attribute.array[ index + 2 ];
  1555. return this;
  1556. },
  1557. clone: function () {
  1558. return new THREE.Vector3( this.x, this.y, this.z );
  1559. }
  1560. };
  1561. // File:src/math/Vector4.js
  1562. /**
  1563. * @author supereggbert / http://www.paulbrunt.co.uk/
  1564. * @author philogb / http://blog.thejit.org/
  1565. * @author mikael emtinger / http://gomo.se/
  1566. * @author egraether / http://egraether.com/
  1567. * @author WestLangley / http://github.com/WestLangley
  1568. */
  1569. THREE.Vector4 = function ( x, y, z, w ) {
  1570. this.x = x || 0;
  1571. this.y = y || 0;
  1572. this.z = z || 0;
  1573. this.w = ( w !== undefined ) ? w : 1;
  1574. };
  1575. THREE.Vector4.prototype = {
  1576. constructor: THREE.Vector4,
  1577. set: function ( x, y, z, w ) {
  1578. this.x = x;
  1579. this.y = y;
  1580. this.z = z;
  1581. this.w = w;
  1582. return this;
  1583. },
  1584. setX: function ( x ) {
  1585. this.x = x;
  1586. return this;
  1587. },
  1588. setY: function ( y ) {
  1589. this.y = y;
  1590. return this;
  1591. },
  1592. setZ: function ( z ) {
  1593. this.z = z;
  1594. return this;
  1595. },
  1596. setW: function ( w ) {
  1597. this.w = w;
  1598. return this;
  1599. },
  1600. setComponent: function ( index, value ) {
  1601. switch ( index ) {
  1602. case 0: this.x = value; break;
  1603. case 1: this.y = value; break;
  1604. case 2: this.z = value; break;
  1605. case 3: this.w = value; break;
  1606. default: throw new Error( 'index is out of range: ' + index );
  1607. }
  1608. },
  1609. getComponent: function ( index ) {
  1610. switch ( index ) {
  1611. case 0: return this.x;
  1612. case 1: return this.y;
  1613. case 2: return this.z;
  1614. case 3: return this.w;
  1615. default: throw new Error( 'index is out of range: ' + index );
  1616. }
  1617. },
  1618. copy: function ( v ) {
  1619. this.x = v.x;
  1620. this.y = v.y;
  1621. this.z = v.z;
  1622. this.w = ( v.w !== undefined ) ? v.w : 1;
  1623. return this;
  1624. },
  1625. add: function ( v, w ) {
  1626. if ( w !== undefined ) {
  1627. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1628. return this.addVectors( v, w );
  1629. }
  1630. this.x += v.x;
  1631. this.y += v.y;
  1632. this.z += v.z;
  1633. this.w += v.w;
  1634. return this;
  1635. },
  1636. addScalar: function ( s ) {
  1637. this.x += s;
  1638. this.y += s;
  1639. this.z += s;
  1640. this.w += s;
  1641. return this;
  1642. },
  1643. addVectors: function ( a, b ) {
  1644. this.x = a.x + b.x;
  1645. this.y = a.y + b.y;
  1646. this.z = a.z + b.z;
  1647. this.w = a.w + b.w;
  1648. return this;
  1649. },
  1650. addScaledVector: function ( v, s ) {
  1651. this.x += v.x * s;
  1652. this.y += v.y * s;
  1653. this.z += v.z * s;
  1654. this.w += v.w * s;
  1655. return this;
  1656. },
  1657. sub: function ( v, w ) {
  1658. if ( w !== undefined ) {
  1659. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1660. return this.subVectors( v, w );
  1661. }
  1662. this.x -= v.x;
  1663. this.y -= v.y;
  1664. this.z -= v.z;
  1665. this.w -= v.w;
  1666. return this;
  1667. },
  1668. subScalar: function ( s ) {
  1669. this.x -= s;
  1670. this.y -= s;
  1671. this.z -= s;
  1672. this.w -= s;
  1673. return this;
  1674. },
  1675. subVectors: function ( a, b ) {
  1676. this.x = a.x - b.x;
  1677. this.y = a.y - b.y;
  1678. this.z = a.z - b.z;
  1679. this.w = a.w - b.w;
  1680. return this;
  1681. },
  1682. multiplyScalar: function ( scalar ) {
  1683. this.x *= scalar;
  1684. this.y *= scalar;
  1685. this.z *= scalar;
  1686. this.w *= scalar;
  1687. return this;
  1688. },
  1689. applyMatrix4: function ( m ) {
  1690. var x = this.x;
  1691. var y = this.y;
  1692. var z = this.z;
  1693. var w = this.w;
  1694. var e = m.elements;
  1695. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1696. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1697. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1698. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1699. return this;
  1700. },
  1701. divideScalar: function ( scalar ) {
  1702. if ( scalar !== 0 ) {
  1703. var invScalar = 1 / scalar;
  1704. this.x *= invScalar;
  1705. this.y *= invScalar;
  1706. this.z *= invScalar;
  1707. this.w *= invScalar;
  1708. } else {
  1709. this.x = 0;
  1710. this.y = 0;
  1711. this.z = 0;
  1712. this.w = 1;
  1713. }
  1714. return this;
  1715. },
  1716. setAxisAngleFromQuaternion: function ( q ) {
  1717. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1718. // q is assumed to be normalized
  1719. this.w = 2 * Math.acos( q.w );
  1720. var s = Math.sqrt( 1 - q.w * q.w );
  1721. if ( s < 0.0001 ) {
  1722. this.x = 1;
  1723. this.y = 0;
  1724. this.z = 0;
  1725. } else {
  1726. this.x = q.x / s;
  1727. this.y = q.y / s;
  1728. this.z = q.z / s;
  1729. }
  1730. return this;
  1731. },
  1732. setAxisAngleFromRotationMatrix: function ( m ) {
  1733. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1734. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1735. var angle, x, y, z, // variables for result
  1736. epsilon = 0.01, // margin to allow for rounding errors
  1737. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1738. te = m.elements,
  1739. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1740. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1741. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1742. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1743. && ( Math.abs( m13 - m31 ) < epsilon )
  1744. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1745. // singularity found
  1746. // first check for identity matrix which must have +1 for all terms
  1747. // in leading diagonal and zero in other terms
  1748. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1749. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1750. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1751. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1752. // this singularity is identity matrix so angle = 0
  1753. this.set( 1, 0, 0, 0 );
  1754. return this; // zero angle, arbitrary axis
  1755. }
  1756. // otherwise this singularity is angle = 180
  1757. angle = Math.PI;
  1758. var xx = ( m11 + 1 ) / 2;
  1759. var yy = ( m22 + 1 ) / 2;
  1760. var zz = ( m33 + 1 ) / 2;
  1761. var xy = ( m12 + m21 ) / 4;
  1762. var xz = ( m13 + m31 ) / 4;
  1763. var yz = ( m23 + m32 ) / 4;
  1764. if ( ( xx > yy ) && ( xx > zz ) ) {
  1765. // m11 is the largest diagonal term
  1766. if ( xx < epsilon ) {
  1767. x = 0;
  1768. y = 0.707106781;
  1769. z = 0.707106781;
  1770. } else {
  1771. x = Math.sqrt( xx );
  1772. y = xy / x;
  1773. z = xz / x;
  1774. }
  1775. } else if ( yy > zz ) {
  1776. // m22 is the largest diagonal term
  1777. if ( yy < epsilon ) {
  1778. x = 0.707106781;
  1779. y = 0;
  1780. z = 0.707106781;
  1781. } else {
  1782. y = Math.sqrt( yy );
  1783. x = xy / y;
  1784. z = yz / y;
  1785. }
  1786. } else {
  1787. // m33 is the largest diagonal term so base result on this
  1788. if ( zz < epsilon ) {
  1789. x = 0.707106781;
  1790. y = 0.707106781;
  1791. z = 0;
  1792. } else {
  1793. z = Math.sqrt( zz );
  1794. x = xz / z;
  1795. y = yz / z;
  1796. }
  1797. }
  1798. this.set( x, y, z, angle );
  1799. return this; // return 180 deg rotation
  1800. }
  1801. // as we have reached here there are no singularities so we can handle normally
  1802. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1803. + ( m13 - m31 ) * ( m13 - m31 )
  1804. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1805. if ( Math.abs( s ) < 0.001 ) s = 1;
  1806. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1807. // caught by singularity test above, but I've left it in just in case
  1808. this.x = ( m32 - m23 ) / s;
  1809. this.y = ( m13 - m31 ) / s;
  1810. this.z = ( m21 - m12 ) / s;
  1811. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1812. return this;
  1813. },
  1814. min: function ( v ) {
  1815. if ( this.x > v.x ) {
  1816. this.x = v.x;
  1817. }
  1818. if ( this.y > v.y ) {
  1819. this.y = v.y;
  1820. }
  1821. if ( this.z > v.z ) {
  1822. this.z = v.z;
  1823. }
  1824. if ( this.w > v.w ) {
  1825. this.w = v.w;
  1826. }
  1827. return this;
  1828. },
  1829. max: function ( v ) {
  1830. if ( this.x < v.x ) {
  1831. this.x = v.x;
  1832. }
  1833. if ( this.y < v.y ) {
  1834. this.y = v.y;
  1835. }
  1836. if ( this.z < v.z ) {
  1837. this.z = v.z;
  1838. }
  1839. if ( this.w < v.w ) {
  1840. this.w = v.w;
  1841. }
  1842. return this;
  1843. },
  1844. clamp: function ( min, max ) {
  1845. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1846. if ( this.x < min.x ) {
  1847. this.x = min.x;
  1848. } else if ( this.x > max.x ) {
  1849. this.x = max.x;
  1850. }
  1851. if ( this.y < min.y ) {
  1852. this.y = min.y;
  1853. } else if ( this.y > max.y ) {
  1854. this.y = max.y;
  1855. }
  1856. if ( this.z < min.z ) {
  1857. this.z = min.z;
  1858. } else if ( this.z > max.z ) {
  1859. this.z = max.z;
  1860. }
  1861. if ( this.w < min.w ) {
  1862. this.w = min.w;
  1863. } else if ( this.w > max.w ) {
  1864. this.w = max.w;
  1865. }
  1866. return this;
  1867. },
  1868. clampScalar: function () {
  1869. var min, max;
  1870. return function clampScalar( minVal, maxVal ) {
  1871. if ( min === undefined ) {
  1872. min = new THREE.Vector4();
  1873. max = new THREE.Vector4();
  1874. }
  1875. min.set( minVal, minVal, minVal, minVal );
  1876. max.set( maxVal, maxVal, maxVal, maxVal );
  1877. return this.clamp( min, max );
  1878. };
  1879. }(),
  1880. floor: function () {
  1881. this.x = Math.floor( this.x );
  1882. this.y = Math.floor( this.y );
  1883. this.z = Math.floor( this.z );
  1884. this.w = Math.floor( this.w );
  1885. return this;
  1886. },
  1887. ceil: function () {
  1888. this.x = Math.ceil( this.x );
  1889. this.y = Math.ceil( this.y );
  1890. this.z = Math.ceil( this.z );
  1891. this.w = Math.ceil( this.w );
  1892. return this;
  1893. },
  1894. round: function () {
  1895. this.x = Math.round( this.x );
  1896. this.y = Math.round( this.y );
  1897. this.z = Math.round( this.z );
  1898. this.w = Math.round( this.w );
  1899. return this;
  1900. },
  1901. roundToZero: function () {
  1902. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1903. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1904. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1905. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1906. return this;
  1907. },
  1908. negate: function () {
  1909. this.x = - this.x;
  1910. this.y = - this.y;
  1911. this.z = - this.z;
  1912. this.w = - this.w;
  1913. return this;
  1914. },
  1915. dot: function ( v ) {
  1916. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1917. },
  1918. lengthSq: function () {
  1919. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1920. },
  1921. length: function () {
  1922. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1923. },
  1924. lengthManhattan: function () {
  1925. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1926. },
  1927. normalize: function () {
  1928. return this.divideScalar( this.length() );
  1929. },
  1930. setLength: function ( l ) {
  1931. var oldLength = this.length();
  1932. if ( oldLength !== 0 && l !== oldLength ) {
  1933. this.multiplyScalar( l / oldLength );
  1934. }
  1935. return this;
  1936. },
  1937. lerp: function ( v, alpha ) {
  1938. this.x += ( v.x - this.x ) * alpha;
  1939. this.y += ( v.y - this.y ) * alpha;
  1940. this.z += ( v.z - this.z ) * alpha;
  1941. this.w += ( v.w - this.w ) * alpha;
  1942. return this;
  1943. },
  1944. lerpVectors: function ( v1, v2, alpha ) {
  1945. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1946. return this;
  1947. },
  1948. equals: function ( v ) {
  1949. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1950. },
  1951. fromArray: function ( array, offset ) {
  1952. if ( offset === undefined ) offset = 0;
  1953. this.x = array[ offset ];
  1954. this.y = array[ offset + 1 ];
  1955. this.z = array[ offset + 2 ];
  1956. this.w = array[ offset + 3 ];
  1957. return this;
  1958. },
  1959. toArray: function ( array, offset ) {
  1960. if ( array === undefined ) array = [];
  1961. if ( offset === undefined ) offset = 0;
  1962. array[ offset ] = this.x;
  1963. array[ offset + 1 ] = this.y;
  1964. array[ offset + 2 ] = this.z;
  1965. array[ offset + 3 ] = this.w;
  1966. return array;
  1967. },
  1968. fromAttribute: function ( attribute, index, offset ) {
  1969. if ( offset === undefined ) offset = 0;
  1970. index = index * attribute.itemSize + offset;
  1971. this.x = attribute.array[ index ];
  1972. this.y = attribute.array[ index + 1 ];
  1973. this.z = attribute.array[ index + 2 ];
  1974. this.w = attribute.array[ index + 3 ];
  1975. return this;
  1976. },
  1977. clone: function () {
  1978. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  1979. }
  1980. };
  1981. // File:src/math/Euler.js
  1982. /**
  1983. * @author mrdoob / http://mrdoob.com/
  1984. * @author WestLangley / http://github.com/WestLangley
  1985. * @author bhouston / http://exocortex.com
  1986. */
  1987. THREE.Euler = function ( x, y, z, order ) {
  1988. this._x = x || 0;
  1989. this._y = y || 0;
  1990. this._z = z || 0;
  1991. this._order = order || THREE.Euler.DefaultOrder;
  1992. };
  1993. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1994. THREE.Euler.DefaultOrder = 'XYZ';
  1995. THREE.Euler.prototype = {
  1996. constructor: THREE.Euler,
  1997. get x () {
  1998. return this._x;
  1999. },
  2000. set x ( value ) {
  2001. this._x = value;
  2002. this.onChangeCallback();
  2003. },
  2004. get y () {
  2005. return this._y;
  2006. },
  2007. set y ( value ) {
  2008. this._y = value;
  2009. this.onChangeCallback();
  2010. },
  2011. get z () {
  2012. return this._z;
  2013. },
  2014. set z ( value ) {
  2015. this._z = value;
  2016. this.onChangeCallback();
  2017. },
  2018. get order () {
  2019. return this._order;
  2020. },
  2021. set order ( value ) {
  2022. this._order = value;
  2023. this.onChangeCallback();
  2024. },
  2025. set: function ( x, y, z, order ) {
  2026. this._x = x;
  2027. this._y = y;
  2028. this._z = z;
  2029. this._order = order || this._order;
  2030. this.onChangeCallback();
  2031. return this;
  2032. },
  2033. copy: function ( euler ) {
  2034. this._x = euler._x;
  2035. this._y = euler._y;
  2036. this._z = euler._z;
  2037. this._order = euler._order;
  2038. this.onChangeCallback();
  2039. return this;
  2040. },
  2041. setFromRotationMatrix: function ( m, order, update ) {
  2042. var clamp = THREE.Math.clamp;
  2043. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2044. var te = m.elements;
  2045. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2046. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2047. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2048. order = order || this._order;
  2049. if ( order === 'XYZ' ) {
  2050. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2051. if ( Math.abs( m13 ) < 0.99999 ) {
  2052. this._x = Math.atan2( - m23, m33 );
  2053. this._z = Math.atan2( - m12, m11 );
  2054. } else {
  2055. this._x = Math.atan2( m32, m22 );
  2056. this._z = 0;
  2057. }
  2058. } else if ( order === 'YXZ' ) {
  2059. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2060. if ( Math.abs( m23 ) < 0.99999 ) {
  2061. this._y = Math.atan2( m13, m33 );
  2062. this._z = Math.atan2( m21, m22 );
  2063. } else {
  2064. this._y = Math.atan2( - m31, m11 );
  2065. this._z = 0;
  2066. }
  2067. } else if ( order === 'ZXY' ) {
  2068. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2069. if ( Math.abs( m32 ) < 0.99999 ) {
  2070. this._y = Math.atan2( - m31, m33 );
  2071. this._z = Math.atan2( - m12, m22 );
  2072. } else {
  2073. this._y = 0;
  2074. this._z = Math.atan2( m21, m11 );
  2075. }
  2076. } else if ( order === 'ZYX' ) {
  2077. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2078. if ( Math.abs( m31 ) < 0.99999 ) {
  2079. this._x = Math.atan2( m32, m33 );
  2080. this._z = Math.atan2( m21, m11 );
  2081. } else {
  2082. this._x = 0;
  2083. this._z = Math.atan2( - m12, m22 );
  2084. }
  2085. } else if ( order === 'YZX' ) {
  2086. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2087. if ( Math.abs( m21 ) < 0.99999 ) {
  2088. this._x = Math.atan2( - m23, m22 );
  2089. this._y = Math.atan2( - m31, m11 );
  2090. } else {
  2091. this._x = 0;
  2092. this._y = Math.atan2( m13, m33 );
  2093. }
  2094. } else if ( order === 'XZY' ) {
  2095. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2096. if ( Math.abs( m12 ) < 0.99999 ) {
  2097. this._x = Math.atan2( m32, m22 );
  2098. this._y = Math.atan2( m13, m11 );
  2099. } else {
  2100. this._x = Math.atan2( - m23, m33 );
  2101. this._y = 0;
  2102. }
  2103. } else {
  2104. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2105. }
  2106. this._order = order;
  2107. if ( update !== false ) this.onChangeCallback();
  2108. return this;
  2109. },
  2110. setFromQuaternion: function () {
  2111. var matrix;
  2112. return function ( q, order, update ) {
  2113. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2114. matrix.makeRotationFromQuaternion( q );
  2115. this.setFromRotationMatrix( matrix, order, update );
  2116. return this;
  2117. };
  2118. }(),
  2119. setFromVector3: function ( v, order ) {
  2120. return this.set( v.x, v.y, v.z, order || this._order );
  2121. },
  2122. reorder: function () {
  2123. // WARNING: this discards revolution information -bhouston
  2124. var q = new THREE.Quaternion();
  2125. return function ( newOrder ) {
  2126. q.setFromEuler( this );
  2127. this.setFromQuaternion( q, newOrder );
  2128. };
  2129. }(),
  2130. equals: function ( euler ) {
  2131. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2132. },
  2133. fromArray: function ( array ) {
  2134. this._x = array[ 0 ];
  2135. this._y = array[ 1 ];
  2136. this._z = array[ 2 ];
  2137. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2138. this.onChangeCallback();
  2139. return this;
  2140. },
  2141. toArray: function ( array, offset ) {
  2142. if ( array === undefined ) array = [];
  2143. if ( offset === undefined ) offset = 0;
  2144. array[ offset ] = this._x;
  2145. array[ offset + 1 ] = this._y;
  2146. array[ offset + 2 ] = this._z;
  2147. array[ offset + 3 ] = this._order;
  2148. return array;
  2149. },
  2150. toVector3: function ( optionalResult ) {
  2151. if ( optionalResult ) {
  2152. return optionalResult.set( this._x, this._y, this._z );
  2153. } else {
  2154. return new THREE.Vector3( this._x, this._y, this._z );
  2155. }
  2156. },
  2157. onChange: function ( callback ) {
  2158. this.onChangeCallback = callback;
  2159. return this;
  2160. },
  2161. onChangeCallback: function () {},
  2162. clone: function () {
  2163. return new THREE.Euler( this._x, this._y, this._z, this._order );
  2164. }
  2165. };
  2166. // File:src/math/Line3.js
  2167. /**
  2168. * @author bhouston / http://exocortex.com
  2169. */
  2170. THREE.Line3 = function ( start, end ) {
  2171. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2172. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2173. };
  2174. THREE.Line3.prototype = {
  2175. constructor: THREE.Line3,
  2176. set: function ( start, end ) {
  2177. this.start.copy( start );
  2178. this.end.copy( end );
  2179. return this;
  2180. },
  2181. copy: function ( line ) {
  2182. this.start.copy( line.start );
  2183. this.end.copy( line.end );
  2184. return this;
  2185. },
  2186. center: function ( optionalTarget ) {
  2187. var result = optionalTarget || new THREE.Vector3();
  2188. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2189. },
  2190. delta: function ( optionalTarget ) {
  2191. var result = optionalTarget || new THREE.Vector3();
  2192. return result.subVectors( this.end, this.start );
  2193. },
  2194. distanceSq: function () {
  2195. return this.start.distanceToSquared( this.end );
  2196. },
  2197. distance: function () {
  2198. return this.start.distanceTo( this.end );
  2199. },
  2200. at: function ( t, optionalTarget ) {
  2201. var result = optionalTarget || new THREE.Vector3();
  2202. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2203. },
  2204. closestPointToPointParameter: function () {
  2205. var startP = new THREE.Vector3();
  2206. var startEnd = new THREE.Vector3();
  2207. return function ( point, clampToLine ) {
  2208. startP.subVectors( point, this.start );
  2209. startEnd.subVectors( this.end, this.start );
  2210. var startEnd2 = startEnd.dot( startEnd );
  2211. var startEnd_startP = startEnd.dot( startP );
  2212. var t = startEnd_startP / startEnd2;
  2213. if ( clampToLine ) {
  2214. t = THREE.Math.clamp( t, 0, 1 );
  2215. }
  2216. return t;
  2217. };
  2218. }(),
  2219. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2220. var t = this.closestPointToPointParameter( point, clampToLine );
  2221. var result = optionalTarget || new THREE.Vector3();
  2222. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2223. },
  2224. applyMatrix4: function ( matrix ) {
  2225. this.start.applyMatrix4( matrix );
  2226. this.end.applyMatrix4( matrix );
  2227. return this;
  2228. },
  2229. equals: function ( line ) {
  2230. return line.start.equals( this.start ) && line.end.equals( this.end );
  2231. },
  2232. clone: function () {
  2233. return new THREE.Line3().copy( this );
  2234. }
  2235. };
  2236. // File:src/math/Box2.js
  2237. /**
  2238. * @author bhouston / http://exocortex.com
  2239. */
  2240. THREE.Box2 = function ( min, max ) {
  2241. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2242. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2243. };
  2244. THREE.Box2.prototype = {
  2245. constructor: THREE.Box2,
  2246. set: function ( min, max ) {
  2247. this.min.copy( min );
  2248. this.max.copy( max );
  2249. return this;
  2250. },
  2251. setFromPoints: function ( points ) {
  2252. this.makeEmpty();
  2253. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2254. this.expandByPoint( points[ i ] )
  2255. }
  2256. return this;
  2257. },
  2258. setFromCenterAndSize: function () {
  2259. var v1 = new THREE.Vector2();
  2260. return function ( center, size ) {
  2261. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2262. this.min.copy( center ).sub( halfSize );
  2263. this.max.copy( center ).add( halfSize );
  2264. return this;
  2265. };
  2266. }(),
  2267. copy: function ( box ) {
  2268. this.min.copy( box.min );
  2269. this.max.copy( box.max );
  2270. return this;
  2271. },
  2272. makeEmpty: function () {
  2273. this.min.x = this.min.y = Infinity;
  2274. this.max.x = this.max.y = - Infinity;
  2275. return this;
  2276. },
  2277. empty: function () {
  2278. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2279. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2280. },
  2281. center: function ( optionalTarget ) {
  2282. var result = optionalTarget || new THREE.Vector2();
  2283. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2284. },
  2285. size: function ( optionalTarget ) {
  2286. var result = optionalTarget || new THREE.Vector2();
  2287. return result.subVectors( this.max, this.min );
  2288. },
  2289. expandByPoint: function ( point ) {
  2290. this.min.min( point );
  2291. this.max.max( point );
  2292. return this;
  2293. },
  2294. expandByVector: function ( vector ) {
  2295. this.min.sub( vector );
  2296. this.max.add( vector );
  2297. return this;
  2298. },
  2299. expandByScalar: function ( scalar ) {
  2300. this.min.addScalar( - scalar );
  2301. this.max.addScalar( scalar );
  2302. return this;
  2303. },
  2304. containsPoint: function ( point ) {
  2305. if ( point.x < this.min.x || point.x > this.max.x ||
  2306. point.y < this.min.y || point.y > this.max.y ) {
  2307. return false;
  2308. }
  2309. return true;
  2310. },
  2311. containsBox: function ( box ) {
  2312. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2313. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2314. return true;
  2315. }
  2316. return false;
  2317. },
  2318. getParameter: function ( point, optionalTarget ) {
  2319. // This can potentially have a divide by zero if the box
  2320. // has a size dimension of 0.
  2321. var result = optionalTarget || new THREE.Vector2();
  2322. return result.set(
  2323. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2324. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2325. );
  2326. },
  2327. isIntersectionBox: function ( box ) {
  2328. // using 6 splitting planes to rule out intersections.
  2329. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2330. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2331. return false;
  2332. }
  2333. return true;
  2334. },
  2335. clampPoint: function ( point, optionalTarget ) {
  2336. var result = optionalTarget || new THREE.Vector2();
  2337. return result.copy( point ).clamp( this.min, this.max );
  2338. },
  2339. distanceToPoint: function () {
  2340. var v1 = new THREE.Vector2();
  2341. return function ( point ) {
  2342. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2343. return clampedPoint.sub( point ).length();
  2344. };
  2345. }(),
  2346. intersect: function ( box ) {
  2347. this.min.max( box.min );
  2348. this.max.min( box.max );
  2349. return this;
  2350. },
  2351. union: function ( box ) {
  2352. this.min.min( box.min );
  2353. this.max.max( box.max );
  2354. return this;
  2355. },
  2356. translate: function ( offset ) {
  2357. this.min.add( offset );
  2358. this.max.add( offset );
  2359. return this;
  2360. },
  2361. equals: function ( box ) {
  2362. return box.min.equals( this.min ) && box.max.equals( this.max );
  2363. },
  2364. clone: function () {
  2365. return new THREE.Box2().copy( this );
  2366. }
  2367. };
  2368. // File:src/math/Box3.js
  2369. /**
  2370. * @author bhouston / http://exocortex.com
  2371. * @author WestLangley / http://github.com/WestLangley
  2372. */
  2373. THREE.Box3 = function ( min, max ) {
  2374. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2375. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2376. };
  2377. THREE.Box3.prototype = {
  2378. constructor: THREE.Box3,
  2379. set: function ( min, max ) {
  2380. this.min.copy( min );
  2381. this.max.copy( max );
  2382. return this;
  2383. },
  2384. setFromPoints: function ( points ) {
  2385. this.makeEmpty();
  2386. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2387. this.expandByPoint( points[ i ] );
  2388. }
  2389. return this;
  2390. },
  2391. setFromCenterAndSize: function () {
  2392. var v1 = new THREE.Vector3();
  2393. return function ( center, size ) {
  2394. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2395. this.min.copy( center ).sub( halfSize );
  2396. this.max.copy( center ).add( halfSize );
  2397. return this;
  2398. };
  2399. }(),
  2400. setFromObject: function () {
  2401. // Computes the world-axis-aligned bounding box of an object (including its children),
  2402. // accounting for both the object's, and children's, world transforms
  2403. var v1 = new THREE.Vector3();
  2404. return function ( object ) {
  2405. var scope = this;
  2406. object.updateMatrixWorld( true );
  2407. this.makeEmpty();
  2408. object.traverse( function ( node ) {
  2409. var geometry = node.geometry;
  2410. if ( geometry !== undefined ) {
  2411. if ( geometry instanceof THREE.Geometry ) {
  2412. var vertices = geometry.vertices;
  2413. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2414. v1.copy( vertices[ i ] );
  2415. v1.applyMatrix4( node.matrixWorld );
  2416. scope.expandByPoint( v1 );
  2417. }
  2418. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2419. var positions = geometry.attributes[ 'position' ].array;
  2420. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2421. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2422. v1.applyMatrix4( node.matrixWorld );
  2423. scope.expandByPoint( v1 );
  2424. }
  2425. }
  2426. }
  2427. } );
  2428. return this;
  2429. };
  2430. }(),
  2431. copy: function ( box ) {
  2432. this.min.copy( box.min );
  2433. this.max.copy( box.max );
  2434. return this;
  2435. },
  2436. makeEmpty: function () {
  2437. this.min.x = this.min.y = this.min.z = Infinity;
  2438. this.max.x = this.max.y = this.max.z = - Infinity;
  2439. return this;
  2440. },
  2441. empty: function () {
  2442. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2443. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2444. },
  2445. center: function ( optionalTarget ) {
  2446. var result = optionalTarget || new THREE.Vector3();
  2447. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2448. },
  2449. size: function ( optionalTarget ) {
  2450. var result = optionalTarget || new THREE.Vector3();
  2451. return result.subVectors( this.max, this.min );
  2452. },
  2453. expandByPoint: function ( point ) {
  2454. this.min.min( point );
  2455. this.max.max( point );
  2456. return this;
  2457. },
  2458. expandByVector: function ( vector ) {
  2459. this.min.sub( vector );
  2460. this.max.add( vector );
  2461. return this;
  2462. },
  2463. expandByScalar: function ( scalar ) {
  2464. this.min.addScalar( - scalar );
  2465. this.max.addScalar( scalar );
  2466. return this;
  2467. },
  2468. containsPoint: function ( point ) {
  2469. if ( point.x < this.min.x || point.x > this.max.x ||
  2470. point.y < this.min.y || point.y > this.max.y ||
  2471. point.z < this.min.z || point.z > this.max.z ) {
  2472. return false;
  2473. }
  2474. return true;
  2475. },
  2476. containsBox: function ( box ) {
  2477. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2478. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2479. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2480. return true;
  2481. }
  2482. return false;
  2483. },
  2484. getParameter: function ( point, optionalTarget ) {
  2485. // This can potentially have a divide by zero if the box
  2486. // has a size dimension of 0.
  2487. var result = optionalTarget || new THREE.Vector3();
  2488. return result.set(
  2489. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2490. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2491. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2492. );
  2493. },
  2494. isIntersectionBox: function ( box ) {
  2495. // using 6 splitting planes to rule out intersections.
  2496. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2497. box.max.y < this.min.y || box.min.y > this.max.y ||
  2498. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2499. return false;
  2500. }
  2501. return true;
  2502. },
  2503. clampPoint: function ( point, optionalTarget ) {
  2504. var result = optionalTarget || new THREE.Vector3();
  2505. return result.copy( point ).clamp( this.min, this.max );
  2506. },
  2507. distanceToPoint: function () {
  2508. var v1 = new THREE.Vector3();
  2509. return function ( point ) {
  2510. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2511. return clampedPoint.sub( point ).length();
  2512. };
  2513. }(),
  2514. getBoundingSphere: function () {
  2515. var v1 = new THREE.Vector3();
  2516. return function ( optionalTarget ) {
  2517. var result = optionalTarget || new THREE.Sphere();
  2518. result.center = this.center();
  2519. result.radius = this.size( v1 ).length() * 0.5;
  2520. return result;
  2521. };
  2522. }(),
  2523. intersect: function ( box ) {
  2524. this.min.max( box.min );
  2525. this.max.min( box.max );
  2526. return this;
  2527. },
  2528. union: function ( box ) {
  2529. this.min.min( box.min );
  2530. this.max.max( box.max );
  2531. return this;
  2532. },
  2533. applyMatrix4: function () {
  2534. var points = [
  2535. new THREE.Vector3(),
  2536. new THREE.Vector3(),
  2537. new THREE.Vector3(),
  2538. new THREE.Vector3(),
  2539. new THREE.Vector3(),
  2540. new THREE.Vector3(),
  2541. new THREE.Vector3(),
  2542. new THREE.Vector3()
  2543. ];
  2544. return function ( matrix ) {
  2545. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2546. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2547. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2548. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2549. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2550. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2551. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2552. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2553. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2554. this.makeEmpty();
  2555. this.setFromPoints( points );
  2556. return this;
  2557. };
  2558. }(),
  2559. translate: function ( offset ) {
  2560. this.min.add( offset );
  2561. this.max.add( offset );
  2562. return this;
  2563. },
  2564. equals: function ( box ) {
  2565. return box.min.equals( this.min ) && box.max.equals( this.max );
  2566. },
  2567. clone: function () {
  2568. return new THREE.Box3().copy( this );
  2569. }
  2570. };
  2571. // File:src/math/Matrix3.js
  2572. /**
  2573. * @author alteredq / http://alteredqualia.com/
  2574. * @author WestLangley / http://github.com/WestLangley
  2575. * @author bhouston / http://exocortex.com
  2576. */
  2577. THREE.Matrix3 = function () {
  2578. this.elements = new Float32Array( [
  2579. 1, 0, 0,
  2580. 0, 1, 0,
  2581. 0, 0, 1
  2582. ] );
  2583. if ( arguments.length > 0 ) {
  2584. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2585. }
  2586. };
  2587. THREE.Matrix3.prototype = {
  2588. constructor: THREE.Matrix3,
  2589. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2590. var te = this.elements;
  2591. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2592. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2593. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2594. return this;
  2595. },
  2596. identity: function () {
  2597. this.set(
  2598. 1, 0, 0,
  2599. 0, 1, 0,
  2600. 0, 0, 1
  2601. );
  2602. return this;
  2603. },
  2604. copy: function ( m ) {
  2605. var me = m.elements;
  2606. this.set(
  2607. me[ 0 ], me[ 3 ], me[ 6 ],
  2608. me[ 1 ], me[ 4 ], me[ 7 ],
  2609. me[ 2 ], me[ 5 ], me[ 8 ]
  2610. );
  2611. return this;
  2612. },
  2613. multiplyVector3: function ( vector ) {
  2614. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2615. return vector.applyMatrix3( this );
  2616. },
  2617. multiplyVector3Array: function ( a ) {
  2618. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2619. return this.applyToVector3Array( a );
  2620. },
  2621. applyToVector3Array: function () {
  2622. var v1;
  2623. return function ( array, offset, length ) {
  2624. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2625. if ( offset === undefined ) offset = 0;
  2626. if ( length === undefined ) length = array.length;
  2627. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2628. v1.fromArray( array, j );
  2629. v1.applyMatrix3( this );
  2630. v1.toArray( array, j );
  2631. }
  2632. return array;
  2633. };
  2634. }(),
  2635. applyToBuffer: function () {
  2636. var v1;
  2637. return function applyToBuffer( buffer, offset, length ) {
  2638. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2639. if ( offset === undefined ) offset = 0;
  2640. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2641. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2642. v1.x = buffer.getX( j );
  2643. v1.y = buffer.getY( j );
  2644. v1.z = buffer.getZ( j );
  2645. v1.applyMatrix3( this );
  2646. buffer.setXYZ( v1.x, v1.y, v1.z );
  2647. }
  2648. return buffer;
  2649. };
  2650. }(),
  2651. multiplyScalar: function ( s ) {
  2652. var te = this.elements;
  2653. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2654. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2655. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2656. return this;
  2657. },
  2658. determinant: function () {
  2659. var te = this.elements;
  2660. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2661. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2662. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2663. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2664. },
  2665. getInverse: function ( matrix, throwOnInvertible ) {
  2666. // input: THREE.Matrix4
  2667. // ( based on http://code.google.com/p/webgl-mjs/ )
  2668. var me = matrix.elements;
  2669. var te = this.elements;
  2670. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2671. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2672. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2673. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2674. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2675. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2676. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2677. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2678. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2679. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2680. // no inverse
  2681. if ( det === 0 ) {
  2682. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2683. if ( throwOnInvertible || false ) {
  2684. throw new Error( msg );
  2685. } else {
  2686. console.warn( msg );
  2687. }
  2688. this.identity();
  2689. return this;
  2690. }
  2691. this.multiplyScalar( 1.0 / det );
  2692. return this;
  2693. },
  2694. transpose: function () {
  2695. var tmp, m = this.elements;
  2696. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2697. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2698. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2699. return this;
  2700. },
  2701. flattenToArrayOffset: function ( array, offset ) {
  2702. var te = this.elements;
  2703. array[ offset ] = te[ 0 ];
  2704. array[ offset + 1 ] = te[ 1 ];
  2705. array[ offset + 2 ] = te[ 2 ];
  2706. array[ offset + 3 ] = te[ 3 ];
  2707. array[ offset + 4 ] = te[ 4 ];
  2708. array[ offset + 5 ] = te[ 5 ];
  2709. array[ offset + 6 ] = te[ 6 ];
  2710. array[ offset + 7 ] = te[ 7 ];
  2711. array[ offset + 8 ] = te[ 8 ];
  2712. return array;
  2713. },
  2714. getNormalMatrix: function ( m ) {
  2715. // input: THREE.Matrix4
  2716. this.getInverse( m ).transpose();
  2717. return this;
  2718. },
  2719. transposeIntoArray: function ( r ) {
  2720. var m = this.elements;
  2721. r[ 0 ] = m[ 0 ];
  2722. r[ 1 ] = m[ 3 ];
  2723. r[ 2 ] = m[ 6 ];
  2724. r[ 3 ] = m[ 1 ];
  2725. r[ 4 ] = m[ 4 ];
  2726. r[ 5 ] = m[ 7 ];
  2727. r[ 6 ] = m[ 2 ];
  2728. r[ 7 ] = m[ 5 ];
  2729. r[ 8 ] = m[ 8 ];
  2730. return this;
  2731. },
  2732. fromArray: function ( array ) {
  2733. this.elements.set( array );
  2734. return this;
  2735. },
  2736. toArray: function () {
  2737. var te = this.elements;
  2738. return [
  2739. te[ 0 ], te[ 1 ], te[ 2 ],
  2740. te[ 3 ], te[ 4 ], te[ 5 ],
  2741. te[ 6 ], te[ 7 ], te[ 8 ]
  2742. ];
  2743. },
  2744. clone: function () {
  2745. return new THREE.Matrix3().fromArray( this.elements );
  2746. }
  2747. };
  2748. // File:src/math/Matrix4.js
  2749. /**
  2750. * @author mrdoob / http://mrdoob.com/
  2751. * @author supereggbert / http://www.paulbrunt.co.uk/
  2752. * @author philogb / http://blog.thejit.org/
  2753. * @author jordi_ros / http://plattsoft.com
  2754. * @author D1plo1d / http://github.com/D1plo1d
  2755. * @author alteredq / http://alteredqualia.com/
  2756. * @author mikael emtinger / http://gomo.se/
  2757. * @author timknip / http://www.floorplanner.com/
  2758. * @author bhouston / http://exocortex.com
  2759. * @author WestLangley / http://github.com/WestLangley
  2760. */
  2761. THREE.Matrix4 = function () {
  2762. this.elements = new Float32Array( [
  2763. 1, 0, 0, 0,
  2764. 0, 1, 0, 0,
  2765. 0, 0, 1, 0,
  2766. 0, 0, 0, 1
  2767. ] );
  2768. if ( arguments.length > 0 ) {
  2769. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2770. }
  2771. };
  2772. THREE.Matrix4.prototype = {
  2773. constructor: THREE.Matrix4,
  2774. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2775. var te = this.elements;
  2776. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2777. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2778. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2779. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2780. return this;
  2781. },
  2782. identity: function () {
  2783. this.set(
  2784. 1, 0, 0, 0,
  2785. 0, 1, 0, 0,
  2786. 0, 0, 1, 0,
  2787. 0, 0, 0, 1
  2788. );
  2789. return this;
  2790. },
  2791. copy: function ( m ) {
  2792. this.elements.set( m.elements );
  2793. return this;
  2794. },
  2795. extractPosition: function ( m ) {
  2796. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2797. return this.copyPosition( m );
  2798. },
  2799. copyPosition: function ( m ) {
  2800. var te = this.elements;
  2801. var me = m.elements;
  2802. te[ 12 ] = me[ 12 ];
  2803. te[ 13 ] = me[ 13 ];
  2804. te[ 14 ] = me[ 14 ];
  2805. return this;
  2806. },
  2807. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2808. var te = this.elements;
  2809. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2810. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2811. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2812. return this;
  2813. },
  2814. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2815. this.set(
  2816. xAxis.x, yAxis.x, zAxis.x, 0,
  2817. xAxis.y, yAxis.y, zAxis.y, 0,
  2818. xAxis.z, yAxis.z, zAxis.z, 0,
  2819. 0, 0, 0, 1
  2820. );
  2821. return this;
  2822. },
  2823. extractRotation: function () {
  2824. var v1;
  2825. return function ( m ) {
  2826. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2827. var te = this.elements;
  2828. var me = m.elements;
  2829. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2830. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2831. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2832. te[ 0 ] = me[ 0 ] * scaleX;
  2833. te[ 1 ] = me[ 1 ] * scaleX;
  2834. te[ 2 ] = me[ 2 ] * scaleX;
  2835. te[ 4 ] = me[ 4 ] * scaleY;
  2836. te[ 5 ] = me[ 5 ] * scaleY;
  2837. te[ 6 ] = me[ 6 ] * scaleY;
  2838. te[ 8 ] = me[ 8 ] * scaleZ;
  2839. te[ 9 ] = me[ 9 ] * scaleZ;
  2840. te[ 10 ] = me[ 10 ] * scaleZ;
  2841. return this;
  2842. };
  2843. }(),
  2844. makeRotationFromEuler: function ( euler ) {
  2845. if ( euler instanceof THREE.Euler === false ) {
  2846. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2847. }
  2848. var te = this.elements;
  2849. var x = euler.x, y = euler.y, z = euler.z;
  2850. var a = Math.cos( x ), b = Math.sin( x );
  2851. var c = Math.cos( y ), d = Math.sin( y );
  2852. var e = Math.cos( z ), f = Math.sin( z );
  2853. if ( euler.order === 'XYZ' ) {
  2854. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2855. te[ 0 ] = c * e;
  2856. te[ 4 ] = - c * f;
  2857. te[ 8 ] = d;
  2858. te[ 1 ] = af + be * d;
  2859. te[ 5 ] = ae - bf * d;
  2860. te[ 9 ] = - b * c;
  2861. te[ 2 ] = bf - ae * d;
  2862. te[ 6 ] = be + af * d;
  2863. te[ 10 ] = a * c;
  2864. } else if ( euler.order === 'YXZ' ) {
  2865. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2866. te[ 0 ] = ce + df * b;
  2867. te[ 4 ] = de * b - cf;
  2868. te[ 8 ] = a * d;
  2869. te[ 1 ] = a * f;
  2870. te[ 5 ] = a * e;
  2871. te[ 9 ] = - b;
  2872. te[ 2 ] = cf * b - de;
  2873. te[ 6 ] = df + ce * b;
  2874. te[ 10 ] = a * c;
  2875. } else if ( euler.order === 'ZXY' ) {
  2876. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2877. te[ 0 ] = ce - df * b;
  2878. te[ 4 ] = - a * f;
  2879. te[ 8 ] = de + cf * b;
  2880. te[ 1 ] = cf + de * b;
  2881. te[ 5 ] = a * e;
  2882. te[ 9 ] = df - ce * b;
  2883. te[ 2 ] = - a * d;
  2884. te[ 6 ] = b;
  2885. te[ 10 ] = a * c;
  2886. } else if ( euler.order === 'ZYX' ) {
  2887. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2888. te[ 0 ] = c * e;
  2889. te[ 4 ] = be * d - af;
  2890. te[ 8 ] = ae * d + bf;
  2891. te[ 1 ] = c * f;
  2892. te[ 5 ] = bf * d + ae;
  2893. te[ 9 ] = af * d - be;
  2894. te[ 2 ] = - d;
  2895. te[ 6 ] = b * c;
  2896. te[ 10 ] = a * c;
  2897. } else if ( euler.order === 'YZX' ) {
  2898. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2899. te[ 0 ] = c * e;
  2900. te[ 4 ] = bd - ac * f;
  2901. te[ 8 ] = bc * f + ad;
  2902. te[ 1 ] = f;
  2903. te[ 5 ] = a * e;
  2904. te[ 9 ] = - b * e;
  2905. te[ 2 ] = - d * e;
  2906. te[ 6 ] = ad * f + bc;
  2907. te[ 10 ] = ac - bd * f;
  2908. } else if ( euler.order === 'XZY' ) {
  2909. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2910. te[ 0 ] = c * e;
  2911. te[ 4 ] = - f;
  2912. te[ 8 ] = d * e;
  2913. te[ 1 ] = ac * f + bd;
  2914. te[ 5 ] = a * e;
  2915. te[ 9 ] = ad * f - bc;
  2916. te[ 2 ] = bc * f - ad;
  2917. te[ 6 ] = b * e;
  2918. te[ 10 ] = bd * f + ac;
  2919. }
  2920. // last column
  2921. te[ 3 ] = 0;
  2922. te[ 7 ] = 0;
  2923. te[ 11 ] = 0;
  2924. // bottom row
  2925. te[ 12 ] = 0;
  2926. te[ 13 ] = 0;
  2927. te[ 14 ] = 0;
  2928. te[ 15 ] = 1;
  2929. return this;
  2930. },
  2931. setRotationFromQuaternion: function ( q ) {
  2932. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2933. return this.makeRotationFromQuaternion( q );
  2934. },
  2935. makeRotationFromQuaternion: function ( q ) {
  2936. var te = this.elements;
  2937. var x = q.x, y = q.y, z = q.z, w = q.w;
  2938. var x2 = x + x, y2 = y + y, z2 = z + z;
  2939. var xx = x * x2, xy = x * y2, xz = x * z2;
  2940. var yy = y * y2, yz = y * z2, zz = z * z2;
  2941. var wx = w * x2, wy = w * y2, wz = w * z2;
  2942. te[ 0 ] = 1 - ( yy + zz );
  2943. te[ 4 ] = xy - wz;
  2944. te[ 8 ] = xz + wy;
  2945. te[ 1 ] = xy + wz;
  2946. te[ 5 ] = 1 - ( xx + zz );
  2947. te[ 9 ] = yz - wx;
  2948. te[ 2 ] = xz - wy;
  2949. te[ 6 ] = yz + wx;
  2950. te[ 10 ] = 1 - ( xx + yy );
  2951. // last column
  2952. te[ 3 ] = 0;
  2953. te[ 7 ] = 0;
  2954. te[ 11 ] = 0;
  2955. // bottom row
  2956. te[ 12 ] = 0;
  2957. te[ 13 ] = 0;
  2958. te[ 14 ] = 0;
  2959. te[ 15 ] = 1;
  2960. return this;
  2961. },
  2962. lookAt: function () {
  2963. var x, y, z;
  2964. return function ( eye, target, up ) {
  2965. if ( x === undefined ) x = new THREE.Vector3();
  2966. if ( y === undefined ) y = new THREE.Vector3();
  2967. if ( z === undefined ) z = new THREE.Vector3();
  2968. var te = this.elements;
  2969. z.subVectors( eye, target ).normalize();
  2970. if ( z.length() === 0 ) {
  2971. z.z = 1;
  2972. }
  2973. x.crossVectors( up, z ).normalize();
  2974. if ( x.length() === 0 ) {
  2975. z.x += 0.0001;
  2976. x.crossVectors( up, z ).normalize();
  2977. }
  2978. y.crossVectors( z, x );
  2979. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2980. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2981. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2982. return this;
  2983. };
  2984. }(),
  2985. multiply: function ( m, n ) {
  2986. if ( n !== undefined ) {
  2987. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2988. return this.multiplyMatrices( m, n );
  2989. }
  2990. return this.multiplyMatrices( this, m );
  2991. },
  2992. multiplyMatrices: function ( a, b ) {
  2993. var ae = a.elements;
  2994. var be = b.elements;
  2995. var te = this.elements;
  2996. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2997. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2998. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2999. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3000. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3001. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3002. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3003. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3004. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3005. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3006. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3007. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3008. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3009. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3010. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3011. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3012. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3013. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3014. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3015. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3016. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3017. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3018. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3019. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3020. return this;
  3021. },
  3022. multiplyToArray: function ( a, b, r ) {
  3023. var te = this.elements;
  3024. this.multiplyMatrices( a, b );
  3025. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3026. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3027. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3028. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3029. return this;
  3030. },
  3031. multiplyScalar: function ( s ) {
  3032. var te = this.elements;
  3033. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3034. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3035. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3036. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3037. return this;
  3038. },
  3039. multiplyVector3: function ( vector ) {
  3040. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  3041. return vector.applyProjection( this );
  3042. },
  3043. multiplyVector4: function ( vector ) {
  3044. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3045. return vector.applyMatrix4( this );
  3046. },
  3047. multiplyVector3Array: function ( a ) {
  3048. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  3049. return this.applyToVector3Array( a );
  3050. },
  3051. applyToVector3Array: function () {
  3052. var v1;
  3053. return function ( array, offset, length ) {
  3054. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3055. if ( offset === undefined ) offset = 0;
  3056. if ( length === undefined ) length = array.length;
  3057. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3058. v1.fromArray( array, j );
  3059. v1.applyMatrix4( this );
  3060. v1.toArray( array, j );
  3061. }
  3062. return array;
  3063. };
  3064. }(),
  3065. applyToBuffer: function () {
  3066. var v1;
  3067. return function applyToBuffer( buffer, offset, length ) {
  3068. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3069. if ( offset === undefined ) offset = 0;
  3070. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3071. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3072. v1.x = buffer.getX( j );
  3073. v1.y = buffer.getY( j );
  3074. v1.z = buffer.getZ( j );
  3075. v1.applyMatrix4( this );
  3076. buffer.setXYZ( v1.x, v1.y, v1.z );
  3077. }
  3078. return buffer;
  3079. };
  3080. }(),
  3081. rotateAxis: function ( v ) {
  3082. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  3083. v.transformDirection( this );
  3084. },
  3085. crossVector: function ( vector ) {
  3086. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3087. return vector.applyMatrix4( this );
  3088. },
  3089. determinant: function () {
  3090. var te = this.elements;
  3091. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3092. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3093. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3094. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3095. //TODO: make this more efficient
  3096. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3097. return (
  3098. n41 * (
  3099. + n14 * n23 * n32
  3100. - n13 * n24 * n32
  3101. - n14 * n22 * n33
  3102. + n12 * n24 * n33
  3103. + n13 * n22 * n34
  3104. - n12 * n23 * n34
  3105. ) +
  3106. n42 * (
  3107. + n11 * n23 * n34
  3108. - n11 * n24 * n33
  3109. + n14 * n21 * n33
  3110. - n13 * n21 * n34
  3111. + n13 * n24 * n31
  3112. - n14 * n23 * n31
  3113. ) +
  3114. n43 * (
  3115. + n11 * n24 * n32
  3116. - n11 * n22 * n34
  3117. - n14 * n21 * n32
  3118. + n12 * n21 * n34
  3119. + n14 * n22 * n31
  3120. - n12 * n24 * n31
  3121. ) +
  3122. n44 * (
  3123. - n13 * n22 * n31
  3124. - n11 * n23 * n32
  3125. + n11 * n22 * n33
  3126. + n13 * n21 * n32
  3127. - n12 * n21 * n33
  3128. + n12 * n23 * n31
  3129. )
  3130. );
  3131. },
  3132. transpose: function () {
  3133. var te = this.elements;
  3134. var tmp;
  3135. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3136. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3137. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3138. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3139. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3140. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3141. return this;
  3142. },
  3143. flattenToArrayOffset: function ( array, offset ) {
  3144. var te = this.elements;
  3145. array[ offset ] = te[ 0 ];
  3146. array[ offset + 1 ] = te[ 1 ];
  3147. array[ offset + 2 ] = te[ 2 ];
  3148. array[ offset + 3 ] = te[ 3 ];
  3149. array[ offset + 4 ] = te[ 4 ];
  3150. array[ offset + 5 ] = te[ 5 ];
  3151. array[ offset + 6 ] = te[ 6 ];
  3152. array[ offset + 7 ] = te[ 7 ];
  3153. array[ offset + 8 ] = te[ 8 ];
  3154. array[ offset + 9 ] = te[ 9 ];
  3155. array[ offset + 10 ] = te[ 10 ];
  3156. array[ offset + 11 ] = te[ 11 ];
  3157. array[ offset + 12 ] = te[ 12 ];
  3158. array[ offset + 13 ] = te[ 13 ];
  3159. array[ offset + 14 ] = te[ 14 ];
  3160. array[ offset + 15 ] = te[ 15 ];
  3161. return array;
  3162. },
  3163. getPosition: function () {
  3164. var v1;
  3165. return function () {
  3166. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3167. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3168. var te = this.elements;
  3169. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3170. };
  3171. }(),
  3172. setPosition: function ( v ) {
  3173. var te = this.elements;
  3174. te[ 12 ] = v.x;
  3175. te[ 13 ] = v.y;
  3176. te[ 14 ] = v.z;
  3177. return this;
  3178. },
  3179. getInverse: function ( m, throwOnInvertible ) {
  3180. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3181. var te = this.elements;
  3182. var me = m.elements;
  3183. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3184. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3185. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3186. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3187. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3188. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3189. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3190. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3191. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3192. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3193. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3194. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3195. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3196. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3197. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3198. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3199. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3200. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3201. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3202. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3203. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3204. if ( det === 0 ) {
  3205. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3206. if ( throwOnInvertible || false ) {
  3207. throw new Error( msg );
  3208. } else {
  3209. console.warn( msg );
  3210. }
  3211. this.identity();
  3212. return this;
  3213. }
  3214. this.multiplyScalar( 1 / det );
  3215. return this;
  3216. },
  3217. translate: function ( v ) {
  3218. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3219. },
  3220. rotateX: function ( angle ) {
  3221. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3222. },
  3223. rotateY: function ( angle ) {
  3224. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3225. },
  3226. rotateZ: function ( angle ) {
  3227. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3228. },
  3229. rotateByAxis: function ( axis, angle ) {
  3230. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3231. },
  3232. scale: function ( v ) {
  3233. var te = this.elements;
  3234. var x = v.x, y = v.y, z = v.z;
  3235. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3236. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3237. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3238. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3239. return this;
  3240. },
  3241. getMaxScaleOnAxis: function () {
  3242. var te = this.elements;
  3243. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3244. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3245. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3246. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  3247. },
  3248. makeTranslation: function ( x, y, z ) {
  3249. this.set(
  3250. 1, 0, 0, x,
  3251. 0, 1, 0, y,
  3252. 0, 0, 1, z,
  3253. 0, 0, 0, 1
  3254. );
  3255. return this;
  3256. },
  3257. makeRotationX: function ( theta ) {
  3258. var c = Math.cos( theta ), s = Math.sin( theta );
  3259. this.set(
  3260. 1, 0, 0, 0,
  3261. 0, c, - s, 0,
  3262. 0, s, c, 0,
  3263. 0, 0, 0, 1
  3264. );
  3265. return this;
  3266. },
  3267. makeRotationY: function ( theta ) {
  3268. var c = Math.cos( theta ), s = Math.sin( theta );
  3269. this.set(
  3270. c, 0, s, 0,
  3271. 0, 1, 0, 0,
  3272. - s, 0, c, 0,
  3273. 0, 0, 0, 1
  3274. );
  3275. return this;
  3276. },
  3277. makeRotationZ: function ( theta ) {
  3278. var c = Math.cos( theta ), s = Math.sin( theta );
  3279. this.set(
  3280. c, - s, 0, 0,
  3281. s, c, 0, 0,
  3282. 0, 0, 1, 0,
  3283. 0, 0, 0, 1
  3284. );
  3285. return this;
  3286. },
  3287. makeRotationAxis: function ( axis, angle ) {
  3288. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3289. var c = Math.cos( angle );
  3290. var s = Math.sin( angle );
  3291. var t = 1 - c;
  3292. var x = axis.x, y = axis.y, z = axis.z;
  3293. var tx = t * x, ty = t * y;
  3294. this.set(
  3295. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3296. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3297. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3298. 0, 0, 0, 1
  3299. );
  3300. return this;
  3301. },
  3302. makeScale: function ( x, y, z ) {
  3303. this.set(
  3304. x, 0, 0, 0,
  3305. 0, y, 0, 0,
  3306. 0, 0, z, 0,
  3307. 0, 0, 0, 1
  3308. );
  3309. return this;
  3310. },
  3311. compose: function ( position, quaternion, scale ) {
  3312. this.makeRotationFromQuaternion( quaternion );
  3313. this.scale( scale );
  3314. this.setPosition( position );
  3315. return this;
  3316. },
  3317. decompose: function () {
  3318. var vector, matrix;
  3319. return function ( position, quaternion, scale ) {
  3320. if ( vector === undefined ) vector = new THREE.Vector3();
  3321. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3322. var te = this.elements;
  3323. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3324. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3325. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3326. // if determine is negative, we need to invert one scale
  3327. var det = this.determinant();
  3328. if ( det < 0 ) {
  3329. sx = - sx;
  3330. }
  3331. position.x = te[ 12 ];
  3332. position.y = te[ 13 ];
  3333. position.z = te[ 14 ];
  3334. // scale the rotation part
  3335. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3336. var invSX = 1 / sx;
  3337. var invSY = 1 / sy;
  3338. var invSZ = 1 / sz;
  3339. matrix.elements[ 0 ] *= invSX;
  3340. matrix.elements[ 1 ] *= invSX;
  3341. matrix.elements[ 2 ] *= invSX;
  3342. matrix.elements[ 4 ] *= invSY;
  3343. matrix.elements[ 5 ] *= invSY;
  3344. matrix.elements[ 6 ] *= invSY;
  3345. matrix.elements[ 8 ] *= invSZ;
  3346. matrix.elements[ 9 ] *= invSZ;
  3347. matrix.elements[ 10 ] *= invSZ;
  3348. quaternion.setFromRotationMatrix( matrix );
  3349. scale.x = sx;
  3350. scale.y = sy;
  3351. scale.z = sz;
  3352. return this;
  3353. };
  3354. }(),
  3355. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3356. var te = this.elements;
  3357. var x = 2 * near / ( right - left );
  3358. var y = 2 * near / ( top - bottom );
  3359. var a = ( right + left ) / ( right - left );
  3360. var b = ( top + bottom ) / ( top - bottom );
  3361. var c = - ( far + near ) / ( far - near );
  3362. var d = - 2 * far * near / ( far - near );
  3363. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3364. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3365. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3366. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3367. return this;
  3368. },
  3369. makePerspective: function ( fov, aspect, near, far ) {
  3370. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3371. var ymin = - ymax;
  3372. var xmin = ymin * aspect;
  3373. var xmax = ymax * aspect;
  3374. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3375. },
  3376. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3377. var te = this.elements;
  3378. var w = right - left;
  3379. var h = top - bottom;
  3380. var p = far - near;
  3381. var x = ( right + left ) / w;
  3382. var y = ( top + bottom ) / h;
  3383. var z = ( far + near ) / p;
  3384. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3385. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3386. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3387. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3388. return this;
  3389. },
  3390. equals: function ( matrix ) {
  3391. var te = this.elements;
  3392. var me = matrix.elements;
  3393. for ( var i = 0; i < 16; i ++ ) {
  3394. if ( te[ i ] !== me[ i ] ) return false;
  3395. }
  3396. return true;
  3397. },
  3398. fromArray: function ( array ) {
  3399. this.elements.set( array );
  3400. return this;
  3401. },
  3402. toArray: function () {
  3403. var te = this.elements;
  3404. return [
  3405. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3406. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3407. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3408. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3409. ];
  3410. },
  3411. clone: function () {
  3412. return new THREE.Matrix4().fromArray( this.elements );
  3413. }
  3414. };
  3415. // File:src/math/Ray.js
  3416. /**
  3417. * @author bhouston / http://exocortex.com
  3418. */
  3419. THREE.Ray = function ( origin, direction ) {
  3420. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3421. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3422. };
  3423. THREE.Ray.prototype = {
  3424. constructor: THREE.Ray,
  3425. set: function ( origin, direction ) {
  3426. this.origin.copy( origin );
  3427. this.direction.copy( direction );
  3428. return this;
  3429. },
  3430. copy: function ( ray ) {
  3431. this.origin.copy( ray.origin );
  3432. this.direction.copy( ray.direction );
  3433. return this;
  3434. },
  3435. at: function ( t, optionalTarget ) {
  3436. var result = optionalTarget || new THREE.Vector3();
  3437. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3438. },
  3439. recast: function () {
  3440. var v1 = new THREE.Vector3();
  3441. return function ( t ) {
  3442. this.origin.copy( this.at( t, v1 ) );
  3443. return this;
  3444. };
  3445. }(),
  3446. closestPointToPoint: function ( point, optionalTarget ) {
  3447. var result = optionalTarget || new THREE.Vector3();
  3448. result.subVectors( point, this.origin );
  3449. var directionDistance = result.dot( this.direction );
  3450. if ( directionDistance < 0 ) {
  3451. return result.copy( this.origin );
  3452. }
  3453. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3454. },
  3455. distanceToPoint: function ( point ) {
  3456. return Math.sqrt( this.distanceSqToPoint( point ) );
  3457. },
  3458. distanceSqToPoint: function () {
  3459. var v1 = new THREE.Vector3();
  3460. return function ( point ) {
  3461. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3462. // point behind the ray
  3463. if ( directionDistance < 0 ) {
  3464. return this.origin.distanceToSquared( point );
  3465. }
  3466. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3467. return v1.distanceToSquared( point );
  3468. };
  3469. }(),
  3470. distanceSqToSegment: function () {
  3471. var segCenter = new THREE.Vector3();
  3472. var segDir = new THREE.Vector3();
  3473. var diff = new THREE.Vector3();
  3474. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3475. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3476. // It returns the min distance between the ray and the segment
  3477. // defined by v0 and v1
  3478. // It can also set two optional targets :
  3479. // - The closest point on the ray
  3480. // - The closest point on the segment
  3481. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3482. segDir.copy( v1 ).sub( v0 ).normalize();
  3483. diff.copy( this.origin ).sub( segCenter );
  3484. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3485. var a01 = - this.direction.dot( segDir );
  3486. var b0 = diff.dot( this.direction );
  3487. var b1 = - diff.dot( segDir );
  3488. var c = diff.lengthSq();
  3489. var det = Math.abs( 1 - a01 * a01 );
  3490. var s0, s1, sqrDist, extDet;
  3491. if ( det > 0 ) {
  3492. // The ray and segment are not parallel.
  3493. s0 = a01 * b1 - b0;
  3494. s1 = a01 * b0 - b1;
  3495. extDet = segExtent * det;
  3496. if ( s0 >= 0 ) {
  3497. if ( s1 >= - extDet ) {
  3498. if ( s1 <= extDet ) {
  3499. // region 0
  3500. // Minimum at interior points of ray and segment.
  3501. var invDet = 1 / det;
  3502. s0 *= invDet;
  3503. s1 *= invDet;
  3504. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3505. } else {
  3506. // region 1
  3507. s1 = segExtent;
  3508. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3509. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3510. }
  3511. } else {
  3512. // region 5
  3513. s1 = - segExtent;
  3514. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3515. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3516. }
  3517. } else {
  3518. if ( s1 <= - extDet ) {
  3519. // region 4
  3520. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3521. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3522. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3523. } else if ( s1 <= extDet ) {
  3524. // region 3
  3525. s0 = 0;
  3526. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3527. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3528. } else {
  3529. // region 2
  3530. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3531. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3532. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3533. }
  3534. }
  3535. } else {
  3536. // Ray and segment are parallel.
  3537. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3538. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3539. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3540. }
  3541. if ( optionalPointOnRay ) {
  3542. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3543. }
  3544. if ( optionalPointOnSegment ) {
  3545. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3546. }
  3547. return sqrDist;
  3548. };
  3549. }(),
  3550. isIntersectionSphere: function ( sphere ) {
  3551. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3552. },
  3553. intersectSphere: function () {
  3554. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3555. var v1 = new THREE.Vector3();
  3556. return function ( sphere, optionalTarget ) {
  3557. v1.subVectors( sphere.center, this.origin );
  3558. var tca = v1.dot( this.direction );
  3559. var d2 = v1.dot( v1 ) - tca * tca;
  3560. var radius2 = sphere.radius * sphere.radius;
  3561. if ( d2 > radius2 ) return null;
  3562. var thc = Math.sqrt( radius2 - d2 );
  3563. // t0 = first intersect point - entrance on front of sphere
  3564. var t0 = tca - thc;
  3565. // t1 = second intersect point - exit point on back of sphere
  3566. var t1 = tca + thc;
  3567. // test to see if both t0 and t1 are behind the ray - if so, return null
  3568. if ( t0 < 0 && t1 < 0 ) return null;
  3569. // test to see if t0 is behind the ray:
  3570. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3571. // in order to always return an intersect point that is in front of the ray.
  3572. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3573. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3574. return this.at( t0, optionalTarget );
  3575. }
  3576. }(),
  3577. isIntersectionPlane: function ( plane ) {
  3578. // check if the ray lies on the plane first
  3579. var distToPoint = plane.distanceToPoint( this.origin );
  3580. if ( distToPoint === 0 ) {
  3581. return true;
  3582. }
  3583. var denominator = plane.normal.dot( this.direction );
  3584. if ( denominator * distToPoint < 0 ) {
  3585. return true;
  3586. }
  3587. // ray origin is behind the plane (and is pointing behind it)
  3588. return false;
  3589. },
  3590. distanceToPlane: function ( plane ) {
  3591. var denominator = plane.normal.dot( this.direction );
  3592. if ( denominator === 0 ) {
  3593. // line is coplanar, return origin
  3594. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3595. return 0;
  3596. }
  3597. // Null is preferable to undefined since undefined means.... it is undefined
  3598. return null;
  3599. }
  3600. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3601. // Return if the ray never intersects the plane
  3602. return t >= 0 ? t : null;
  3603. },
  3604. intersectPlane: function ( plane, optionalTarget ) {
  3605. var t = this.distanceToPlane( plane );
  3606. if ( t === null ) {
  3607. return null;
  3608. }
  3609. return this.at( t, optionalTarget );
  3610. },
  3611. isIntersectionBox: function () {
  3612. var v = new THREE.Vector3();
  3613. return function ( box ) {
  3614. return this.intersectBox( box, v ) !== null;
  3615. };
  3616. }(),
  3617. intersectBox: function ( box, optionalTarget ) {
  3618. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3619. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3620. var invdirx = 1 / this.direction.x,
  3621. invdiry = 1 / this.direction.y,
  3622. invdirz = 1 / this.direction.z;
  3623. var origin = this.origin;
  3624. if ( invdirx >= 0 ) {
  3625. tmin = ( box.min.x - origin.x ) * invdirx;
  3626. tmax = ( box.max.x - origin.x ) * invdirx;
  3627. } else {
  3628. tmin = ( box.max.x - origin.x ) * invdirx;
  3629. tmax = ( box.min.x - origin.x ) * invdirx;
  3630. }
  3631. if ( invdiry >= 0 ) {
  3632. tymin = ( box.min.y - origin.y ) * invdiry;
  3633. tymax = ( box.max.y - origin.y ) * invdiry;
  3634. } else {
  3635. tymin = ( box.max.y - origin.y ) * invdiry;
  3636. tymax = ( box.min.y - origin.y ) * invdiry;
  3637. }
  3638. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3639. // These lines also handle the case where tmin or tmax is NaN
  3640. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3641. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3642. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3643. if ( invdirz >= 0 ) {
  3644. tzmin = ( box.min.z - origin.z ) * invdirz;
  3645. tzmax = ( box.max.z - origin.z ) * invdirz;
  3646. } else {
  3647. tzmin = ( box.max.z - origin.z ) * invdirz;
  3648. tzmax = ( box.min.z - origin.z ) * invdirz;
  3649. }
  3650. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3651. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3652. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3653. //return point closest to the ray (positive side)
  3654. if ( tmax < 0 ) return null;
  3655. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3656. },
  3657. intersectTriangle: function () {
  3658. // Compute the offset origin, edges, and normal.
  3659. var diff = new THREE.Vector3();
  3660. var edge1 = new THREE.Vector3();
  3661. var edge2 = new THREE.Vector3();
  3662. var normal = new THREE.Vector3();
  3663. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3664. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3665. edge1.subVectors( b, a );
  3666. edge2.subVectors( c, a );
  3667. normal.crossVectors( edge1, edge2 );
  3668. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3669. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3670. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3671. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3672. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3673. var DdN = this.direction.dot( normal );
  3674. var sign;
  3675. if ( DdN > 0 ) {
  3676. if ( backfaceCulling ) return null;
  3677. sign = 1;
  3678. } else if ( DdN < 0 ) {
  3679. sign = - 1;
  3680. DdN = - DdN;
  3681. } else {
  3682. return null;
  3683. }
  3684. diff.subVectors( this.origin, a );
  3685. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3686. // b1 < 0, no intersection
  3687. if ( DdQxE2 < 0 ) {
  3688. return null;
  3689. }
  3690. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3691. // b2 < 0, no intersection
  3692. if ( DdE1xQ < 0 ) {
  3693. return null;
  3694. }
  3695. // b1+b2 > 1, no intersection
  3696. if ( DdQxE2 + DdE1xQ > DdN ) {
  3697. return null;
  3698. }
  3699. // Line intersects triangle, check if ray does.
  3700. var QdN = - sign * diff.dot( normal );
  3701. // t < 0, no intersection
  3702. if ( QdN < 0 ) {
  3703. return null;
  3704. }
  3705. // Ray intersects triangle.
  3706. return this.at( QdN / DdN, optionalTarget );
  3707. };
  3708. }(),
  3709. applyMatrix4: function ( matrix4 ) {
  3710. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3711. this.origin.applyMatrix4( matrix4 );
  3712. this.direction.sub( this.origin );
  3713. this.direction.normalize();
  3714. return this;
  3715. },
  3716. equals: function ( ray ) {
  3717. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3718. },
  3719. clone: function () {
  3720. return new THREE.Ray().copy( this );
  3721. }
  3722. };
  3723. // File:src/math/Sphere.js
  3724. /**
  3725. * @author bhouston / http://exocortex.com
  3726. * @author mrdoob / http://mrdoob.com/
  3727. */
  3728. THREE.Sphere = function ( center, radius ) {
  3729. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3730. this.radius = ( radius !== undefined ) ? radius : 0;
  3731. };
  3732. THREE.Sphere.prototype = {
  3733. constructor: THREE.Sphere,
  3734. set: function ( center, radius ) {
  3735. this.center.copy( center );
  3736. this.radius = radius;
  3737. return this;
  3738. },
  3739. setFromPoints: function () {
  3740. var box = new THREE.Box3();
  3741. return function ( points, optionalCenter ) {
  3742. var center = this.center;
  3743. if ( optionalCenter !== undefined ) {
  3744. center.copy( optionalCenter );
  3745. } else {
  3746. box.setFromPoints( points ).center( center );
  3747. }
  3748. var maxRadiusSq = 0;
  3749. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3750. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3751. }
  3752. this.radius = Math.sqrt( maxRadiusSq );
  3753. return this;
  3754. };
  3755. }(),
  3756. copy: function ( sphere ) {
  3757. this.center.copy( sphere.center );
  3758. this.radius = sphere.radius;
  3759. return this;
  3760. },
  3761. empty: function () {
  3762. return ( this.radius <= 0 );
  3763. },
  3764. containsPoint: function ( point ) {
  3765. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3766. },
  3767. distanceToPoint: function ( point ) {
  3768. return ( point.distanceTo( this.center ) - this.radius );
  3769. },
  3770. intersectsSphere: function ( sphere ) {
  3771. var radiusSum = this.radius + sphere.radius;
  3772. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3773. },
  3774. clampPoint: function ( point, optionalTarget ) {
  3775. var deltaLengthSq = this.center.distanceToSquared( point );
  3776. var result = optionalTarget || new THREE.Vector3();
  3777. result.copy( point );
  3778. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3779. result.sub( this.center ).normalize();
  3780. result.multiplyScalar( this.radius ).add( this.center );
  3781. }
  3782. return result;
  3783. },
  3784. getBoundingBox: function ( optionalTarget ) {
  3785. var box = optionalTarget || new THREE.Box3();
  3786. box.set( this.center, this.center );
  3787. box.expandByScalar( this.radius );
  3788. return box;
  3789. },
  3790. applyMatrix4: function ( matrix ) {
  3791. this.center.applyMatrix4( matrix );
  3792. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3793. return this;
  3794. },
  3795. translate: function ( offset ) {
  3796. this.center.add( offset );
  3797. return this;
  3798. },
  3799. equals: function ( sphere ) {
  3800. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3801. },
  3802. clone: function () {
  3803. return new THREE.Sphere().copy( this );
  3804. }
  3805. };
  3806. // File:src/math/Frustum.js
  3807. /**
  3808. * @author mrdoob / http://mrdoob.com/
  3809. * @author alteredq / http://alteredqualia.com/
  3810. * @author bhouston / http://exocortex.com
  3811. */
  3812. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3813. this.planes = [
  3814. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3815. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3816. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3817. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3818. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3819. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3820. ];
  3821. };
  3822. THREE.Frustum.prototype = {
  3823. constructor: THREE.Frustum,
  3824. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3825. var planes = this.planes;
  3826. planes[ 0 ].copy( p0 );
  3827. planes[ 1 ].copy( p1 );
  3828. planes[ 2 ].copy( p2 );
  3829. planes[ 3 ].copy( p3 );
  3830. planes[ 4 ].copy( p4 );
  3831. planes[ 5 ].copy( p5 );
  3832. return this;
  3833. },
  3834. copy: function ( frustum ) {
  3835. var planes = this.planes;
  3836. for ( var i = 0; i < 6; i ++ ) {
  3837. planes[ i ].copy( frustum.planes[ i ] );
  3838. }
  3839. return this;
  3840. },
  3841. setFromMatrix: function ( m ) {
  3842. var planes = this.planes;
  3843. var me = m.elements;
  3844. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3845. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3846. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3847. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3848. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3849. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3850. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3851. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3852. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3853. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3854. return this;
  3855. },
  3856. intersectsObject: function () {
  3857. var sphere = new THREE.Sphere();
  3858. return function ( object ) {
  3859. var geometry = object.geometry;
  3860. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3861. sphere.copy( geometry.boundingSphere );
  3862. sphere.applyMatrix4( object.matrixWorld );
  3863. return this.intersectsSphere( sphere );
  3864. };
  3865. }(),
  3866. intersectsSphere: function ( sphere ) {
  3867. var planes = this.planes;
  3868. var center = sphere.center;
  3869. var negRadius = - sphere.radius;
  3870. for ( var i = 0; i < 6; i ++ ) {
  3871. var distance = planes[ i ].distanceToPoint( center );
  3872. if ( distance < negRadius ) {
  3873. return false;
  3874. }
  3875. }
  3876. return true;
  3877. },
  3878. intersectsBox: function () {
  3879. var p1 = new THREE.Vector3(),
  3880. p2 = new THREE.Vector3();
  3881. return function ( box ) {
  3882. var planes = this.planes;
  3883. for ( var i = 0; i < 6 ; i ++ ) {
  3884. var plane = planes[ i ];
  3885. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3886. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3887. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3888. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3889. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3890. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3891. var d1 = plane.distanceToPoint( p1 );
  3892. var d2 = plane.distanceToPoint( p2 );
  3893. // if both outside plane, no intersection
  3894. if ( d1 < 0 && d2 < 0 ) {
  3895. return false;
  3896. }
  3897. }
  3898. return true;
  3899. };
  3900. }(),
  3901. containsPoint: function ( point ) {
  3902. var planes = this.planes;
  3903. for ( var i = 0; i < 6; i ++ ) {
  3904. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3905. return false;
  3906. }
  3907. }
  3908. return true;
  3909. },
  3910. clone: function () {
  3911. return new THREE.Frustum().copy( this );
  3912. }
  3913. };
  3914. // File:src/math/Plane.js
  3915. /**
  3916. * @author bhouston / http://exocortex.com
  3917. */
  3918. THREE.Plane = function ( normal, constant ) {
  3919. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3920. this.constant = ( constant !== undefined ) ? constant : 0;
  3921. };
  3922. THREE.Plane.prototype = {
  3923. constructor: THREE.Plane,
  3924. set: function ( normal, constant ) {
  3925. this.normal.copy( normal );
  3926. this.constant = constant;
  3927. return this;
  3928. },
  3929. setComponents: function ( x, y, z, w ) {
  3930. this.normal.set( x, y, z );
  3931. this.constant = w;
  3932. return this;
  3933. },
  3934. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3935. this.normal.copy( normal );
  3936. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3937. return this;
  3938. },
  3939. setFromCoplanarPoints: function () {
  3940. var v1 = new THREE.Vector3();
  3941. var v2 = new THREE.Vector3();
  3942. return function ( a, b, c ) {
  3943. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3944. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3945. this.setFromNormalAndCoplanarPoint( normal, a );
  3946. return this;
  3947. };
  3948. }(),
  3949. copy: function ( plane ) {
  3950. this.normal.copy( plane.normal );
  3951. this.constant = plane.constant;
  3952. return this;
  3953. },
  3954. normalize: function () {
  3955. // Note: will lead to a divide by zero if the plane is invalid.
  3956. var inverseNormalLength = 1.0 / this.normal.length();
  3957. this.normal.multiplyScalar( inverseNormalLength );
  3958. this.constant *= inverseNormalLength;
  3959. return this;
  3960. },
  3961. negate: function () {
  3962. this.constant *= - 1;
  3963. this.normal.negate();
  3964. return this;
  3965. },
  3966. distanceToPoint: function ( point ) {
  3967. return this.normal.dot( point ) + this.constant;
  3968. },
  3969. distanceToSphere: function ( sphere ) {
  3970. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3971. },
  3972. projectPoint: function ( point, optionalTarget ) {
  3973. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3974. },
  3975. orthoPoint: function ( point, optionalTarget ) {
  3976. var perpendicularMagnitude = this.distanceToPoint( point );
  3977. var result = optionalTarget || new THREE.Vector3();
  3978. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3979. },
  3980. isIntersectionLine: function ( line ) {
  3981. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3982. var startSign = this.distanceToPoint( line.start );
  3983. var endSign = this.distanceToPoint( line.end );
  3984. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3985. },
  3986. intersectLine: function () {
  3987. var v1 = new THREE.Vector3();
  3988. return function ( line, optionalTarget ) {
  3989. var result = optionalTarget || new THREE.Vector3();
  3990. var direction = line.delta( v1 );
  3991. var denominator = this.normal.dot( direction );
  3992. if ( denominator === 0 ) {
  3993. // line is coplanar, return origin
  3994. if ( this.distanceToPoint( line.start ) === 0 ) {
  3995. return result.copy( line.start );
  3996. }
  3997. // Unsure if this is the correct method to handle this case.
  3998. return undefined;
  3999. }
  4000. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4001. if ( t < 0 || t > 1 ) {
  4002. return undefined;
  4003. }
  4004. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4005. };
  4006. }(),
  4007. coplanarPoint: function ( optionalTarget ) {
  4008. var result = optionalTarget || new THREE.Vector3();
  4009. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4010. },
  4011. applyMatrix4: function () {
  4012. var v1 = new THREE.Vector3();
  4013. var v2 = new THREE.Vector3();
  4014. var m1 = new THREE.Matrix3();
  4015. return function ( matrix, optionalNormalMatrix ) {
  4016. // compute new normal based on theory here:
  4017. // http://www.songho.ca/opengl/gl_normaltransform.html
  4018. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4019. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4020. var newCoplanarPoint = this.coplanarPoint( v2 );
  4021. newCoplanarPoint.applyMatrix4( matrix );
  4022. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4023. return this;
  4024. };
  4025. }(),
  4026. translate: function ( offset ) {
  4027. this.constant = this.constant - offset.dot( this.normal );
  4028. return this;
  4029. },
  4030. equals: function ( plane ) {
  4031. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4032. },
  4033. clone: function () {
  4034. return new THREE.Plane().copy( this );
  4035. }
  4036. };
  4037. // File:src/math/Math.js
  4038. /**
  4039. * @author alteredq / http://alteredqualia.com/
  4040. * @author mrdoob / http://mrdoob.com/
  4041. */
  4042. THREE.Math = {
  4043. generateUUID: function () {
  4044. // http://www.broofa.com/Tools/Math.uuid.htm
  4045. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4046. var uuid = new Array( 36 );
  4047. var rnd = 0, r;
  4048. return function () {
  4049. for ( var i = 0; i < 36; i ++ ) {
  4050. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4051. uuid[ i ] = '-';
  4052. } else if ( i === 14 ) {
  4053. uuid[ i ] = '4';
  4054. } else {
  4055. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4056. r = rnd & 0xf;
  4057. rnd = rnd >> 4;
  4058. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4059. }
  4060. }
  4061. return uuid.join( '' );
  4062. };
  4063. }(),
  4064. // Clamp value to range <a, b>
  4065. clamp: function ( x, a, b ) {
  4066. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  4067. },
  4068. // Clamp value to range <a, inf)
  4069. clampBottom: function ( x, a ) {
  4070. return x < a ? a : x;
  4071. },
  4072. // compute euclidian modulo of m % n
  4073. // https://en.wikipedia.org/wiki/Modulo_operation
  4074. euclideanModulo: function ( n, m ) {
  4075. return ( ( n % m ) + m ) % m;
  4076. },
  4077. // Linear mapping from range <a1, a2> to range <b1, b2>
  4078. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4079. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4080. },
  4081. // http://en.wikipedia.org/wiki/Smoothstep
  4082. smoothstep: function ( x, min, max ) {
  4083. if ( x <= min ) return 0;
  4084. if ( x >= max ) return 1;
  4085. x = ( x - min ) / ( max - min );
  4086. return x * x * ( 3 - 2 * x );
  4087. },
  4088. smootherstep: function ( x, min, max ) {
  4089. if ( x <= min ) return 0;
  4090. if ( x >= max ) return 1;
  4091. x = ( x - min ) / ( max - min );
  4092. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4093. },
  4094. // Random float from <0, 1> with 16 bits of randomness
  4095. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4096. random16: function () {
  4097. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4098. },
  4099. // Random integer from <low, high> interval
  4100. randInt: function ( low, high ) {
  4101. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4102. },
  4103. // Random float from <low, high> interval
  4104. randFloat: function ( low, high ) {
  4105. return low + Math.random() * ( high - low );
  4106. },
  4107. // Random float from <-range/2, range/2> interval
  4108. randFloatSpread: function ( range ) {
  4109. return range * ( 0.5 - Math.random() );
  4110. },
  4111. degToRad: function () {
  4112. var degreeToRadiansFactor = Math.PI / 180;
  4113. return function ( degrees ) {
  4114. return degrees * degreeToRadiansFactor;
  4115. };
  4116. }(),
  4117. radToDeg: function () {
  4118. var radianToDegreesFactor = 180 / Math.PI;
  4119. return function ( radians ) {
  4120. return radians * radianToDegreesFactor;
  4121. };
  4122. }(),
  4123. isPowerOfTwo: function ( value ) {
  4124. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4125. },
  4126. nextPowerOfTwo: function ( value ) {
  4127. value --;
  4128. value |= value >> 1;
  4129. value |= value >> 2;
  4130. value |= value >> 4;
  4131. value |= value >> 8;
  4132. value |= value >> 16;
  4133. value ++;
  4134. return value;
  4135. }
  4136. };
  4137. // File:src/math/Spline.js
  4138. /**
  4139. * Spline from Tween.js, slightly optimized (and trashed)
  4140. * http://sole.github.com/tween.js/examples/05_spline.html
  4141. *
  4142. * @author mrdoob / http://mrdoob.com/
  4143. * @author alteredq / http://alteredqualia.com/
  4144. */
  4145. THREE.Spline = function ( points ) {
  4146. this.points = points;
  4147. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4148. point, intPoint, weight, w2, w3,
  4149. pa, pb, pc, pd;
  4150. this.initFromArray = function ( a ) {
  4151. this.points = [];
  4152. for ( var i = 0; i < a.length; i ++ ) {
  4153. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4154. }
  4155. };
  4156. this.getPoint = function ( k ) {
  4157. point = ( this.points.length - 1 ) * k;
  4158. intPoint = Math.floor( point );
  4159. weight = point - intPoint;
  4160. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4161. c[ 1 ] = intPoint;
  4162. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4163. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4164. pa = this.points[ c[ 0 ] ];
  4165. pb = this.points[ c[ 1 ] ];
  4166. pc = this.points[ c[ 2 ] ];
  4167. pd = this.points[ c[ 3 ] ];
  4168. w2 = weight * weight;
  4169. w3 = weight * w2;
  4170. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4171. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4172. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4173. return v3;
  4174. };
  4175. this.getControlPointsArray = function () {
  4176. var i, p, l = this.points.length,
  4177. coords = [];
  4178. for ( i = 0; i < l; i ++ ) {
  4179. p = this.points[ i ];
  4180. coords[ i ] = [ p.x, p.y, p.z ];
  4181. }
  4182. return coords;
  4183. };
  4184. // approximate length by summing linear segments
  4185. this.getLength = function ( nSubDivisions ) {
  4186. var i, index, nSamples, position,
  4187. point = 0, intPoint = 0, oldIntPoint = 0,
  4188. oldPosition = new THREE.Vector3(),
  4189. tmpVec = new THREE.Vector3(),
  4190. chunkLengths = [],
  4191. totalLength = 0;
  4192. // first point has 0 length
  4193. chunkLengths[ 0 ] = 0;
  4194. if ( ! nSubDivisions ) nSubDivisions = 100;
  4195. nSamples = this.points.length * nSubDivisions;
  4196. oldPosition.copy( this.points[ 0 ] );
  4197. for ( i = 1; i < nSamples; i ++ ) {
  4198. index = i / nSamples;
  4199. position = this.getPoint( index );
  4200. tmpVec.copy( position );
  4201. totalLength += tmpVec.distanceTo( oldPosition );
  4202. oldPosition.copy( position );
  4203. point = ( this.points.length - 1 ) * index;
  4204. intPoint = Math.floor( point );
  4205. if ( intPoint !== oldIntPoint ) {
  4206. chunkLengths[ intPoint ] = totalLength;
  4207. oldIntPoint = intPoint;
  4208. }
  4209. }
  4210. // last point ends with total length
  4211. chunkLengths[ chunkLengths.length ] = totalLength;
  4212. return { chunks: chunkLengths, total: totalLength };
  4213. };
  4214. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4215. var i, j,
  4216. index, indexCurrent, indexNext,
  4217. realDistance,
  4218. sampling, position,
  4219. newpoints = [],
  4220. tmpVec = new THREE.Vector3(),
  4221. sl = this.getLength();
  4222. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4223. for ( i = 1; i < this.points.length; i ++ ) {
  4224. //tmpVec.copy( this.points[ i - 1 ] );
  4225. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4226. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4227. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4228. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4229. indexNext = i / ( this.points.length - 1 );
  4230. for ( j = 1; j < sampling - 1; j ++ ) {
  4231. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4232. position = this.getPoint( index );
  4233. newpoints.push( tmpVec.copy( position ).clone() );
  4234. }
  4235. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4236. }
  4237. this.points = newpoints;
  4238. };
  4239. // Catmull-Rom
  4240. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4241. var v0 = ( p2 - p0 ) * 0.5,
  4242. v1 = ( p3 - p1 ) * 0.5;
  4243. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4244. }
  4245. };
  4246. // File:src/math/Triangle.js
  4247. /**
  4248. * @author bhouston / http://exocortex.com
  4249. * @author mrdoob / http://mrdoob.com/
  4250. */
  4251. THREE.Triangle = function ( a, b, c ) {
  4252. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4253. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4254. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4255. };
  4256. THREE.Triangle.normal = function () {
  4257. var v0 = new THREE.Vector3();
  4258. return function ( a, b, c, optionalTarget ) {
  4259. var result = optionalTarget || new THREE.Vector3();
  4260. result.subVectors( c, b );
  4261. v0.subVectors( a, b );
  4262. result.cross( v0 );
  4263. var resultLengthSq = result.lengthSq();
  4264. if ( resultLengthSq > 0 ) {
  4265. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4266. }
  4267. return result.set( 0, 0, 0 );
  4268. };
  4269. }();
  4270. // static/instance method to calculate barycentric coordinates
  4271. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4272. THREE.Triangle.barycoordFromPoint = function () {
  4273. var v0 = new THREE.Vector3();
  4274. var v1 = new THREE.Vector3();
  4275. var v2 = new THREE.Vector3();
  4276. return function ( point, a, b, c, optionalTarget ) {
  4277. v0.subVectors( c, a );
  4278. v1.subVectors( b, a );
  4279. v2.subVectors( point, a );
  4280. var dot00 = v0.dot( v0 );
  4281. var dot01 = v0.dot( v1 );
  4282. var dot02 = v0.dot( v2 );
  4283. var dot11 = v1.dot( v1 );
  4284. var dot12 = v1.dot( v2 );
  4285. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4286. var result = optionalTarget || new THREE.Vector3();
  4287. // collinear or singular triangle
  4288. if ( denom === 0 ) {
  4289. // arbitrary location outside of triangle?
  4290. // not sure if this is the best idea, maybe should be returning undefined
  4291. return result.set( - 2, - 1, - 1 );
  4292. }
  4293. var invDenom = 1 / denom;
  4294. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4295. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4296. // barycentric coordinates must always sum to 1
  4297. return result.set( 1 - u - v, v, u );
  4298. };
  4299. }();
  4300. THREE.Triangle.containsPoint = function () {
  4301. var v1 = new THREE.Vector3();
  4302. return function ( point, a, b, c ) {
  4303. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4304. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4305. };
  4306. }();
  4307. THREE.Triangle.prototype = {
  4308. constructor: THREE.Triangle,
  4309. set: function ( a, b, c ) {
  4310. this.a.copy( a );
  4311. this.b.copy( b );
  4312. this.c.copy( c );
  4313. return this;
  4314. },
  4315. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4316. this.a.copy( points[ i0 ] );
  4317. this.b.copy( points[ i1 ] );
  4318. this.c.copy( points[ i2 ] );
  4319. return this;
  4320. },
  4321. copy: function ( triangle ) {
  4322. this.a.copy( triangle.a );
  4323. this.b.copy( triangle.b );
  4324. this.c.copy( triangle.c );
  4325. return this;
  4326. },
  4327. area: function () {
  4328. var v0 = new THREE.Vector3();
  4329. var v1 = new THREE.Vector3();
  4330. return function () {
  4331. v0.subVectors( this.c, this.b );
  4332. v1.subVectors( this.a, this.b );
  4333. return v0.cross( v1 ).length() * 0.5;
  4334. };
  4335. }(),
  4336. midpoint: function ( optionalTarget ) {
  4337. var result = optionalTarget || new THREE.Vector3();
  4338. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4339. },
  4340. normal: function ( optionalTarget ) {
  4341. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4342. },
  4343. plane: function ( optionalTarget ) {
  4344. var result = optionalTarget || new THREE.Plane();
  4345. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4346. },
  4347. barycoordFromPoint: function ( point, optionalTarget ) {
  4348. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4349. },
  4350. containsPoint: function ( point ) {
  4351. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4352. },
  4353. equals: function ( triangle ) {
  4354. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4355. },
  4356. clone: function () {
  4357. return new THREE.Triangle().copy( this );
  4358. }
  4359. };
  4360. // File:src/core/Clock.js
  4361. /**
  4362. * @author alteredq / http://alteredqualia.com/
  4363. */
  4364. THREE.Clock = function ( autoStart ) {
  4365. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4366. this.startTime = 0;
  4367. this.oldTime = 0;
  4368. this.elapsedTime = 0;
  4369. this.running = false;
  4370. };
  4371. THREE.Clock.prototype = {
  4372. constructor: THREE.Clock,
  4373. start: function () {
  4374. this.startTime = self.performance !== undefined && self.performance.now !== undefined
  4375. ? self.performance.now()
  4376. : Date.now();
  4377. this.oldTime = this.startTime;
  4378. this.running = true;
  4379. },
  4380. stop: function () {
  4381. this.getElapsedTime();
  4382. this.running = false;
  4383. },
  4384. getElapsedTime: function () {
  4385. this.getDelta();
  4386. return this.elapsedTime;
  4387. },
  4388. getDelta: function () {
  4389. var diff = 0;
  4390. if ( this.autoStart && ! this.running ) {
  4391. this.start();
  4392. }
  4393. if ( this.running ) {
  4394. var newTime = self.performance !== undefined && self.performance.now !== undefined
  4395. ? self.performance.now()
  4396. : Date.now();
  4397. diff = 0.001 * ( newTime - this.oldTime );
  4398. this.oldTime = newTime;
  4399. this.elapsedTime += diff;
  4400. }
  4401. return diff;
  4402. }
  4403. };
  4404. // File:src/core/EventDispatcher.js
  4405. /**
  4406. * https://github.com/mrdoob/eventdispatcher.js/
  4407. */
  4408. THREE.EventDispatcher = function () {};
  4409. THREE.EventDispatcher.prototype = {
  4410. constructor: THREE.EventDispatcher,
  4411. apply: function ( object ) {
  4412. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4413. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4414. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4415. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4416. },
  4417. addEventListener: function ( type, listener ) {
  4418. if ( this._listeners === undefined ) this._listeners = {};
  4419. var listeners = this._listeners;
  4420. if ( listeners[ type ] === undefined ) {
  4421. listeners[ type ] = [];
  4422. }
  4423. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4424. listeners[ type ].push( listener );
  4425. }
  4426. },
  4427. hasEventListener: function ( type, listener ) {
  4428. if ( this._listeners === undefined ) return false;
  4429. var listeners = this._listeners;
  4430. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4431. return true;
  4432. }
  4433. return false;
  4434. },
  4435. removeEventListener: function ( type, listener ) {
  4436. if ( this._listeners === undefined ) return;
  4437. var listeners = this._listeners;
  4438. var listenerArray = listeners[ type ];
  4439. if ( listenerArray !== undefined ) {
  4440. var index = listenerArray.indexOf( listener );
  4441. if ( index !== - 1 ) {
  4442. listenerArray.splice( index, 1 );
  4443. }
  4444. }
  4445. },
  4446. dispatchEvent: function ( event ) {
  4447. if ( this._listeners === undefined ) return;
  4448. var listeners = this._listeners;
  4449. var listenerArray = listeners[ event.type ];
  4450. if ( listenerArray !== undefined ) {
  4451. event.target = this;
  4452. var array = [];
  4453. var length = listenerArray.length;
  4454. for ( var i = 0; i < length; i ++ ) {
  4455. array[ i ] = listenerArray[ i ];
  4456. }
  4457. for ( var i = 0; i < length; i ++ ) {
  4458. array[ i ].call( this, event );
  4459. }
  4460. }
  4461. }
  4462. };
  4463. // File:src/core/Raycaster.js
  4464. /**
  4465. * @author mrdoob / http://mrdoob.com/
  4466. * @author bhouston / http://exocortex.com/
  4467. * @author stephomi / http://stephaneginier.com/
  4468. */
  4469. ( function ( THREE ) {
  4470. THREE.Raycaster = function ( origin, direction, near, far ) {
  4471. this.ray = new THREE.Ray( origin, direction );
  4472. // direction is assumed to be normalized (for accurate distance calculations)
  4473. this.near = near || 0;
  4474. this.far = far || Infinity;
  4475. this.params = {
  4476. Sprite: {},
  4477. Mesh: {},
  4478. PointCloud: { threshold: 1 },
  4479. LOD: {},
  4480. Line: {}
  4481. };
  4482. };
  4483. var descSort = function ( a, b ) {
  4484. return a.distance - b.distance;
  4485. };
  4486. var intersectObject = function ( object, raycaster, intersects, recursive ) {
  4487. if ( object.visible === false ) return;
  4488. object.raycast( raycaster, intersects );
  4489. if ( recursive === true ) {
  4490. var children = object.children;
  4491. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4492. intersectObject( children[ i ], raycaster, intersects, true );
  4493. }
  4494. }
  4495. };
  4496. //
  4497. THREE.Raycaster.prototype = {
  4498. constructor: THREE.Raycaster,
  4499. linePrecision: 1,
  4500. set: function ( origin, direction ) {
  4501. // direction is assumed to be normalized (for accurate distance calculations)
  4502. this.ray.set( origin, direction );
  4503. },
  4504. setFromCamera: function ( coords, camera ) {
  4505. if ( camera instanceof THREE.PerspectiveCamera ) {
  4506. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4507. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4508. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4509. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4510. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4511. } else {
  4512. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4513. }
  4514. },
  4515. intersectObject: function ( object, recursive ) {
  4516. var intersects = [];
  4517. intersectObject( object, this, intersects, recursive );
  4518. intersects.sort( descSort );
  4519. return intersects;
  4520. },
  4521. intersectObjects: function ( objects, recursive ) {
  4522. var intersects = [];
  4523. if ( Array.isArray( objects ) === false ) {
  4524. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4525. return intersects;
  4526. }
  4527. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4528. intersectObject( objects[ i ], this, intersects, recursive );
  4529. }
  4530. intersects.sort( descSort );
  4531. return intersects;
  4532. }
  4533. };
  4534. }( THREE ) );
  4535. // File:src/core/Object3D.js
  4536. /**
  4537. * @author mrdoob / http://mrdoob.com/
  4538. * @author mikael emtinger / http://gomo.se/
  4539. * @author alteredq / http://alteredqualia.com/
  4540. * @author WestLangley / http://github.com/WestLangley
  4541. * @author elephantatwork / www.elephantatwork.ch
  4542. */
  4543. THREE.Object3D = function () {
  4544. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4545. this.uuid = THREE.Math.generateUUID();
  4546. this.name = '';
  4547. this.type = 'Object3D';
  4548. this.parent = undefined;
  4549. this.children = [];
  4550. this.up = THREE.Object3D.DefaultUp.clone();
  4551. var position = new THREE.Vector3();
  4552. var rotation = new THREE.Euler();
  4553. var quaternion = new THREE.Quaternion();
  4554. var scale = new THREE.Vector3( 1, 1, 1 );
  4555. var onRotationChange = function () {
  4556. quaternion.setFromEuler( rotation, false );
  4557. };
  4558. var onQuaternionChange = function () {
  4559. rotation.setFromQuaternion( quaternion, undefined, false );
  4560. };
  4561. rotation.onChange( onRotationChange );
  4562. quaternion.onChange( onQuaternionChange );
  4563. Object.defineProperties( this, {
  4564. position: {
  4565. enumerable: true,
  4566. value: position
  4567. },
  4568. rotation: {
  4569. enumerable: true,
  4570. value: rotation
  4571. },
  4572. quaternion: {
  4573. enumerable: true,
  4574. value: quaternion
  4575. },
  4576. scale: {
  4577. enumerable: true,
  4578. value: scale
  4579. }
  4580. } );
  4581. this.rotationAutoUpdate = true;
  4582. this.matrix = new THREE.Matrix4();
  4583. this.matrixWorld = new THREE.Matrix4();
  4584. this.matrixAutoUpdate = true;
  4585. this.matrixWorldNeedsUpdate = false;
  4586. this.visible = true;
  4587. this.castShadow = false;
  4588. this.receiveShadow = false;
  4589. this.frustumCulled = true;
  4590. this.renderOrder = 0;
  4591. this.userData = {};
  4592. };
  4593. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4594. THREE.Object3D.prototype = {
  4595. constructor: THREE.Object3D,
  4596. get eulerOrder () {
  4597. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4598. return this.rotation.order;
  4599. },
  4600. set eulerOrder ( value ) {
  4601. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4602. this.rotation.order = value;
  4603. },
  4604. get useQuaternion () {
  4605. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4606. },
  4607. set useQuaternion ( value ) {
  4608. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4609. },
  4610. set renderDepth ( value ) {
  4611. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  4612. },
  4613. applyMatrix: function ( matrix ) {
  4614. this.matrix.multiplyMatrices( matrix, this.matrix );
  4615. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4616. },
  4617. setRotationFromAxisAngle: function ( axis, angle ) {
  4618. // assumes axis is normalized
  4619. this.quaternion.setFromAxisAngle( axis, angle );
  4620. },
  4621. setRotationFromEuler: function ( euler ) {
  4622. this.quaternion.setFromEuler( euler, true );
  4623. },
  4624. setRotationFromMatrix: function ( m ) {
  4625. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4626. this.quaternion.setFromRotationMatrix( m );
  4627. },
  4628. setRotationFromQuaternion: function ( q ) {
  4629. // assumes q is normalized
  4630. this.quaternion.copy( q );
  4631. },
  4632. rotateOnAxis: function () {
  4633. // rotate object on axis in object space
  4634. // axis is assumed to be normalized
  4635. var q1 = new THREE.Quaternion();
  4636. return function ( axis, angle ) {
  4637. q1.setFromAxisAngle( axis, angle );
  4638. this.quaternion.multiply( q1 );
  4639. return this;
  4640. }
  4641. }(),
  4642. rotateX: function () {
  4643. var v1 = new THREE.Vector3( 1, 0, 0 );
  4644. return function ( angle ) {
  4645. return this.rotateOnAxis( v1, angle );
  4646. };
  4647. }(),
  4648. rotateY: function () {
  4649. var v1 = new THREE.Vector3( 0, 1, 0 );
  4650. return function ( angle ) {
  4651. return this.rotateOnAxis( v1, angle );
  4652. };
  4653. }(),
  4654. rotateZ: function () {
  4655. var v1 = new THREE.Vector3( 0, 0, 1 );
  4656. return function ( angle ) {
  4657. return this.rotateOnAxis( v1, angle );
  4658. };
  4659. }(),
  4660. translateOnAxis: function () {
  4661. // translate object by distance along axis in object space
  4662. // axis is assumed to be normalized
  4663. var v1 = new THREE.Vector3();
  4664. return function ( axis, distance ) {
  4665. v1.copy( axis ).applyQuaternion( this.quaternion );
  4666. this.position.add( v1.multiplyScalar( distance ) );
  4667. return this;
  4668. }
  4669. }(),
  4670. translate: function ( distance, axis ) {
  4671. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4672. return this.translateOnAxis( axis, distance );
  4673. },
  4674. translateX: function () {
  4675. var v1 = new THREE.Vector3( 1, 0, 0 );
  4676. return function ( distance ) {
  4677. return this.translateOnAxis( v1, distance );
  4678. };
  4679. }(),
  4680. translateY: function () {
  4681. var v1 = new THREE.Vector3( 0, 1, 0 );
  4682. return function ( distance ) {
  4683. return this.translateOnAxis( v1, distance );
  4684. };
  4685. }(),
  4686. translateZ: function () {
  4687. var v1 = new THREE.Vector3( 0, 0, 1 );
  4688. return function ( distance ) {
  4689. return this.translateOnAxis( v1, distance );
  4690. };
  4691. }(),
  4692. localToWorld: function ( vector ) {
  4693. return vector.applyMatrix4( this.matrixWorld );
  4694. },
  4695. worldToLocal: function () {
  4696. var m1 = new THREE.Matrix4();
  4697. return function ( vector ) {
  4698. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4699. };
  4700. }(),
  4701. lookAt: function () {
  4702. // This routine does not support objects with rotated and/or translated parent(s)
  4703. var m1 = new THREE.Matrix4();
  4704. return function ( vector ) {
  4705. m1.lookAt( vector, this.position, this.up );
  4706. this.quaternion.setFromRotationMatrix( m1 );
  4707. };
  4708. }(),
  4709. add: function ( object ) {
  4710. if ( arguments.length > 1 ) {
  4711. for ( var i = 0; i < arguments.length; i ++ ) {
  4712. this.add( arguments[ i ] );
  4713. }
  4714. return this;
  4715. }
  4716. if ( object === this ) {
  4717. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4718. return this;
  4719. }
  4720. if ( object instanceof THREE.Object3D ) {
  4721. if ( object.parent !== undefined ) {
  4722. object.parent.remove( object );
  4723. }
  4724. object.parent = this;
  4725. object.dispatchEvent( { type: 'added' } );
  4726. this.children.push( object );
  4727. } else {
  4728. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4729. }
  4730. return this;
  4731. },
  4732. remove: function ( object ) {
  4733. if ( arguments.length > 1 ) {
  4734. for ( var i = 0; i < arguments.length; i ++ ) {
  4735. this.remove( arguments[ i ] );
  4736. }
  4737. }
  4738. var index = this.children.indexOf( object );
  4739. if ( index !== - 1 ) {
  4740. object.parent = undefined;
  4741. object.dispatchEvent( { type: 'removed' } );
  4742. this.children.splice( index, 1 );
  4743. }
  4744. },
  4745. getChildByName: function ( name ) {
  4746. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4747. return this.getObjectByName( name );
  4748. },
  4749. getObjectById: function ( id ) {
  4750. return this.getObjectByProperty( 'id', id );
  4751. },
  4752. getObjectByName: function ( name ) {
  4753. return this.getObjectByProperty( 'name', name );
  4754. },
  4755. getObjectByProperty: function ( name, value ) {
  4756. if ( this[ name ] === value ) return this;
  4757. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4758. var child = this.children[ i ];
  4759. var object = child.getObjectByProperty( name, value );
  4760. if ( object !== undefined ) {
  4761. return object;
  4762. }
  4763. }
  4764. return undefined;
  4765. },
  4766. getWorldPosition: function ( optionalTarget ) {
  4767. var result = optionalTarget || new THREE.Vector3();
  4768. this.updateMatrixWorld( true );
  4769. return result.setFromMatrixPosition( this.matrixWorld );
  4770. },
  4771. getWorldQuaternion: function () {
  4772. var position = new THREE.Vector3();
  4773. var scale = new THREE.Vector3();
  4774. return function ( optionalTarget ) {
  4775. var result = optionalTarget || new THREE.Quaternion();
  4776. this.updateMatrixWorld( true );
  4777. this.matrixWorld.decompose( position, result, scale );
  4778. return result;
  4779. }
  4780. }(),
  4781. getWorldRotation: function () {
  4782. var quaternion = new THREE.Quaternion();
  4783. return function ( optionalTarget ) {
  4784. var result = optionalTarget || new THREE.Euler();
  4785. this.getWorldQuaternion( quaternion );
  4786. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4787. }
  4788. }(),
  4789. getWorldScale: function () {
  4790. var position = new THREE.Vector3();
  4791. var quaternion = new THREE.Quaternion();
  4792. return function ( optionalTarget ) {
  4793. var result = optionalTarget || new THREE.Vector3();
  4794. this.updateMatrixWorld( true );
  4795. this.matrixWorld.decompose( position, quaternion, result );
  4796. return result;
  4797. }
  4798. }(),
  4799. getWorldDirection: function () {
  4800. var quaternion = new THREE.Quaternion();
  4801. return function ( optionalTarget ) {
  4802. var result = optionalTarget || new THREE.Vector3();
  4803. this.getWorldQuaternion( quaternion );
  4804. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4805. }
  4806. }(),
  4807. raycast: function () {},
  4808. traverse: function ( callback ) {
  4809. callback( this );
  4810. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4811. this.children[ i ].traverse( callback );
  4812. }
  4813. },
  4814. traverseVisible: function ( callback ) {
  4815. if ( this.visible === false ) return;
  4816. callback( this );
  4817. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4818. this.children[ i ].traverseVisible( callback );
  4819. }
  4820. },
  4821. traverseAncestors: function ( callback ) {
  4822. if ( this.parent ) {
  4823. callback( this.parent );
  4824. this.parent.traverseAncestors( callback );
  4825. }
  4826. },
  4827. updateMatrix: function () {
  4828. this.matrix.compose( this.position, this.quaternion, this.scale );
  4829. this.matrixWorldNeedsUpdate = true;
  4830. },
  4831. updateMatrixWorld: function ( force ) {
  4832. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4833. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4834. if ( this.parent === undefined ) {
  4835. this.matrixWorld.copy( this.matrix );
  4836. } else {
  4837. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4838. }
  4839. this.matrixWorldNeedsUpdate = false;
  4840. force = true;
  4841. }
  4842. // update children
  4843. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4844. this.children[ i ].updateMatrixWorld( force );
  4845. }
  4846. },
  4847. toJSON: function ( meta ) {
  4848. var isRootObject = ( meta === undefined );
  4849. var data = {};
  4850. // meta is a hash used to collect geometries, materials.
  4851. // not providing it implies that this is the root object
  4852. // being serialized.
  4853. if ( isRootObject ) {
  4854. // initialize meta obj
  4855. meta = {
  4856. geometries: {},
  4857. materials: {},
  4858. textures: {},
  4859. images: {}
  4860. };
  4861. data.metadata = {
  4862. version: 4.4,
  4863. type: 'Object',
  4864. generator: 'Object3D.toJSON'
  4865. };
  4866. }
  4867. // standard Object3D serialization
  4868. data.uuid = this.uuid;
  4869. data.type = this.type;
  4870. if ( this.name !== '' ) data.name = this.name;
  4871. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4872. if ( this.visible !== true ) data.visible = this.visible;
  4873. data.matrix = this.matrix.toArray();
  4874. if ( this.children.length > 0 ) {
  4875. data.children = [];
  4876. for ( var i = 0; i < this.children.length; i ++ ) {
  4877. data.children.push( this.children[ i ].toJSON( meta ).object );
  4878. }
  4879. }
  4880. var output = {};
  4881. if ( isRootObject ) {
  4882. var geometries = extractFromCache( meta.geometries );
  4883. var materials = extractFromCache( meta.materials );
  4884. var textures = extractFromCache( meta.textures );
  4885. var images = extractFromCache( meta.images );
  4886. if ( geometries.length > 0 ) output.geometries = geometries;
  4887. if ( materials.length > 0 ) output.materials = materials;
  4888. if ( textures.length > 0 ) output.textures = textures;
  4889. if ( images.length > 0 ) output.images = images;
  4890. }
  4891. output.object = data;
  4892. return output;
  4893. // extract data from the cache hash
  4894. // remove metadata on each item
  4895. // and return as array
  4896. function extractFromCache ( cache ) {
  4897. var values = [];
  4898. for ( var key in cache ) {
  4899. var data = cache[ key ];
  4900. delete data.metadata;
  4901. values.push( data );
  4902. }
  4903. return values;
  4904. }
  4905. },
  4906. clone: function ( recursive ) {
  4907. return new THREE.Object3D().copy( this, recursive );
  4908. },
  4909. copy: function ( source, recursive ) {
  4910. if ( recursive === undefined ) recursive = true;
  4911. this.name = source.name;
  4912. this.up.copy( source.up );
  4913. this.position.copy( source.position );
  4914. this.quaternion.copy( source.quaternion );
  4915. this.scale.copy( source.scale );
  4916. this.rotationAutoUpdate = source.rotationAutoUpdate;
  4917. this.matrix.copy( source.matrix );
  4918. this.matrixWorld.copy( source.matrixWorld );
  4919. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4920. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4921. this.visible = source.visible;
  4922. this.castShadow = source.castShadow;
  4923. this.receiveShadow = source.receiveShadow;
  4924. this.frustumCulled = source.frustumCulled;
  4925. this.renderOrder = source.renderOrder;
  4926. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4927. if ( recursive === true ) {
  4928. for ( var i = 0; i < source.children.length; i ++ ) {
  4929. var child = source.children[ i ];
  4930. this.add( child.clone() );
  4931. }
  4932. }
  4933. return this;
  4934. }
  4935. };
  4936. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4937. THREE.Object3DIdCount = 0;
  4938. // File:src/core/Face3.js
  4939. /**
  4940. * @author mrdoob / http://mrdoob.com/
  4941. * @author alteredq / http://alteredqualia.com/
  4942. */
  4943. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  4944. this.a = a;
  4945. this.b = b;
  4946. this.c = c;
  4947. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  4948. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4949. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  4950. this.vertexColors = Array.isArray( color ) ? color : [];
  4951. this.vertexTangents = [];
  4952. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4953. };
  4954. THREE.Face3.prototype = {
  4955. constructor: THREE.Face3,
  4956. copy: function ( source ) {
  4957. this.a = source.a;
  4958. this.b = source.b;
  4959. this.c = source.c;
  4960. this.normal.copy( source.normal );
  4961. this.color.copy( source.color );
  4962. this.materialIndex = source.materialIndex;
  4963. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4964. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4965. }
  4966. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4967. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4968. }
  4969. for ( var i = 0, il = source.vertexTangents.length; i < il; i ++ ) {
  4970. this.vertexTangents[ i ] = source.vertexTangents[ i ].clone();
  4971. }
  4972. return this;
  4973. },
  4974. clone: function () {
  4975. return new THREE.Face3().copy( this );
  4976. }
  4977. };
  4978. // File:src/core/Face4.js
  4979. /**
  4980. * @author mrdoob / http://mrdoob.com/
  4981. */
  4982. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  4983. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  4984. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  4985. };
  4986. // File:src/core/BufferAttribute.js
  4987. /**
  4988. * @author mrdoob / http://mrdoob.com/
  4989. */
  4990. THREE.BufferAttribute = function ( array, itemSize ) {
  4991. this.uuid = THREE.Math.generateUUID();
  4992. this.array = array;
  4993. this.itemSize = itemSize;
  4994. this.version = 0;
  4995. };
  4996. THREE.BufferAttribute.prototype = {
  4997. constructor: THREE.BufferAttribute,
  4998. get length () {
  4999. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5000. return this.array.length;
  5001. },
  5002. get count() {
  5003. return this.array.length / this.itemSize;
  5004. },
  5005. set needsUpdate( value ) {
  5006. if ( value === true ) this.version ++;
  5007. },
  5008. copyAt: function ( index1, attribute, index2 ) {
  5009. index1 *= this.itemSize;
  5010. index2 *= attribute.itemSize;
  5011. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5012. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5013. }
  5014. return this;
  5015. },
  5016. copyArray: function ( array ) {
  5017. this.array.set( array );
  5018. return this;
  5019. },
  5020. copyColorsArray: function ( colors ) {
  5021. var array = this.array, offset = 0;
  5022. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5023. var color = colors[ i ];
  5024. if ( color === undefined ) {
  5025. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5026. color = new THREE.Color();
  5027. }
  5028. array[ offset ++ ] = color.r;
  5029. array[ offset ++ ] = color.g;
  5030. array[ offset ++ ] = color.b;
  5031. }
  5032. return this;
  5033. },
  5034. copyIndicesArray: function ( indices ) {
  5035. var array = this.array, offset = 0;
  5036. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5037. var index = indices[ i ];
  5038. array[ offset ++ ] = index.a;
  5039. array[ offset ++ ] = index.b;
  5040. array[ offset ++ ] = index.c;
  5041. }
  5042. return this;
  5043. },
  5044. copyVector2sArray: function ( vectors ) {
  5045. var array = this.array, offset = 0;
  5046. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5047. var vector = vectors[ i ];
  5048. if ( vector === undefined ) {
  5049. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5050. vector = new THREE.Vector2();
  5051. }
  5052. array[ offset ++ ] = vector.x;
  5053. array[ offset ++ ] = vector.y;
  5054. }
  5055. return this;
  5056. },
  5057. copyVector3sArray: function ( vectors ) {
  5058. var array = this.array, offset = 0;
  5059. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5060. var vector = vectors[ i ];
  5061. if ( vector === undefined ) {
  5062. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5063. vector = new THREE.Vector3();
  5064. }
  5065. array[ offset ++ ] = vector.x;
  5066. array[ offset ++ ] = vector.y;
  5067. array[ offset ++ ] = vector.z;
  5068. }
  5069. return this;
  5070. },
  5071. copyVector4sArray: function ( vectors ) {
  5072. var array = this.array, offset = 0;
  5073. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5074. var vector = vectors[ i ];
  5075. if ( vector === undefined ) {
  5076. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5077. vector = new THREE.Vector4();
  5078. }
  5079. array[ offset ++ ] = vector.x;
  5080. array[ offset ++ ] = vector.y;
  5081. array[ offset ++ ] = vector.z;
  5082. array[ offset ++ ] = vector.w;
  5083. }
  5084. return this;
  5085. },
  5086. set: function ( value, offset ) {
  5087. if ( offset === undefined ) offset = 0;
  5088. this.array.set( value, offset );
  5089. return this;
  5090. },
  5091. getX: function ( index ) {
  5092. return this.array[ index * this.itemSize ];
  5093. },
  5094. setX: function ( index, x ) {
  5095. this.array[ index * this.itemSize ] = x;
  5096. return this;
  5097. },
  5098. getY: function ( index ) {
  5099. return this.array[ index * this.itemSize + 1 ];
  5100. },
  5101. setY: function ( index, y ) {
  5102. this.array[ index * this.itemSize + 1 ] = y;
  5103. return this;
  5104. },
  5105. getZ: function ( index ) {
  5106. return this.array[ index * this.itemSize + 2 ];
  5107. },
  5108. setZ: function ( index, z ) {
  5109. this.array[ index * this.itemSize + 2 ] = z;
  5110. return this;
  5111. },
  5112. getW: function ( index ) {
  5113. return this.array[ index * this.itemSize + 3 ];
  5114. },
  5115. setW: function ( index, w ) {
  5116. this.array[ index * this.itemSize + 3 ] = w;
  5117. return this;
  5118. },
  5119. setXY: function ( index, x, y ) {
  5120. index *= this.itemSize;
  5121. this.array[ index + 0 ] = x;
  5122. this.array[ index + 1 ] = y;
  5123. return this;
  5124. },
  5125. setXYZ: function ( index, x, y, z ) {
  5126. index *= this.itemSize;
  5127. this.array[ index + 0 ] = x;
  5128. this.array[ index + 1 ] = y;
  5129. this.array[ index + 2 ] = z;
  5130. return this;
  5131. },
  5132. setXYZW: function ( index, x, y, z, w ) {
  5133. index *= this.itemSize;
  5134. this.array[ index + 0 ] = x;
  5135. this.array[ index + 1 ] = y;
  5136. this.array[ index + 2 ] = z;
  5137. this.array[ index + 3 ] = w;
  5138. return this;
  5139. },
  5140. clone: function () {
  5141. return new THREE.BufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5142. }
  5143. };
  5144. //
  5145. THREE.Int8Attribute = function ( array, itemSize ) {
  5146. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5147. };
  5148. THREE.Uint8Attribute = function ( array, itemSize ) {
  5149. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5150. };
  5151. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5152. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5153. };
  5154. THREE.Int16Attribute = function ( array, itemSize ) {
  5155. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5156. };
  5157. THREE.Uint16Attribute = function ( array, itemSize ) {
  5158. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5159. };
  5160. THREE.Int32Attribute = function ( array, itemSize ) {
  5161. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5162. };
  5163. THREE.Uint32Attribute = function ( array, itemSize ) {
  5164. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5165. };
  5166. THREE.Float32Attribute = function ( array, itemSize ) {
  5167. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5168. };
  5169. THREE.Float64Attribute = function ( array, itemSize ) {
  5170. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5171. };
  5172. // File:src/core/DynamicBufferAttribute.js
  5173. /**
  5174. * @author benaadams / https://twitter.com/ben_a_adams
  5175. * @author mrdoob / http://mrdoob.com/
  5176. */
  5177. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5178. THREE.BufferAttribute.call( this, array, itemSize );
  5179. this.updateRange = { offset: 0, count: - 1 };
  5180. };
  5181. THREE.DynamicBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5182. THREE.DynamicBufferAttribute.prototype.constructor = THREE.DynamicBufferAttribute;
  5183. THREE.DynamicBufferAttribute.prototype.clone = function () {
  5184. return new THREE.DynamicBufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5185. };
  5186. // File:src/core/InstancedBufferAttribute.js
  5187. /**
  5188. * @author benaadams / https://twitter.com/ben_a_adams
  5189. */
  5190. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute, dynamic ) {
  5191. THREE.DynamicBufferAttribute.call( this, array, itemSize );
  5192. this.dynamic = dynamic || false;
  5193. this.meshPerAttribute = meshPerAttribute || 1;
  5194. };
  5195. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.DynamicBufferAttribute.prototype );
  5196. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5197. THREE.InstancedBufferAttribute.prototype.clone = function () {
  5198. return new THREE.InstancedBufferAttribute( new this.array.constructor( this.array ), this.itemSize, this.meshPerAttribute, this.dynamic );
  5199. };
  5200. // File:src/core/InterleavedBuffer.js
  5201. /**
  5202. * @author benaadams / https://twitter.com/ben_a_adams
  5203. */
  5204. THREE.InterleavedBuffer = function ( array, stride, dynamic ) {
  5205. this.uuid = THREE.Math.generateUUID();
  5206. this.array = array;
  5207. this.stride = stride;
  5208. this.version = 0;
  5209. this.dynamic = dynamic || false;
  5210. this.updateRange = { offset: 0, count: - 1 };
  5211. };
  5212. THREE.InterleavedBuffer.prototype = {
  5213. constructor: THREE.InterleavedBuffer,
  5214. get length () {
  5215. return this.array.length;
  5216. },
  5217. get count () {
  5218. return this.array.length / this.stride;
  5219. },
  5220. set needsUpdate( value ) {
  5221. if ( value === true ) this.version ++;
  5222. },
  5223. copyAt: function ( index1, attribute, index2 ) {
  5224. index1 *= this.stride;
  5225. index2 *= attribute.stride;
  5226. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5227. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5228. }
  5229. return this;
  5230. },
  5231. set: function ( value, offset ) {
  5232. if ( offset === undefined ) offset = 0;
  5233. this.array.set( value, offset );
  5234. return this;
  5235. },
  5236. clone: function () {
  5237. return new THREE.InterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic );
  5238. }
  5239. };
  5240. // File:src/core/InstancedInterleavedBuffer.js
  5241. /**
  5242. * @author benaadams / https://twitter.com/ben_a_adams
  5243. */
  5244. THREE.InstancedInterleavedBuffer = function ( array, stride, dynamic, meshPerAttribute ) {
  5245. THREE.InterleavedBuffer.call( this, array, stride, dynamic );
  5246. this.meshPerAttribute = meshPerAttribute || 1;
  5247. };
  5248. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5249. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5250. THREE.InstancedInterleavedBuffer.prototype.clone = function () {
  5251. return new THREE.InstancedInterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic, this.meshPerAttribute );
  5252. };
  5253. // File:src/core/InterleavedBufferAttribute.js
  5254. /**
  5255. * @author benaadams / https://twitter.com/ben_a_adams
  5256. */
  5257. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5258. this.uuid = THREE.Math.generateUUID();
  5259. this.data = interleavedBuffer;
  5260. this.itemSize = itemSize;
  5261. this.offset = offset;
  5262. };
  5263. THREE.InterleavedBufferAttribute.prototype = {
  5264. constructor: THREE.InterleavedBufferAttribute,
  5265. get length() {
  5266. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5267. return this.array.length;
  5268. },
  5269. get count() {
  5270. return this.data.array.length / this.data.stride;
  5271. },
  5272. setX: function ( index, x ) {
  5273. this.data.array[ index * this.data.stride + this.offset ] = x;
  5274. return this;
  5275. },
  5276. setY: function ( index, y ) {
  5277. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5278. return this;
  5279. },
  5280. setZ: function ( index, z ) {
  5281. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5282. return this;
  5283. },
  5284. setW: function ( index, w ) {
  5285. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5286. return this;
  5287. },
  5288. getX: function ( index ) {
  5289. return this.data.array[ index * this.data.stride + this.offset ];
  5290. },
  5291. getY: function ( index ) {
  5292. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5293. },
  5294. getZ: function ( index ) {
  5295. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5296. },
  5297. getW: function ( index ) {
  5298. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5299. },
  5300. setXY: function ( index, x, y ) {
  5301. index = index * this.data.stride + this.offset;
  5302. this.data.array[ index + 0 ] = x;
  5303. this.data.array[ index + 1 ] = y;
  5304. return this;
  5305. },
  5306. setXYZ: function ( index, x, y, z ) {
  5307. index = index * this.data.stride + this.offset;
  5308. this.data.array[ index + 0 ] = x;
  5309. this.data.array[ index + 1 ] = y;
  5310. this.data.array[ index + 2 ] = z;
  5311. return this;
  5312. },
  5313. setXYZW: function ( index, x, y, z, w ) {
  5314. index = index * this.data.stride + this.offset;
  5315. this.data.array[ index + 0 ] = x;
  5316. this.data.array[ index + 1 ] = y;
  5317. this.data.array[ index + 2 ] = z;
  5318. this.data.array[ index + 3 ] = w;
  5319. return this;
  5320. }
  5321. };
  5322. // File:src/core/Geometry.js
  5323. /**
  5324. * @author mrdoob / http://mrdoob.com/
  5325. * @author kile / http://kile.stravaganza.org/
  5326. * @author alteredq / http://alteredqualia.com/
  5327. * @author mikael emtinger / http://gomo.se/
  5328. * @author zz85 / http://www.lab4games.net/zz85/blog
  5329. * @author bhouston / http://exocortex.com
  5330. */
  5331. THREE.Geometry = function () {
  5332. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5333. this.uuid = THREE.Math.generateUUID();
  5334. this.name = '';
  5335. this.type = 'Geometry';
  5336. this.vertices = [];
  5337. this.colors = [];
  5338. this.faces = [];
  5339. this.faceVertexUvs = [ [] ];
  5340. this.morphTargets = [];
  5341. this.morphColors = [];
  5342. this.morphNormals = [];
  5343. this.skinWeights = [];
  5344. this.skinIndices = [];
  5345. this.lineDistances = [];
  5346. this.boundingBox = null;
  5347. this.boundingSphere = null;
  5348. this.hasTangents = false;
  5349. // update flags
  5350. this.verticesNeedUpdate = false;
  5351. this.elementsNeedUpdate = false;
  5352. this.uvsNeedUpdate = false;
  5353. this.normalsNeedUpdate = false;
  5354. this.tangentsNeedUpdate = false;
  5355. this.colorsNeedUpdate = false;
  5356. this.lineDistancesNeedUpdate = false;
  5357. };
  5358. THREE.Geometry.prototype = {
  5359. constructor: THREE.Geometry,
  5360. applyMatrix: function ( matrix ) {
  5361. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5362. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5363. var vertex = this.vertices[ i ];
  5364. vertex.applyMatrix4( matrix );
  5365. }
  5366. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5367. var face = this.faces[ i ];
  5368. face.normal.applyMatrix3( normalMatrix ).normalize();
  5369. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5370. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5371. }
  5372. }
  5373. if ( this.boundingBox !== null ) {
  5374. this.computeBoundingBox();
  5375. }
  5376. if ( this.boundingSphere !== null ) {
  5377. this.computeBoundingSphere();
  5378. }
  5379. this.verticesNeedUpdate = true;
  5380. this.normalsNeedUpdate = true;
  5381. },
  5382. fromBufferGeometry: function ( geometry ) {
  5383. var scope = this;
  5384. var attributes = geometry.attributes;
  5385. var vertices = attributes.position.array;
  5386. var indices = attributes.index !== undefined ? attributes.index.array : undefined;
  5387. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5388. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5389. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5390. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5391. var tangents = attributes.tangent !== undefined ? attributes.tangent.array : undefined;
  5392. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5393. if ( tangents !== undefined ) this.hasTangents = true;
  5394. var tempNormals = [];
  5395. var tempUVs = [];
  5396. var tempUVs2 = [];
  5397. var tempTangents = [];
  5398. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5399. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5400. if ( normals !== undefined ) {
  5401. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5402. }
  5403. if ( colors !== undefined ) {
  5404. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5405. }
  5406. if ( uvs !== undefined ) {
  5407. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5408. }
  5409. if ( uvs2 !== undefined ) {
  5410. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5411. }
  5412. if ( tangents !== undefined ) {
  5413. tempTangents.push( new THREE.Vector4( tangents[ k ], tangents[ k + 1 ], tangents[ k + 2 ], tangents[ k + 3 ] ) );
  5414. }
  5415. }
  5416. var addFace = function ( a, b, c ) {
  5417. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5418. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5419. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5420. scope.faces.push( face );
  5421. if ( uvs !== undefined ) {
  5422. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5423. }
  5424. if ( uvs2 !== undefined ) {
  5425. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5426. }
  5427. if ( tangents !== undefined ) {
  5428. face.vertexTangents.push( tempTangents[ a ].clone(), tempTangents[ b ].clone(), tempTangents[ c ].clone() );
  5429. }
  5430. };
  5431. if ( indices !== undefined ) {
  5432. var drawcalls = geometry.drawcalls;
  5433. if ( drawcalls.length > 0 ) {
  5434. for ( var i = 0; i < drawcalls.length; i ++ ) {
  5435. var drawcall = drawcalls[ i ];
  5436. var start = drawcall.start;
  5437. var count = drawcall.count;
  5438. var index = drawcall.index;
  5439. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5440. addFace( index + indices[ j ], index + indices[ j + 1 ], index + indices[ j + 2 ] );
  5441. }
  5442. }
  5443. } else {
  5444. for ( var i = 0; i < indices.length; i += 3 ) {
  5445. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5446. }
  5447. }
  5448. } else {
  5449. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5450. addFace( i, i + 1, i + 2 );
  5451. }
  5452. }
  5453. this.computeFaceNormals();
  5454. if ( geometry.boundingBox !== null ) {
  5455. this.boundingBox = geometry.boundingBox.clone();
  5456. }
  5457. if ( geometry.boundingSphere !== null ) {
  5458. this.boundingSphere = geometry.boundingSphere.clone();
  5459. }
  5460. return this;
  5461. },
  5462. center: function () {
  5463. this.computeBoundingBox();
  5464. var offset = this.boundingBox.center().negate();
  5465. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  5466. return offset;
  5467. },
  5468. normalize: function () {
  5469. this.computeBoundingSphere();
  5470. var center = this.boundingSphere.center;
  5471. var radius = this.boundingSphere.radius;
  5472. var s = radius === 0 ? 1 : 1.0 / radius;
  5473. var matrix = new THREE.Matrix4();
  5474. matrix.set(
  5475. s, 0, 0, - s * center.x,
  5476. 0, s, 0, - s * center.y,
  5477. 0, 0, s, - s * center.z,
  5478. 0, 0, 0, 1
  5479. );
  5480. this.applyMatrix( matrix );
  5481. return this;
  5482. },
  5483. computeFaceNormals: function () {
  5484. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5485. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5486. var face = this.faces[ f ];
  5487. var vA = this.vertices[ face.a ];
  5488. var vB = this.vertices[ face.b ];
  5489. var vC = this.vertices[ face.c ];
  5490. cb.subVectors( vC, vB );
  5491. ab.subVectors( vA, vB );
  5492. cb.cross( ab );
  5493. cb.normalize();
  5494. face.normal.copy( cb );
  5495. }
  5496. },
  5497. computeVertexNormals: function ( areaWeighted ) {
  5498. var v, vl, f, fl, face, vertices;
  5499. vertices = new Array( this.vertices.length );
  5500. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5501. vertices[ v ] = new THREE.Vector3();
  5502. }
  5503. if ( areaWeighted ) {
  5504. // vertex normals weighted by triangle areas
  5505. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5506. var vA, vB, vC;
  5507. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5508. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5509. face = this.faces[ f ];
  5510. vA = this.vertices[ face.a ];
  5511. vB = this.vertices[ face.b ];
  5512. vC = this.vertices[ face.c ];
  5513. cb.subVectors( vC, vB );
  5514. ab.subVectors( vA, vB );
  5515. cb.cross( ab );
  5516. vertices[ face.a ].add( cb );
  5517. vertices[ face.b ].add( cb );
  5518. vertices[ face.c ].add( cb );
  5519. }
  5520. } else {
  5521. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5522. face = this.faces[ f ];
  5523. vertices[ face.a ].add( face.normal );
  5524. vertices[ face.b ].add( face.normal );
  5525. vertices[ face.c ].add( face.normal );
  5526. }
  5527. }
  5528. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5529. vertices[ v ].normalize();
  5530. }
  5531. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5532. face = this.faces[ f ];
  5533. var vertexNormals = face.vertexNormals;
  5534. if ( vertexNormals.length === 3 ) {
  5535. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5536. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5537. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5538. } else {
  5539. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5540. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5541. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5542. }
  5543. }
  5544. },
  5545. computeMorphNormals: function () {
  5546. var i, il, f, fl, face;
  5547. // save original normals
  5548. // - create temp variables on first access
  5549. // otherwise just copy (for faster repeated calls)
  5550. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5551. face = this.faces[ f ];
  5552. if ( ! face.__originalFaceNormal ) {
  5553. face.__originalFaceNormal = face.normal.clone();
  5554. } else {
  5555. face.__originalFaceNormal.copy( face.normal );
  5556. }
  5557. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5558. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5559. if ( ! face.__originalVertexNormals[ i ] ) {
  5560. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5561. } else {
  5562. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5563. }
  5564. }
  5565. }
  5566. // use temp geometry to compute face and vertex normals for each morph
  5567. var tmpGeo = new THREE.Geometry();
  5568. tmpGeo.faces = this.faces;
  5569. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5570. // create on first access
  5571. if ( ! this.morphNormals[ i ] ) {
  5572. this.morphNormals[ i ] = {};
  5573. this.morphNormals[ i ].faceNormals = [];
  5574. this.morphNormals[ i ].vertexNormals = [];
  5575. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5576. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5577. var faceNormal, vertexNormals;
  5578. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5579. faceNormal = new THREE.Vector3();
  5580. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5581. dstNormalsFace.push( faceNormal );
  5582. dstNormalsVertex.push( vertexNormals );
  5583. }
  5584. }
  5585. var morphNormals = this.morphNormals[ i ];
  5586. // set vertices to morph target
  5587. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5588. // compute morph normals
  5589. tmpGeo.computeFaceNormals();
  5590. tmpGeo.computeVertexNormals();
  5591. // store morph normals
  5592. var faceNormal, vertexNormals;
  5593. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5594. face = this.faces[ f ];
  5595. faceNormal = morphNormals.faceNormals[ f ];
  5596. vertexNormals = morphNormals.vertexNormals[ f ];
  5597. faceNormal.copy( face.normal );
  5598. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5599. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5600. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5601. }
  5602. }
  5603. // restore original normals
  5604. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5605. face = this.faces[ f ];
  5606. face.normal = face.__originalFaceNormal;
  5607. face.vertexNormals = face.__originalVertexNormals;
  5608. }
  5609. },
  5610. computeTangents: function () {
  5611. // based on http://www.terathon.com/code/tangent.html
  5612. // tangents go to vertices
  5613. var f, fl, v, vl, i, vertexIndex,
  5614. face, uv, vA, vB, vC, uvA, uvB, uvC,
  5615. x1, x2, y1, y2, z1, z2,
  5616. s1, s2, t1, t2, r, t, test,
  5617. tan1 = [], tan2 = [],
  5618. sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
  5619. tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
  5620. n = new THREE.Vector3(), w;
  5621. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5622. tan1[ v ] = new THREE.Vector3();
  5623. tan2[ v ] = new THREE.Vector3();
  5624. }
  5625. function handleTriangle( context, a, b, c, ua, ub, uc ) {
  5626. vA = context.vertices[ a ];
  5627. vB = context.vertices[ b ];
  5628. vC = context.vertices[ c ];
  5629. uvA = uv[ ua ];
  5630. uvB = uv[ ub ];
  5631. uvC = uv[ uc ];
  5632. x1 = vB.x - vA.x;
  5633. x2 = vC.x - vA.x;
  5634. y1 = vB.y - vA.y;
  5635. y2 = vC.y - vA.y;
  5636. z1 = vB.z - vA.z;
  5637. z2 = vC.z - vA.z;
  5638. s1 = uvB.x - uvA.x;
  5639. s2 = uvC.x - uvA.x;
  5640. t1 = uvB.y - uvA.y;
  5641. t2 = uvC.y - uvA.y;
  5642. r = 1.0 / ( s1 * t2 - s2 * t1 );
  5643. sdir.set( ( t2 * x1 - t1 * x2 ) * r,
  5644. ( t2 * y1 - t1 * y2 ) * r,
  5645. ( t2 * z1 - t1 * z2 ) * r );
  5646. tdir.set( ( s1 * x2 - s2 * x1 ) * r,
  5647. ( s1 * y2 - s2 * y1 ) * r,
  5648. ( s1 * z2 - s2 * z1 ) * r );
  5649. tan1[ a ].add( sdir );
  5650. tan1[ b ].add( sdir );
  5651. tan1[ c ].add( sdir );
  5652. tan2[ a ].add( tdir );
  5653. tan2[ b ].add( tdir );
  5654. tan2[ c ].add( tdir );
  5655. }
  5656. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5657. face = this.faces[ f ];
  5658. uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
  5659. handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
  5660. }
  5661. var faceIndex = [ 'a', 'b', 'c', 'd' ];
  5662. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5663. face = this.faces[ f ];
  5664. for ( i = 0; i < Math.min( face.vertexNormals.length, 3 ); i ++ ) {
  5665. n.copy( face.vertexNormals[ i ] );
  5666. vertexIndex = face[ faceIndex[ i ] ];
  5667. t = tan1[ vertexIndex ];
  5668. // Gram-Schmidt orthogonalize
  5669. tmp.copy( t );
  5670. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  5671. // Calculate handedness
  5672. tmp2.crossVectors( face.vertexNormals[ i ], t );
  5673. test = tmp2.dot( tan2[ vertexIndex ] );
  5674. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  5675. face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
  5676. }
  5677. }
  5678. this.hasTangents = true;
  5679. },
  5680. computeLineDistances: function () {
  5681. var d = 0;
  5682. var vertices = this.vertices;
  5683. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5684. if ( i > 0 ) {
  5685. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5686. }
  5687. this.lineDistances[ i ] = d;
  5688. }
  5689. },
  5690. computeBoundingBox: function () {
  5691. if ( this.boundingBox === null ) {
  5692. this.boundingBox = new THREE.Box3();
  5693. }
  5694. this.boundingBox.setFromPoints( this.vertices );
  5695. },
  5696. computeBoundingSphere: function () {
  5697. if ( this.boundingSphere === null ) {
  5698. this.boundingSphere = new THREE.Sphere();
  5699. }
  5700. this.boundingSphere.setFromPoints( this.vertices );
  5701. },
  5702. merge: function ( geometry, matrix, materialIndexOffset ) {
  5703. if ( geometry instanceof THREE.Geometry === false ) {
  5704. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5705. return;
  5706. }
  5707. var normalMatrix,
  5708. vertexOffset = this.vertices.length,
  5709. vertices1 = this.vertices,
  5710. vertices2 = geometry.vertices,
  5711. faces1 = this.faces,
  5712. faces2 = geometry.faces,
  5713. uvs1 = this.faceVertexUvs[ 0 ],
  5714. uvs2 = geometry.faceVertexUvs[ 0 ];
  5715. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5716. if ( matrix !== undefined ) {
  5717. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5718. }
  5719. // vertices
  5720. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5721. var vertex = vertices2[ i ];
  5722. var vertexCopy = vertex.clone();
  5723. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5724. vertices1.push( vertexCopy );
  5725. }
  5726. // faces
  5727. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5728. var face = faces2[ i ], faceCopy, normal, color,
  5729. faceVertexNormals = face.vertexNormals,
  5730. faceVertexColors = face.vertexColors;
  5731. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5732. faceCopy.normal.copy( face.normal );
  5733. if ( normalMatrix !== undefined ) {
  5734. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5735. }
  5736. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5737. normal = faceVertexNormals[ j ].clone();
  5738. if ( normalMatrix !== undefined ) {
  5739. normal.applyMatrix3( normalMatrix ).normalize();
  5740. }
  5741. faceCopy.vertexNormals.push( normal );
  5742. }
  5743. faceCopy.color.copy( face.color );
  5744. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5745. color = faceVertexColors[ j ];
  5746. faceCopy.vertexColors.push( color.clone() );
  5747. }
  5748. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5749. faces1.push( faceCopy );
  5750. }
  5751. // uvs
  5752. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5753. var uv = uvs2[ i ], uvCopy = [];
  5754. if ( uv === undefined ) {
  5755. continue;
  5756. }
  5757. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5758. uvCopy.push( uv[ j ].clone() );
  5759. }
  5760. uvs1.push( uvCopy );
  5761. }
  5762. },
  5763. mergeMesh: function ( mesh ) {
  5764. if ( mesh instanceof THREE.Mesh === false ) {
  5765. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5766. return;
  5767. }
  5768. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5769. this.merge( mesh.geometry, mesh.matrix );
  5770. },
  5771. /*
  5772. * Checks for duplicate vertices with hashmap.
  5773. * Duplicated vertices are removed
  5774. * and faces' vertices are updated.
  5775. */
  5776. mergeVertices: function () {
  5777. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5778. var unique = [], changes = [];
  5779. var v, key;
  5780. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5781. var precision = Math.pow( 10, precisionPoints );
  5782. var i, il, face;
  5783. var indices, j, jl;
  5784. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5785. v = this.vertices[ i ];
  5786. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5787. if ( verticesMap[ key ] === undefined ) {
  5788. verticesMap[ key ] = i;
  5789. unique.push( this.vertices[ i ] );
  5790. changes[ i ] = unique.length - 1;
  5791. } else {
  5792. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5793. changes[ i ] = changes[ verticesMap[ key ] ];
  5794. }
  5795. }
  5796. // if faces are completely degenerate after merging vertices, we
  5797. // have to remove them from the geometry.
  5798. var faceIndicesToRemove = [];
  5799. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5800. face = this.faces[ i ];
  5801. face.a = changes[ face.a ];
  5802. face.b = changes[ face.b ];
  5803. face.c = changes[ face.c ];
  5804. indices = [ face.a, face.b, face.c ];
  5805. var dupIndex = - 1;
  5806. // if any duplicate vertices are found in a Face3
  5807. // we have to remove the face as nothing can be saved
  5808. for ( var n = 0; n < 3; n ++ ) {
  5809. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5810. dupIndex = n;
  5811. faceIndicesToRemove.push( i );
  5812. break;
  5813. }
  5814. }
  5815. }
  5816. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5817. var idx = faceIndicesToRemove[ i ];
  5818. this.faces.splice( idx, 1 );
  5819. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5820. this.faceVertexUvs[ j ].splice( idx, 1 );
  5821. }
  5822. }
  5823. // Use unique set of vertices
  5824. var diff = this.vertices.length - unique.length;
  5825. this.vertices = unique;
  5826. return diff;
  5827. },
  5828. toJSON: function () {
  5829. var data = {
  5830. metadata: {
  5831. version: 4.4,
  5832. type: 'Geometry',
  5833. generator: 'Geometry.toJSON'
  5834. }
  5835. };
  5836. // standard Geometry serialization
  5837. data.uuid = this.uuid;
  5838. data.type = this.type;
  5839. if ( this.name !== '' ) data.name = this.name;
  5840. if ( this.parameters !== undefined ) {
  5841. var parameters = this.parameters;
  5842. for ( var key in parameters ) {
  5843. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5844. }
  5845. return data;
  5846. }
  5847. var vertices = [];
  5848. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5849. var vertex = this.vertices[ i ];
  5850. vertices.push( vertex.x, vertex.y, vertex.z );
  5851. }
  5852. var faces = [];
  5853. var normals = [];
  5854. var normalsHash = {};
  5855. var colors = [];
  5856. var colorsHash = {};
  5857. var uvs = [];
  5858. var uvsHash = {};
  5859. for ( var i = 0; i < this.faces.length; i ++ ) {
  5860. var face = this.faces[ i ];
  5861. var hasMaterial = false; // face.materialIndex !== undefined;
  5862. var hasFaceUv = false; // deprecated
  5863. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5864. var hasFaceNormal = face.normal.length() > 0;
  5865. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5866. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5867. var hasFaceVertexColor = face.vertexColors.length > 0;
  5868. var faceType = 0;
  5869. faceType = setBit( faceType, 0, 0 );
  5870. faceType = setBit( faceType, 1, hasMaterial );
  5871. faceType = setBit( faceType, 2, hasFaceUv );
  5872. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5873. faceType = setBit( faceType, 4, hasFaceNormal );
  5874. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5875. faceType = setBit( faceType, 6, hasFaceColor );
  5876. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5877. faces.push( faceType );
  5878. faces.push( face.a, face.b, face.c );
  5879. if ( hasFaceVertexUv ) {
  5880. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5881. faces.push(
  5882. getUvIndex( faceVertexUvs[ 0 ] ),
  5883. getUvIndex( faceVertexUvs[ 1 ] ),
  5884. getUvIndex( faceVertexUvs[ 2 ] )
  5885. );
  5886. }
  5887. if ( hasFaceNormal ) {
  5888. faces.push( getNormalIndex( face.normal ) );
  5889. }
  5890. if ( hasFaceVertexNormal ) {
  5891. var vertexNormals = face.vertexNormals;
  5892. faces.push(
  5893. getNormalIndex( vertexNormals[ 0 ] ),
  5894. getNormalIndex( vertexNormals[ 1 ] ),
  5895. getNormalIndex( vertexNormals[ 2 ] )
  5896. );
  5897. }
  5898. if ( hasFaceColor ) {
  5899. faces.push( getColorIndex( face.color ) );
  5900. }
  5901. if ( hasFaceVertexColor ) {
  5902. var vertexColors = face.vertexColors;
  5903. faces.push(
  5904. getColorIndex( vertexColors[ 0 ] ),
  5905. getColorIndex( vertexColors[ 1 ] ),
  5906. getColorIndex( vertexColors[ 2 ] )
  5907. );
  5908. }
  5909. }
  5910. function setBit( value, position, enabled ) {
  5911. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  5912. }
  5913. function getNormalIndex( normal ) {
  5914. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5915. if ( normalsHash[ hash ] !== undefined ) {
  5916. return normalsHash[ hash ];
  5917. }
  5918. normalsHash[ hash ] = normals.length / 3;
  5919. normals.push( normal.x, normal.y, normal.z );
  5920. return normalsHash[ hash ];
  5921. }
  5922. function getColorIndex( color ) {
  5923. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5924. if ( colorsHash[ hash ] !== undefined ) {
  5925. return colorsHash[ hash ];
  5926. }
  5927. colorsHash[ hash ] = colors.length;
  5928. colors.push( color.getHex() );
  5929. return colorsHash[ hash ];
  5930. }
  5931. function getUvIndex( uv ) {
  5932. var hash = uv.x.toString() + uv.y.toString();
  5933. if ( uvsHash[ hash ] !== undefined ) {
  5934. return uvsHash[ hash ];
  5935. }
  5936. uvsHash[ hash ] = uvs.length / 2;
  5937. uvs.push( uv.x, uv.y );
  5938. return uvsHash[ hash ];
  5939. }
  5940. data.data = {};
  5941. data.data.vertices = vertices;
  5942. data.data.normals = normals;
  5943. if ( colors.length > 0 ) data.data.colors = colors;
  5944. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  5945. data.data.faces = faces;
  5946. return data;
  5947. },
  5948. clone: function () {
  5949. return new THREE.Geometry().copy( this );
  5950. },
  5951. copy: function ( source ) {
  5952. this.vertices = [];
  5953. this.faces = [];
  5954. this.faceVertexUvs = [ [] ];
  5955. var vertices = source.vertices;
  5956. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5957. this.vertices.push( vertices[ i ].clone() );
  5958. }
  5959. var faces = source.faces;
  5960. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  5961. this.faces.push( faces[ i ].clone() );
  5962. }
  5963. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  5964. var faceVertexUvs = source.faceVertexUvs[ i ];
  5965. if ( this.faceVertexUvs[ i ] === undefined ) {
  5966. this.faceVertexUvs[ i ] = [];
  5967. }
  5968. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  5969. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  5970. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  5971. var uv = uvs[ k ];
  5972. uvsCopy.push( uv.clone() );
  5973. }
  5974. this.faceVertexUvs[ i ].push( uvsCopy );
  5975. }
  5976. }
  5977. return this;
  5978. },
  5979. dispose: function () {
  5980. this.dispatchEvent( { type: 'dispose' } );
  5981. },
  5982. // Backwards compatibility
  5983. set groupsNeedUpdate ( value ) {
  5984. if ( value === true ) this.dispose();
  5985. }
  5986. };
  5987. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  5988. THREE.GeometryIdCount = 0;
  5989. // File:src/core/DirectGeometry.js
  5990. /**
  5991. * @author mrdoob / http://mrdoob.com/
  5992. */
  5993. THREE.DirectGeometry = function () {
  5994. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5995. this.uuid = THREE.Math.generateUUID();
  5996. this.name = '';
  5997. this.type = 'DirectGeometry';
  5998. this.indices = [];
  5999. this.vertices = [];
  6000. this.normals = [];
  6001. this.colors = [];
  6002. this.uvs = [];
  6003. this.uvs2 = [];
  6004. this.tangents = [];
  6005. this.morphTargets = {};
  6006. this.skinWeights = [];
  6007. this.skinIndices = [];
  6008. // this.lineDistances = [];
  6009. this.boundingBox = null;
  6010. this.boundingSphere = null;
  6011. // update flags
  6012. this.verticesNeedUpdate = false;
  6013. this.normalsNeedUpdate = false;
  6014. this.colorsNeedUpdate = false;
  6015. this.uvsNeedUpdate = false;
  6016. this.tangentsNeedUpdate = false;
  6017. };
  6018. THREE.DirectGeometry.prototype = {
  6019. constructor: THREE.DirectGeometry,
  6020. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6021. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6022. computeFaceNormals: function () {
  6023. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6024. return this;
  6025. },
  6026. computeVertexNormals: function () {
  6027. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6028. return this;
  6029. },
  6030. computeTangents: function () {
  6031. console.warn( 'THREE.DirectGeometry: computeTangents() is not a method of this type of geometry.' );
  6032. return this;
  6033. },
  6034. fromGeometry: function ( geometry ) {
  6035. var faces = geometry.faces;
  6036. var vertices = geometry.vertices;
  6037. var faceVertexUvs = geometry.faceVertexUvs;
  6038. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6039. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6040. var hasTangents = geometry.hasTangents;
  6041. // morphs
  6042. var morphTargets = geometry.morphTargets;
  6043. var morphTargetsLength = morphTargets.length;
  6044. if ( morphTargetsLength > 0 ) {
  6045. var morphTargetsPosition = [];
  6046. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6047. morphTargetsPosition[ i ] = [];
  6048. }
  6049. this.morphTargets.position = morphTargetsPosition;
  6050. }
  6051. var morphNormals = geometry.morphNormals;
  6052. var morphNormalsLength = morphNormals.length;
  6053. if ( morphNormalsLength > 0 ) {
  6054. var morphTargetsNormal = [];
  6055. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6056. morphTargetsNormal[ i ] = [];
  6057. }
  6058. this.morphTargets.normal = morphTargetsNormal;
  6059. }
  6060. // skins
  6061. var skinIndices = geometry.skinIndices;
  6062. var skinWeights = geometry.skinWeights;
  6063. var hasSkinIndices = skinIndices.length === vertices.length;
  6064. var hasSkinWeights = skinWeights.length === vertices.length;
  6065. //
  6066. for ( var i = 0; i < faces.length; i ++ ) {
  6067. var face = faces[ i ];
  6068. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6069. var vertexNormals = face.vertexNormals;
  6070. if ( vertexNormals.length === 3 ) {
  6071. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6072. } else {
  6073. var normal = face.normal;
  6074. this.normals.push( normal, normal, normal );
  6075. }
  6076. var vertexColors = face.vertexColors;
  6077. if ( vertexColors.length === 3 ) {
  6078. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6079. } else {
  6080. var color = face.color;
  6081. this.colors.push( color, color, color );
  6082. }
  6083. if ( hasFaceVertexUv === true ) {
  6084. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6085. if ( vertexUvs !== undefined ) {
  6086. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6087. } else {
  6088. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6089. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6090. }
  6091. }
  6092. if ( hasFaceVertexUv2 === true ) {
  6093. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6094. if ( vertexUvs !== undefined ) {
  6095. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6096. } else {
  6097. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6098. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6099. }
  6100. }
  6101. if ( hasTangents === true ) {
  6102. var vertexTangents = face.vertexTangents;
  6103. if ( vertexTangents.length === 3 ) {
  6104. this.tangents.push( vertexTangents[ 0 ], vertexTangents[ 1 ], vertexTangents[ 2 ] );
  6105. } else {
  6106. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined tangents ', i );
  6107. this.tangents.push( new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4() );
  6108. }
  6109. }
  6110. // morphs
  6111. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6112. var morphTarget = morphTargets[ j ].vertices;
  6113. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6114. }
  6115. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6116. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6117. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6118. }
  6119. // skins
  6120. if ( hasSkinIndices ) {
  6121. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6122. }
  6123. if ( hasSkinWeights ) {
  6124. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6125. }
  6126. }
  6127. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6128. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6129. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6130. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6131. this.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  6132. return this;
  6133. },
  6134. dispose: function () {
  6135. this.dispatchEvent( { type: 'dispose' } );
  6136. }
  6137. };
  6138. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6139. // File:src/core/BufferGeometry.js
  6140. /**
  6141. * @author alteredq / http://alteredqualia.com/
  6142. * @author mrdoob / http://mrdoob.com/
  6143. */
  6144. THREE.BufferGeometry = function () {
  6145. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6146. this.uuid = THREE.Math.generateUUID();
  6147. this.name = '';
  6148. this.type = 'BufferGeometry';
  6149. this.attributes = {};
  6150. this.morphAttributes = {};
  6151. this.drawcalls = [];
  6152. this.boundingBox = null;
  6153. this.boundingSphere = null;
  6154. };
  6155. THREE.BufferGeometry.prototype = {
  6156. constructor: THREE.BufferGeometry,
  6157. addAttribute: function ( name, attribute ) {
  6158. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6159. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6160. this.attributes[ name ] = { array: arguments[ 1 ], itemSize: arguments[ 2 ] };
  6161. return;
  6162. }
  6163. this.attributes[ name ] = attribute;
  6164. },
  6165. getAttribute: function ( name ) {
  6166. return this.attributes[ name ];
  6167. },
  6168. removeAttribute: function ( name ) {
  6169. delete this.attributes[ name ];
  6170. },
  6171. get offsets() {
  6172. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .drawcalls.' );
  6173. return this.drawcalls;
  6174. },
  6175. addDrawCall: function ( start, count, indexOffset ) {
  6176. this.drawcalls.push( {
  6177. start: start,
  6178. count: count,
  6179. index: indexOffset !== undefined ? indexOffset : 0
  6180. } );
  6181. },
  6182. clearDrawCalls: function () {
  6183. this.drawcalls = [];
  6184. },
  6185. applyMatrix: function ( matrix ) {
  6186. var position = this.attributes.position;
  6187. if ( position !== undefined ) {
  6188. matrix.applyToVector3Array( position.array );
  6189. position.needsUpdate = true;
  6190. }
  6191. var normal = this.attributes.normal;
  6192. if ( normal !== undefined ) {
  6193. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6194. normalMatrix.applyToVector3Array( normal.array );
  6195. normal.needsUpdate = true;
  6196. }
  6197. if ( this.boundingBox !== null ) {
  6198. this.computeBoundingBox();
  6199. }
  6200. if ( this.boundingSphere !== null ) {
  6201. this.computeBoundingSphere();
  6202. }
  6203. },
  6204. center: function () {
  6205. this.computeBoundingBox();
  6206. var offset = this.boundingBox.center().negate();
  6207. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  6208. return offset;
  6209. },
  6210. setFromObject: function ( object ) {
  6211. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6212. var geometry = object.geometry;
  6213. if ( object instanceof THREE.PointCloud || object instanceof THREE.Line ) {
  6214. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6215. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6216. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6217. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6218. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6219. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6220. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6221. }
  6222. if ( geometry.boundingSphere !== null ) {
  6223. this.boundingSphere = geometry.boundingSphere.clone();
  6224. }
  6225. if ( geometry.boundingBox !== null ) {
  6226. this.boundingBox = geometry.boundingBox.clone();
  6227. }
  6228. } else if ( object instanceof THREE.Mesh ) {
  6229. if ( geometry instanceof THREE.Geometry ) {
  6230. this.fromGeometry( geometry );
  6231. }
  6232. }
  6233. return this;
  6234. },
  6235. updateFromObject: function ( object ) {
  6236. var geometry = object.geometry;
  6237. if ( object instanceof THREE.Mesh ) {
  6238. var direct = geometry.__directGeometry;
  6239. if ( direct === undefined ) {
  6240. return this.fromGeometry( geometry );
  6241. }
  6242. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6243. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6244. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6245. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6246. direct.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  6247. geometry.verticesNeedUpdate = false;
  6248. geometry.normalsNeedUpdate = false;
  6249. geometry.colorsNeedUpdate = false;
  6250. geometry.uvsNeedUpdate = false;
  6251. geometry.tangentsNeedUpdate = false;
  6252. geometry = direct;
  6253. }
  6254. if ( geometry.verticesNeedUpdate === true ) {
  6255. var attribute = this.attributes.position;
  6256. if ( attribute !== undefined ) {
  6257. attribute.copyVector3sArray( geometry.vertices );
  6258. attribute.needsUpdate = true;
  6259. }
  6260. geometry.verticesNeedUpdate = false;
  6261. }
  6262. if ( geometry.normalsNeedUpdate === true ) {
  6263. var attribute = this.attributes.normal;
  6264. if ( attribute !== undefined ) {
  6265. attribute.copyVector3sArray( geometry.normals );
  6266. attribute.needsUpdate = true;
  6267. }
  6268. geometry.normalsNeedUpdate = false;
  6269. }
  6270. if ( geometry.colorsNeedUpdate === true ) {
  6271. var attribute = this.attributes.color;
  6272. if ( attribute !== undefined ) {
  6273. attribute.copyColorsArray( geometry.colors );
  6274. attribute.needsUpdate = true;
  6275. }
  6276. geometry.colorsNeedUpdate = false;
  6277. }
  6278. if ( geometry.tangentsNeedUpdate === true ) {
  6279. var attribute = this.attributes.tangent;
  6280. if ( attribute !== undefined ) {
  6281. attribute.copyVector4sArray( geometry.tangents );
  6282. attribute.needsUpdate = true;
  6283. }
  6284. geometry.tangentsNeedUpdate = false;
  6285. }
  6286. if ( geometry.lineDistancesNeedUpdate ) {
  6287. var attribute = this.attributes.lineDistance;
  6288. if ( attribute !== undefined ) {
  6289. attribute.copyArray( geometry.lineDistances );
  6290. attribute.needsUpdate = true;
  6291. }
  6292. geometry.lineDistancesNeedUpdate = false;
  6293. }
  6294. return this;
  6295. },
  6296. fromGeometry: function ( geometry ) {
  6297. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6298. return this.fromDirectGeometry( geometry.__directGeometry );
  6299. },
  6300. fromDirectGeometry: function ( geometry ) {
  6301. var positions = new Float32Array( geometry.vertices.length * 3 );
  6302. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6303. if ( geometry.normals.length > 0 ) {
  6304. var normals = new Float32Array( geometry.normals.length * 3 );
  6305. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6306. }
  6307. if ( geometry.colors.length > 0 ) {
  6308. var colors = new Float32Array( geometry.colors.length * 3 );
  6309. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6310. }
  6311. if ( geometry.uvs.length > 0 ) {
  6312. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6313. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6314. }
  6315. if ( geometry.uvs2.length > 0 ) {
  6316. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6317. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6318. }
  6319. if ( geometry.tangents.length > 0 ) {
  6320. var tangents = new Float32Array( geometry.tangents.length * 4 );
  6321. this.addAttribute( 'tangent', new THREE.BufferAttribute( tangents, 4 ).copyVector4sArray( geometry.tangents ) );
  6322. }
  6323. if ( geometry.indices.length > 0 ) {
  6324. var indices = new Uint16Array( geometry.indices.length * 3 );
  6325. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6326. }
  6327. // morphs
  6328. for ( var name in geometry.morphTargets ) {
  6329. var array = [];
  6330. var morphTargets = geometry.morphTargets[ name ];
  6331. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6332. var morphTarget = morphTargets[ i ];
  6333. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6334. array.push( attribute.copyVector3sArray( morphTarget ) );
  6335. }
  6336. this.morphAttributes[ name ] = array;
  6337. }
  6338. // skinning
  6339. if ( geometry.skinIndices.length > 0 ) {
  6340. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6341. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6342. }
  6343. if ( geometry.skinWeights.length > 0 ) {
  6344. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6345. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6346. }
  6347. //
  6348. if ( geometry.boundingSphere !== null ) {
  6349. this.boundingSphere = geometry.boundingSphere.clone();
  6350. }
  6351. if ( geometry.boundingBox !== null ) {
  6352. this.boundingBox = geometry.boundingBox.clone();
  6353. }
  6354. return this;
  6355. },
  6356. computeBoundingBox: function () {
  6357. var vector = new THREE.Vector3();
  6358. return function () {
  6359. if ( this.boundingBox === null ) {
  6360. this.boundingBox = new THREE.Box3();
  6361. }
  6362. var positions = this.attributes.position.array;
  6363. if ( positions ) {
  6364. var bb = this.boundingBox;
  6365. bb.makeEmpty();
  6366. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6367. vector.fromArray( positions, i );
  6368. bb.expandByPoint( vector );
  6369. }
  6370. }
  6371. if ( positions === undefined || positions.length === 0 ) {
  6372. this.boundingBox.min.set( 0, 0, 0 );
  6373. this.boundingBox.max.set( 0, 0, 0 );
  6374. }
  6375. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6376. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6377. }
  6378. };
  6379. }(),
  6380. computeBoundingSphere: function () {
  6381. var box = new THREE.Box3();
  6382. var vector = new THREE.Vector3();
  6383. return function () {
  6384. if ( this.boundingSphere === null ) {
  6385. this.boundingSphere = new THREE.Sphere();
  6386. }
  6387. var positions = this.attributes.position.array;
  6388. if ( positions ) {
  6389. box.makeEmpty();
  6390. var center = this.boundingSphere.center;
  6391. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6392. vector.fromArray( positions, i );
  6393. box.expandByPoint( vector );
  6394. }
  6395. box.center( center );
  6396. // hoping to find a boundingSphere with a radius smaller than the
  6397. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6398. var maxRadiusSq = 0;
  6399. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6400. vector.fromArray( positions, i );
  6401. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6402. }
  6403. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6404. if ( isNaN( this.boundingSphere.radius ) ) {
  6405. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6406. }
  6407. }
  6408. };
  6409. }(),
  6410. computeFaceNormals: function () {
  6411. // backwards compatibility
  6412. },
  6413. computeVertexNormals: function () {
  6414. var attributes = this.attributes;
  6415. if ( attributes.position ) {
  6416. var positions = attributes.position.array;
  6417. if ( attributes.normal === undefined ) {
  6418. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6419. } else {
  6420. // reset existing normals to zero
  6421. var normals = attributes.normal.array;
  6422. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6423. normals[ i ] = 0;
  6424. }
  6425. }
  6426. var normals = attributes.normal.array;
  6427. var vA, vB, vC,
  6428. pA = new THREE.Vector3(),
  6429. pB = new THREE.Vector3(),
  6430. pC = new THREE.Vector3(),
  6431. cb = new THREE.Vector3(),
  6432. ab = new THREE.Vector3();
  6433. // indexed elements
  6434. if ( attributes.index ) {
  6435. var indices = attributes.index.array;
  6436. if ( this.drawcalls.length === 0 ) {
  6437. this.addDrawCall( 0, indices.length );
  6438. }
  6439. for ( var j = 0, jl = this.drawcalls.length; j < jl; ++ j ) {
  6440. var start = this.drawcalls[ j ].start;
  6441. var count = this.drawcalls[ j ].count;
  6442. var index = this.drawcalls[ j ].index;
  6443. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6444. vA = ( index + indices[ i ] ) * 3;
  6445. vB = ( index + indices[ i + 1 ] ) * 3;
  6446. vC = ( index + indices[ i + 2 ] ) * 3;
  6447. pA.fromArray( positions, vA );
  6448. pB.fromArray( positions, vB );
  6449. pC.fromArray( positions, vC );
  6450. cb.subVectors( pC, pB );
  6451. ab.subVectors( pA, pB );
  6452. cb.cross( ab );
  6453. normals[ vA ] += cb.x;
  6454. normals[ vA + 1 ] += cb.y;
  6455. normals[ vA + 2 ] += cb.z;
  6456. normals[ vB ] += cb.x;
  6457. normals[ vB + 1 ] += cb.y;
  6458. normals[ vB + 2 ] += cb.z;
  6459. normals[ vC ] += cb.x;
  6460. normals[ vC + 1 ] += cb.y;
  6461. normals[ vC + 2 ] += cb.z;
  6462. }
  6463. }
  6464. } else {
  6465. // non-indexed elements (unconnected triangle soup)
  6466. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6467. pA.fromArray( positions, i );
  6468. pB.fromArray( positions, i + 3 );
  6469. pC.fromArray( positions, i + 6 );
  6470. cb.subVectors( pC, pB );
  6471. ab.subVectors( pA, pB );
  6472. cb.cross( ab );
  6473. normals[ i ] = cb.x;
  6474. normals[ i + 1 ] = cb.y;
  6475. normals[ i + 2 ] = cb.z;
  6476. normals[ i + 3 ] = cb.x;
  6477. normals[ i + 4 ] = cb.y;
  6478. normals[ i + 5 ] = cb.z;
  6479. normals[ i + 6 ] = cb.x;
  6480. normals[ i + 7 ] = cb.y;
  6481. normals[ i + 8 ] = cb.z;
  6482. }
  6483. }
  6484. this.normalizeNormals();
  6485. attributes.normal.needsUpdate = true;
  6486. }
  6487. },
  6488. computeTangents: function () {
  6489. // based on http://www.terathon.com/code/tangent.html
  6490. // (per vertex tangents)
  6491. if ( this.attributes.index === undefined ||
  6492. this.attributes.position === undefined ||
  6493. this.attributes.normal === undefined ||
  6494. this.attributes.uv === undefined ) {
  6495. console.warn( 'THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()' );
  6496. return;
  6497. }
  6498. var indices = this.attributes.index.array;
  6499. var positions = this.attributes.position.array;
  6500. var normals = this.attributes.normal.array;
  6501. var uvs = this.attributes.uv.array;
  6502. var nVertices = positions.length / 3;
  6503. if ( this.attributes.tangent === undefined ) {
  6504. this.addAttribute( 'tangent', new THREE.BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
  6505. }
  6506. var tangents = this.attributes.tangent.array;
  6507. var tan1 = [], tan2 = [];
  6508. for ( var k = 0; k < nVertices; k ++ ) {
  6509. tan1[ k ] = new THREE.Vector3();
  6510. tan2[ k ] = new THREE.Vector3();
  6511. }
  6512. var vA = new THREE.Vector3(),
  6513. vB = new THREE.Vector3(),
  6514. vC = new THREE.Vector3(),
  6515. uvA = new THREE.Vector2(),
  6516. uvB = new THREE.Vector2(),
  6517. uvC = new THREE.Vector2(),
  6518. x1, x2, y1, y2, z1, z2,
  6519. s1, s2, t1, t2, r;
  6520. var sdir = new THREE.Vector3(), tdir = new THREE.Vector3();
  6521. function handleTriangle( a, b, c ) {
  6522. vA.fromArray( positions, a * 3 );
  6523. vB.fromArray( positions, b * 3 );
  6524. vC.fromArray( positions, c * 3 );
  6525. uvA.fromArray( uvs, a * 2 );
  6526. uvB.fromArray( uvs, b * 2 );
  6527. uvC.fromArray( uvs, c * 2 );
  6528. x1 = vB.x - vA.x;
  6529. x2 = vC.x - vA.x;
  6530. y1 = vB.y - vA.y;
  6531. y2 = vC.y - vA.y;
  6532. z1 = vB.z - vA.z;
  6533. z2 = vC.z - vA.z;
  6534. s1 = uvB.x - uvA.x;
  6535. s2 = uvC.x - uvA.x;
  6536. t1 = uvB.y - uvA.y;
  6537. t2 = uvC.y - uvA.y;
  6538. r = 1.0 / ( s1 * t2 - s2 * t1 );
  6539. sdir.set(
  6540. ( t2 * x1 - t1 * x2 ) * r,
  6541. ( t2 * y1 - t1 * y2 ) * r,
  6542. ( t2 * z1 - t1 * z2 ) * r
  6543. );
  6544. tdir.set(
  6545. ( s1 * x2 - s2 * x1 ) * r,
  6546. ( s1 * y2 - s2 * y1 ) * r,
  6547. ( s1 * z2 - s2 * z1 ) * r
  6548. );
  6549. tan1[ a ].add( sdir );
  6550. tan1[ b ].add( sdir );
  6551. tan1[ c ].add( sdir );
  6552. tan2[ a ].add( tdir );
  6553. tan2[ b ].add( tdir );
  6554. tan2[ c ].add( tdir );
  6555. }
  6556. var i, il;
  6557. var j, jl;
  6558. var iA, iB, iC;
  6559. if ( this.drawcalls.length === 0 ) {
  6560. this.addDrawCall( 0, indices.length );
  6561. }
  6562. var drawcalls = this.drawcalls;
  6563. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6564. var start = drawcalls[ j ].start;
  6565. var count = drawcalls[ j ].count;
  6566. var index = drawcalls[ j ].index;
  6567. for ( i = start, il = start + count; i < il; i += 3 ) {
  6568. iA = index + indices[ i ];
  6569. iB = index + indices[ i + 1 ];
  6570. iC = index + indices[ i + 2 ];
  6571. handleTriangle( iA, iB, iC );
  6572. }
  6573. }
  6574. var tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3();
  6575. var n = new THREE.Vector3(), n2 = new THREE.Vector3();
  6576. var w, t, test;
  6577. function handleVertex( v ) {
  6578. n.fromArray( normals, v * 3 );
  6579. n2.copy( n );
  6580. t = tan1[ v ];
  6581. // Gram-Schmidt orthogonalize
  6582. tmp.copy( t );
  6583. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6584. // Calculate handedness
  6585. tmp2.crossVectors( n2, t );
  6586. test = tmp2.dot( tan2[ v ] );
  6587. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6588. tangents[ v * 4 ] = tmp.x;
  6589. tangents[ v * 4 + 1 ] = tmp.y;
  6590. tangents[ v * 4 + 2 ] = tmp.z;
  6591. tangents[ v * 4 + 3 ] = w;
  6592. }
  6593. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6594. var start = drawcalls[ j ].start;
  6595. var count = drawcalls[ j ].count;
  6596. var index = drawcalls[ j ].index;
  6597. for ( i = start, il = start + count; i < il; i += 3 ) {
  6598. iA = index + indices[ i ];
  6599. iB = index + indices[ i + 1 ];
  6600. iC = index + indices[ i + 2 ];
  6601. handleVertex( iA );
  6602. handleVertex( iB );
  6603. handleVertex( iC );
  6604. }
  6605. }
  6606. },
  6607. /*
  6608. Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices.
  6609. This method will effectively rewrite the index buffer and remap all attributes to match the new indices.
  6610. WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets.
  6611. size - Defaults to 65535 or 4294967296 if extension OES_element_index_uint supported, but allows for larger or smaller chunks.
  6612. */
  6613. computeOffsets: function ( size ) {
  6614. if ( size === undefined ) size = THREE.BufferGeometry.MaxIndex;
  6615. var indices = this.attributes.index.array;
  6616. var vertices = this.attributes.position.array;
  6617. var facesCount = ( indices.length / 3 );
  6618. var UintArray = ( ( vertices.length / 3 ) > 65535 && THREE.BufferGeometry.MaxIndex > 65535 ) ? Uint32Array : Uint16Array;
  6619. /*
  6620. console.log("Computing buffers in offsets of "+size+" -> indices:"+indices.length+" vertices:"+vertices.length);
  6621. console.log("Faces to process: "+(indices.length/3));
  6622. console.log("Reordering "+verticesCount+" vertices.");
  6623. */
  6624. var sortedIndices = new UintArray( indices.length );
  6625. var indexPtr = 0;
  6626. var vertexPtr = 0;
  6627. var tmpOffsets = [ { start: 0, count: 0, index: 0 } ];
  6628. var offset = tmpOffsets[ 0 ];
  6629. var duplicatedVertices = 0;
  6630. var newVerticeMaps = 0;
  6631. var faceVertices = new Int32Array( 6 );
  6632. var vertexMap = new Int32Array( vertices.length );
  6633. var revVertexMap = new Int32Array( vertices.length );
  6634. for ( var j = 0; j < vertices.length; j ++ ) {
  6635. vertexMap[ j ] = - 1; revVertexMap[ j ] = - 1;
  6636. }
  6637. /*
  6638. Traverse every face and reorder vertices in the proper offsets of 65k.
  6639. We can have more than 'size' entries in the index buffer per offset, but only reference 'size' values.
  6640. */
  6641. for ( var findex = 0; findex < facesCount; findex ++ ) {
  6642. newVerticeMaps = 0;
  6643. for ( var vo = 0; vo < 3; vo ++ ) {
  6644. var vid = indices[ findex * 3 + vo ];
  6645. if ( vertexMap[ vid ] === - 1 ) {
  6646. //Unmapped vertex
  6647. faceVertices[ vo * 2 ] = vid;
  6648. faceVertices[ vo * 2 + 1 ] = - 1;
  6649. newVerticeMaps ++;
  6650. } else if ( vertexMap[ vid ] < offset.index ) {
  6651. //Reused vertices from previous block (duplicate)
  6652. faceVertices[ vo * 2 ] = vid;
  6653. faceVertices[ vo * 2 + 1 ] = - 1;
  6654. duplicatedVertices ++;
  6655. } else {
  6656. //Reused vertex in the current block
  6657. faceVertices[ vo * 2 ] = vid;
  6658. faceVertices[ vo * 2 + 1 ] = vertexMap[ vid ];
  6659. }
  6660. }
  6661. var faceMax = vertexPtr + newVerticeMaps;
  6662. if ( faceMax > ( offset.index + size ) ) {
  6663. var new_offset = { start: indexPtr, count: 0, index: vertexPtr };
  6664. tmpOffsets.push( new_offset );
  6665. offset = new_offset;
  6666. //Re-evaluate reused vertices in light of new offset.
  6667. for ( var v = 0; v < 6; v += 2 ) {
  6668. var new_vid = faceVertices[ v + 1 ];
  6669. if ( new_vid > - 1 && new_vid < offset.index )
  6670. faceVertices[ v + 1 ] = - 1;
  6671. }
  6672. }
  6673. //Reindex the face.
  6674. for ( var v = 0; v < 6; v += 2 ) {
  6675. var vid = faceVertices[ v ];
  6676. var new_vid = faceVertices[ v + 1 ];
  6677. if ( new_vid === - 1 )
  6678. new_vid = vertexPtr ++;
  6679. vertexMap[ vid ] = new_vid;
  6680. revVertexMap[ new_vid ] = vid;
  6681. sortedIndices[ indexPtr ++ ] = new_vid - offset.index; //XXX overflows at 16bit
  6682. offset.count ++;
  6683. }
  6684. }
  6685. /* Move all attribute values to map to the new computed indices , also expand the vertex stack to match our new vertexPtr. */
  6686. this.reorderBuffers( sortedIndices, revVertexMap, vertexPtr );
  6687. this.clearDrawCalls();
  6688. for ( var i = 0; i < tmpOffsets.length; i ++ ) {
  6689. var tmpOffset = tmpOffsets[ i ];
  6690. this.addDrawCall( tmpOffset.start, tmpOffset.count, tmpOffset.index );
  6691. }
  6692. /*
  6693. var orderTime = Date.now();
  6694. console.log("Reorder time: "+(orderTime-s)+"ms");
  6695. console.log("Duplicated "+duplicatedVertices+" vertices.");
  6696. console.log("Compute Buffers time: "+(Date.now()-s)+"ms");
  6697. console.log("Draw tmpOffsets: "+tmpOffsets.length);
  6698. */
  6699. },
  6700. merge: function ( geometry, offset ) {
  6701. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6702. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6703. return;
  6704. }
  6705. if ( offset === undefined ) offset = 0;
  6706. var attributes = this.attributes;
  6707. for ( var key in attributes ) {
  6708. if ( geometry.attributes[ key ] === undefined ) continue;
  6709. var attribute1 = attributes[ key ];
  6710. var attributeArray1 = attribute1.array;
  6711. var attribute2 = geometry.attributes[ key ];
  6712. var attributeArray2 = attribute2.array;
  6713. var attributeSize = attribute2.itemSize;
  6714. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6715. attributeArray1[ j ] = attributeArray2[ i ];
  6716. }
  6717. }
  6718. return this;
  6719. },
  6720. normalizeNormals: function () {
  6721. var normals = this.attributes.normal.array;
  6722. var x, y, z, n;
  6723. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6724. x = normals[ i ];
  6725. y = normals[ i + 1 ];
  6726. z = normals[ i + 2 ];
  6727. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6728. normals[ i ] *= n;
  6729. normals[ i + 1 ] *= n;
  6730. normals[ i + 2 ] *= n;
  6731. }
  6732. },
  6733. /*
  6734. reoderBuffers:
  6735. Reorder attributes based on a new indexBuffer and indexMap.
  6736. indexBuffer - Uint16Array of the new ordered indices.
  6737. indexMap - Int32Array where the position is the new vertex ID and the value the old vertex ID for each vertex.
  6738. vertexCount - Amount of total vertices considered in this reordering (in case you want to grow the vertex stack).
  6739. */
  6740. reorderBuffers: function ( indexBuffer, indexMap, vertexCount ) {
  6741. /* Create a copy of all attributes for reordering. */
  6742. var sortedAttributes = {};
  6743. for ( var attr in this.attributes ) {
  6744. if ( attr === 'index' )
  6745. continue;
  6746. var sourceArray = this.attributes[ attr ].array;
  6747. sortedAttributes[ attr ] = new sourceArray.constructor( this.attributes[ attr ].itemSize * vertexCount );
  6748. }
  6749. /* Move attribute positions based on the new index map */
  6750. for ( var new_vid = 0; new_vid < vertexCount; new_vid ++ ) {
  6751. var vid = indexMap[ new_vid ];
  6752. for ( var attr in this.attributes ) {
  6753. if ( attr === 'index' )
  6754. continue;
  6755. var attrArray = this.attributes[ attr ].array;
  6756. var attrSize = this.attributes[ attr ].itemSize;
  6757. var sortedAttr = sortedAttributes[ attr ];
  6758. for ( var k = 0; k < attrSize; k ++ )
  6759. sortedAttr[ new_vid * attrSize + k ] = attrArray[ vid * attrSize + k ];
  6760. }
  6761. }
  6762. /* Carry the new sorted buffers locally */
  6763. this.attributes[ 'index' ].array = indexBuffer;
  6764. for ( var attr in this.attributes ) {
  6765. if ( attr === 'index' )
  6766. continue;
  6767. this.attributes[ attr ].array = sortedAttributes[ attr ];
  6768. this.attributes[ attr ].numItems = this.attributes[ attr ].itemSize * vertexCount;
  6769. }
  6770. },
  6771. toJSON: function () {
  6772. var data = {
  6773. metadata: {
  6774. version: 4.4,
  6775. type: 'BufferGeometry',
  6776. generator: 'BufferGeometry.toJSON'
  6777. }
  6778. };
  6779. // standard BufferGeometry serialization
  6780. data.uuid = this.uuid;
  6781. data.type = this.type;
  6782. if ( this.name !== '' ) data.name = this.name;
  6783. if ( this.parameters !== undefined ) {
  6784. var parameters = this.parameters;
  6785. for ( var key in parameters ) {
  6786. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6787. }
  6788. return data;
  6789. }
  6790. data.data = { attributes: {} };
  6791. var attributes = this.attributes;
  6792. var drawcalls = this.drawcalls;
  6793. var boundingSphere = this.boundingSphere;
  6794. for ( var key in attributes ) {
  6795. var attribute = attributes[ key ];
  6796. var array = Array.prototype.slice.call( attribute.array );
  6797. data.data.attributes[ key ] = {
  6798. itemSize: attribute.itemSize,
  6799. type: attribute.array.constructor.name,
  6800. array: array
  6801. };
  6802. }
  6803. if ( drawcalls.length > 0 ) {
  6804. data.data.drawcalls = JSON.parse( JSON.stringify( drawcalls ) );
  6805. }
  6806. if ( boundingSphere !== null ) {
  6807. data.data.boundingSphere = {
  6808. center: boundingSphere.center.toArray(),
  6809. radius: boundingSphere.radius
  6810. };
  6811. }
  6812. return data;
  6813. },
  6814. clone: function () {
  6815. return new THREE.BufferGeometry().copy( this );
  6816. },
  6817. copy: function ( source ) {
  6818. for ( var attr in source.attributes ) {
  6819. var sourceAttr = source.attributes[ attr ];
  6820. this.addAttribute( attr, sourceAttr.clone() );
  6821. }
  6822. for ( var i = 0, il = source.drawcalls.length; i < il; i ++ ) {
  6823. var offset = source.drawcalls[ i ];
  6824. this.addDrawCall( offset.start, offset.count, offset.index );
  6825. }
  6826. return this;
  6827. },
  6828. dispose: function () {
  6829. this.dispatchEvent( { type: 'dispose' } );
  6830. }
  6831. };
  6832. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6833. THREE.BufferGeometry.MaxIndex = 65535;
  6834. // File:src/core/InstancedBufferGeometry.js
  6835. /**
  6836. * @author benaadams / https://twitter.com/ben_a_adams
  6837. */
  6838. THREE.InstancedBufferGeometry = function () {
  6839. THREE.BufferGeometry.call( this );
  6840. this.type = 'InstancedBufferGeometry';
  6841. this.maxInstancedCount = undefined;
  6842. };
  6843. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6844. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6845. THREE.InstancedBufferGeometry.prototype.addDrawCall = function ( start, count, indexOffset, instances ) {
  6846. this.drawcalls.push( {
  6847. start: start,
  6848. count: count,
  6849. index: indexOffset !== undefined ? indexOffset : 0,
  6850. instances: instances
  6851. } );
  6852. },
  6853. THREE.InstancedBufferGeometry.prototype.clone = function () {
  6854. var geometry = new THREE.InstancedBufferGeometry();
  6855. for ( var attr in this.attributes ) {
  6856. var sourceAttr = this.attributes[ attr ];
  6857. geometry.addAttribute( attr, sourceAttr.clone() );
  6858. }
  6859. for ( var i = 0, il = this.drawcalls.length; i < il; i ++ ) {
  6860. var offset = this.drawcalls[ i ];
  6861. geometry.addDrawCall( offset.start, offset.count, offset.index, offset.instances );
  6862. }
  6863. return geometry;
  6864. };
  6865. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6866. // File:src/cameras/Camera.js
  6867. /**
  6868. * @author mrdoob / http://mrdoob.com/
  6869. * @author mikael emtinger / http://gomo.se/
  6870. * @author WestLangley / http://github.com/WestLangley
  6871. */
  6872. THREE.Camera = function () {
  6873. THREE.Object3D.call( this );
  6874. this.type = 'Camera';
  6875. this.matrixWorldInverse = new THREE.Matrix4();
  6876. this.projectionMatrix = new THREE.Matrix4();
  6877. };
  6878. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  6879. THREE.Camera.prototype.constructor = THREE.Camera;
  6880. THREE.Camera.prototype.getWorldDirection = function () {
  6881. var quaternion = new THREE.Quaternion();
  6882. return function ( optionalTarget ) {
  6883. var result = optionalTarget || new THREE.Vector3();
  6884. this.getWorldQuaternion( quaternion );
  6885. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  6886. };
  6887. }();
  6888. THREE.Camera.prototype.lookAt = function () {
  6889. // This routine does not support cameras with rotated and/or translated parent(s)
  6890. var m1 = new THREE.Matrix4();
  6891. return function ( vector ) {
  6892. m1.lookAt( this.position, vector, this.up );
  6893. this.quaternion.setFromRotationMatrix( m1 );
  6894. };
  6895. }();
  6896. THREE.Camera.prototype.clone = function () {
  6897. var camera = new THREE.Camera();
  6898. return camera.copy( this );
  6899. };
  6900. THREE.Camera.prototype.copy = function ( source ) {
  6901. THREE.Object3D.prototype.copy.call( this, source );
  6902. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  6903. this.projectionMatrix.copy( source.projectionMatrix );
  6904. return this;
  6905. };
  6906. // File:src/cameras/CubeCamera.js
  6907. /**
  6908. * Camera for rendering cube maps
  6909. * - renders scene into axis-aligned cube
  6910. *
  6911. * @author alteredq / http://alteredqualia.com/
  6912. */
  6913. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  6914. THREE.Object3D.call( this );
  6915. this.type = 'CubeCamera';
  6916. var fov = 90, aspect = 1;
  6917. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6918. cameraPX.up.set( 0, - 1, 0 );
  6919. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  6920. this.add( cameraPX );
  6921. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6922. cameraNX.up.set( 0, - 1, 0 );
  6923. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  6924. this.add( cameraNX );
  6925. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6926. cameraPY.up.set( 0, 0, 1 );
  6927. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  6928. this.add( cameraPY );
  6929. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6930. cameraNY.up.set( 0, 0, - 1 );
  6931. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  6932. this.add( cameraNY );
  6933. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6934. cameraPZ.up.set( 0, - 1, 0 );
  6935. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  6936. this.add( cameraPZ );
  6937. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6938. cameraNZ.up.set( 0, - 1, 0 );
  6939. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  6940. this.add( cameraNZ );
  6941. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  6942. this.updateCubeMap = function ( renderer, scene ) {
  6943. if ( this.parent === undefined ) this.updateMatrixWorld();
  6944. var renderTarget = this.renderTarget;
  6945. var generateMipmaps = renderTarget.generateMipmaps;
  6946. renderTarget.generateMipmaps = false;
  6947. renderTarget.activeCubeFace = 0;
  6948. renderer.render( scene, cameraPX, renderTarget );
  6949. renderTarget.activeCubeFace = 1;
  6950. renderer.render( scene, cameraNX, renderTarget );
  6951. renderTarget.activeCubeFace = 2;
  6952. renderer.render( scene, cameraPY, renderTarget );
  6953. renderTarget.activeCubeFace = 3;
  6954. renderer.render( scene, cameraNY, renderTarget );
  6955. renderTarget.activeCubeFace = 4;
  6956. renderer.render( scene, cameraPZ, renderTarget );
  6957. renderTarget.generateMipmaps = generateMipmaps;
  6958. renderTarget.activeCubeFace = 5;
  6959. renderer.render( scene, cameraNZ, renderTarget );
  6960. renderer.setRenderTarget( null );
  6961. };
  6962. };
  6963. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  6964. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  6965. // File:src/cameras/OrthographicCamera.js
  6966. /**
  6967. * @author alteredq / http://alteredqualia.com/
  6968. */
  6969. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  6970. THREE.Camera.call( this );
  6971. this.type = 'OrthographicCamera';
  6972. this.zoom = 1;
  6973. this.left = left;
  6974. this.right = right;
  6975. this.top = top;
  6976. this.bottom = bottom;
  6977. this.near = ( near !== undefined ) ? near : 0.1;
  6978. this.far = ( far !== undefined ) ? far : 2000;
  6979. this.updateProjectionMatrix();
  6980. };
  6981. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  6982. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  6983. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  6984. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  6985. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  6986. var cx = ( this.right + this.left ) / 2;
  6987. var cy = ( this.top + this.bottom ) / 2;
  6988. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  6989. };
  6990. THREE.OrthographicCamera.prototype.clone = function () {
  6991. var camera = new THREE.OrthographicCamera();
  6992. camera.copy( this );
  6993. camera.zoom = this.zoom;
  6994. camera.left = this.left;
  6995. camera.right = this.right;
  6996. camera.top = this.top;
  6997. camera.bottom = this.bottom;
  6998. camera.near = this.near;
  6999. camera.far = this.far;
  7000. return camera;
  7001. };
  7002. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  7003. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7004. data.object.zoom = this.zoom;
  7005. data.object.left = this.left;
  7006. data.object.right = this.right;
  7007. data.object.top = this.top;
  7008. data.object.bottom = this.bottom;
  7009. data.object.near = this.near;
  7010. data.object.far = this.far;
  7011. return data;
  7012. };
  7013. // File:src/cameras/PerspectiveCamera.js
  7014. /**
  7015. * @author mrdoob / http://mrdoob.com/
  7016. * @author greggman / http://games.greggman.com/
  7017. * @author zz85 / http://www.lab4games.net/zz85/blog
  7018. */
  7019. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  7020. THREE.Camera.call( this );
  7021. this.type = 'PerspectiveCamera';
  7022. this.zoom = 1;
  7023. this.fov = fov !== undefined ? fov : 50;
  7024. this.aspect = aspect !== undefined ? aspect : 1;
  7025. this.near = near !== undefined ? near : 0.1;
  7026. this.far = far !== undefined ? far : 2000;
  7027. this.updateProjectionMatrix();
  7028. };
  7029. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  7030. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  7031. /**
  7032. * Uses Focal Length (in mm) to estimate and set FOV
  7033. * 35mm (full-frame) camera is used if frame size is not specified;
  7034. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  7035. */
  7036. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  7037. if ( frameHeight === undefined ) frameHeight = 24;
  7038. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  7039. this.updateProjectionMatrix();
  7040. };
  7041. /**
  7042. * Sets an offset in a larger frustum. This is useful for multi-window or
  7043. * multi-monitor/multi-machine setups.
  7044. *
  7045. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7046. * the monitors are in grid like this
  7047. *
  7048. * +---+---+---+
  7049. * | A | B | C |
  7050. * +---+---+---+
  7051. * | D | E | F |
  7052. * +---+---+---+
  7053. *
  7054. * then for each monitor you would call it like this
  7055. *
  7056. * var w = 1920;
  7057. * var h = 1080;
  7058. * var fullWidth = w * 3;
  7059. * var fullHeight = h * 2;
  7060. *
  7061. * --A--
  7062. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7063. * --B--
  7064. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7065. * --C--
  7066. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7067. * --D--
  7068. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7069. * --E--
  7070. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7071. * --F--
  7072. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7073. *
  7074. * Note there is no reason monitors have to be the same size or in a grid.
  7075. */
  7076. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  7077. this.fullWidth = fullWidth;
  7078. this.fullHeight = fullHeight;
  7079. this.x = x;
  7080. this.y = y;
  7081. this.width = width;
  7082. this.height = height;
  7083. this.updateProjectionMatrix();
  7084. };
  7085. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  7086. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  7087. if ( this.fullWidth ) {
  7088. var aspect = this.fullWidth / this.fullHeight;
  7089. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  7090. var bottom = - top;
  7091. var left = aspect * bottom;
  7092. var right = aspect * top;
  7093. var width = Math.abs( right - left );
  7094. var height = Math.abs( top - bottom );
  7095. this.projectionMatrix.makeFrustum(
  7096. left + this.x * width / this.fullWidth,
  7097. left + ( this.x + this.width ) * width / this.fullWidth,
  7098. top - ( this.y + this.height ) * height / this.fullHeight,
  7099. top - this.y * height / this.fullHeight,
  7100. this.near,
  7101. this.far
  7102. );
  7103. } else {
  7104. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  7105. }
  7106. };
  7107. THREE.PerspectiveCamera.prototype.clone = function () {
  7108. var camera = new THREE.PerspectiveCamera();
  7109. camera.copy( this );
  7110. camera.zoom = this.zoom;
  7111. camera.fov = this.fov;
  7112. camera.aspect = this.aspect;
  7113. camera.near = this.near;
  7114. camera.far = this.far;
  7115. return camera;
  7116. };
  7117. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  7118. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7119. data.object.zoom = this.zoom;
  7120. data.object.fov = this.fov;
  7121. data.object.aspect = this.aspect;
  7122. data.object.near = this.near;
  7123. data.object.far = this.far;
  7124. return data;
  7125. };
  7126. // File:src/lights/Light.js
  7127. /**
  7128. * @author mrdoob / http://mrdoob.com/
  7129. * @author alteredq / http://alteredqualia.com/
  7130. */
  7131. THREE.Light = function ( color ) {
  7132. THREE.Object3D.call( this );
  7133. this.type = 'Light';
  7134. this.color = new THREE.Color( color );
  7135. };
  7136. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  7137. THREE.Light.prototype.constructor = THREE.Light;
  7138. THREE.Light.prototype.clone = function () {
  7139. var light = new THREE.Light();
  7140. return light.copy( this );
  7141. };
  7142. THREE.Light.prototype.copy = function ( source ) {
  7143. THREE.Object3D.prototype.copy.call( this, source );
  7144. this.color.copy( source.color );
  7145. return this;
  7146. };
  7147. // File:src/lights/AmbientLight.js
  7148. /**
  7149. * @author mrdoob / http://mrdoob.com/
  7150. */
  7151. THREE.AmbientLight = function ( color ) {
  7152. THREE.Light.call( this, color );
  7153. this.type = 'AmbientLight';
  7154. };
  7155. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  7156. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  7157. THREE.AmbientLight.prototype.clone = function () {
  7158. var light = new THREE.AmbientLight();
  7159. light.copy( this );
  7160. return light;
  7161. };
  7162. THREE.AmbientLight.prototype.toJSON = function ( meta ) {
  7163. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7164. data.object.color = this.color.getHex();
  7165. return data;
  7166. };
  7167. // File:src/lights/AreaLight.js
  7168. /**
  7169. * @author MPanknin / http://www.redplant.de/
  7170. * @author alteredq / http://alteredqualia.com/
  7171. * @author prafullit
  7172. */
  7173. THREE.AreaLight = function ( color, intensity ) {
  7174. THREE.Light.call( this, color );
  7175. this.type = 'AreaLight';
  7176. this.normal = new THREE.Vector3( 0, - 1, 0 );
  7177. this.right = new THREE.Vector3( 1, 0, 0 );
  7178. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7179. this.width = 1.0;
  7180. this.height = 1.0;
  7181. this.constantAttenuation = 1.5;
  7182. this.linearAttenuation = 0.5;
  7183. this.quadraticAttenuation = 0.1;
  7184. };
  7185. THREE.AreaLight.prototype = Object.create( THREE.Light.prototype );
  7186. THREE.AreaLight.prototype.constructor = THREE.AreaLight;
  7187. THREE.AreaLight.prototype.clone = function () {
  7188. var light = new THREE.AreaLight();
  7189. light.copy( this );
  7190. light.normal.copy( this.normal );
  7191. light.right.copy( this.right );
  7192. light.intensity = this.intensity;
  7193. light.width = this.width;
  7194. light.height = this.height;
  7195. light.constantAttenuation = this.constantAttenuation;
  7196. light.linearAttenuation = this.linearAttenuation;
  7197. light.quadraticAttenuation = this.quadraticAttenuation;
  7198. return light;
  7199. };
  7200. THREE.AreaLight.prototype.toJSON = function ( meta ) {
  7201. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7202. data.object.color = this.color.getHex();
  7203. data.object.intensity = this.intensity;
  7204. return data;
  7205. };
  7206. // File:src/lights/DirectionalLight.js
  7207. /**
  7208. * @author mrdoob / http://mrdoob.com/
  7209. * @author alteredq / http://alteredqualia.com/
  7210. */
  7211. THREE.DirectionalLight = function ( color, intensity ) {
  7212. THREE.Light.call( this, color );
  7213. this.type = 'DirectionalLight';
  7214. this.position.set( 0, 1, 0 );
  7215. this.target = new THREE.Object3D();
  7216. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7217. this.castShadow = false;
  7218. this.onlyShadow = false;
  7219. //
  7220. this.shadowCameraNear = 50;
  7221. this.shadowCameraFar = 5000;
  7222. this.shadowCameraLeft = - 500;
  7223. this.shadowCameraRight = 500;
  7224. this.shadowCameraTop = 500;
  7225. this.shadowCameraBottom = - 500;
  7226. this.shadowCameraVisible = false;
  7227. this.shadowBias = 0;
  7228. this.shadowDarkness = 0.5;
  7229. this.shadowMapWidth = 512;
  7230. this.shadowMapHeight = 512;
  7231. //
  7232. this.shadowMap = null;
  7233. this.shadowMapSize = null;
  7234. this.shadowCamera = null;
  7235. this.shadowMatrix = null;
  7236. };
  7237. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  7238. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  7239. THREE.DirectionalLight.prototype.clone = function () {
  7240. var light = new THREE.DirectionalLight();
  7241. light.copy( this );
  7242. light.target = this.target.clone();
  7243. light.intensity = this.intensity;
  7244. light.castShadow = this.castShadow;
  7245. light.onlyShadow = this.onlyShadow;
  7246. //
  7247. light.shadowCameraNear = this.shadowCameraNear;
  7248. light.shadowCameraFar = this.shadowCameraFar;
  7249. light.shadowCameraLeft = this.shadowCameraLeft;
  7250. light.shadowCameraRight = this.shadowCameraRight;
  7251. light.shadowCameraTop = this.shadowCameraTop;
  7252. light.shadowCameraBottom = this.shadowCameraBottom;
  7253. light.shadowCameraVisible = this.shadowCameraVisible;
  7254. light.shadowBias = this.shadowBias;
  7255. light.shadowDarkness = this.shadowDarkness;
  7256. light.shadowMapWidth = this.shadowMapWidth;
  7257. light.shadowMapHeight = this.shadowMapHeight;
  7258. return light;
  7259. };
  7260. THREE.DirectionalLight.prototype.toJSON = function ( meta ) {
  7261. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7262. data.object.color = this.color.getHex();
  7263. data.object.intensity = this.intensity;
  7264. return data;
  7265. };
  7266. // File:src/lights/HemisphereLight.js
  7267. /**
  7268. * @author alteredq / http://alteredqualia.com/
  7269. */
  7270. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  7271. THREE.Light.call( this, skyColor );
  7272. this.type = 'HemisphereLight';
  7273. this.position.set( 0, 100, 0 );
  7274. this.groundColor = new THREE.Color( groundColor );
  7275. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7276. };
  7277. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  7278. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  7279. THREE.HemisphereLight.prototype.clone = function () {
  7280. var light = new THREE.HemisphereLight();
  7281. light.copy( this );
  7282. light.groundColor.copy( this.groundColor );
  7283. light.intensity = this.intensity;
  7284. return light;
  7285. };
  7286. THREE.HemisphereLight.prototype.toJSON = function ( meta ) {
  7287. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7288. data.object.color = this.color.getHex();
  7289. data.object.groundColor = this.groundColor.getHex();
  7290. return data;
  7291. };
  7292. // File:src/lights/PointLight.js
  7293. /**
  7294. * @author mrdoob / http://mrdoob.com/
  7295. */
  7296. THREE.PointLight = function ( color, intensity, distance, decay ) {
  7297. THREE.Light.call( this, color );
  7298. this.type = 'PointLight';
  7299. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7300. this.distance = ( distance !== undefined ) ? distance : 0;
  7301. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7302. };
  7303. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  7304. THREE.PointLight.prototype.constructor = THREE.PointLight;
  7305. THREE.PointLight.prototype.clone = function () {
  7306. var light = new THREE.PointLight();
  7307. light.copy( this );
  7308. light.intensity = this.intensity;
  7309. light.distance = this.distance;
  7310. light.decay = this.decay;
  7311. return light;
  7312. };
  7313. THREE.PointLight.prototype.toJSON = function ( meta ) {
  7314. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7315. data.object.color = this.color.getHex();
  7316. data.object.intensity = this.intensity;
  7317. data.object.distance = this.distance;
  7318. data.object.decay = this.decay;
  7319. return data;
  7320. };
  7321. // File:src/lights/SpotLight.js
  7322. /**
  7323. * @author alteredq / http://alteredqualia.com/
  7324. */
  7325. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  7326. THREE.Light.call( this, color );
  7327. this.type = 'SpotLight';
  7328. this.position.set( 0, 1, 0 );
  7329. this.target = new THREE.Object3D();
  7330. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7331. this.distance = ( distance !== undefined ) ? distance : 0;
  7332. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  7333. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  7334. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7335. this.castShadow = false;
  7336. this.onlyShadow = false;
  7337. //
  7338. this.shadowCameraNear = 50;
  7339. this.shadowCameraFar = 5000;
  7340. this.shadowCameraFov = 50;
  7341. this.shadowCameraVisible = false;
  7342. this.shadowBias = 0;
  7343. this.shadowDarkness = 0.5;
  7344. this.shadowMapWidth = 512;
  7345. this.shadowMapHeight = 512;
  7346. //
  7347. this.shadowMap = null;
  7348. this.shadowMapSize = null;
  7349. this.shadowCamera = null;
  7350. this.shadowMatrix = null;
  7351. };
  7352. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  7353. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  7354. THREE.SpotLight.prototype.clone = function () {
  7355. var light = new THREE.SpotLight();
  7356. light.copy( this );
  7357. light.target = this.target.clone();
  7358. light.intensity = this.intensity;
  7359. light.distance = this.distance;
  7360. light.angle = this.angle;
  7361. light.exponent = this.exponent;
  7362. light.decay = this.decay;
  7363. light.castShadow = this.castShadow;
  7364. light.onlyShadow = this.onlyShadow;
  7365. //
  7366. light.shadowCameraNear = this.shadowCameraNear;
  7367. light.shadowCameraFar = this.shadowCameraFar;
  7368. light.shadowCameraFov = this.shadowCameraFov;
  7369. light.shadowCameraVisible = this.shadowCameraVisible;
  7370. light.shadowBias = this.shadowBias;
  7371. light.shadowDarkness = this.shadowDarkness;
  7372. light.shadowMapWidth = this.shadowMapWidth;
  7373. light.shadowMapHeight = this.shadowMapHeight;
  7374. return light;
  7375. };
  7376. THREE.SpotLight.prototype.toJSON = function ( meta ) {
  7377. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7378. data.object.color = this.color.getHex();
  7379. data.object.intensity = this.intensity;
  7380. data.object.distance = this.distance;
  7381. data.object.angle = this.angle;
  7382. data.object.exponent = this.exponent;
  7383. data.object.decay = this.decay;
  7384. return data;
  7385. };
  7386. // File:src/loaders/Cache.js
  7387. /**
  7388. * @author mrdoob / http://mrdoob.com/
  7389. */
  7390. THREE.Cache = {
  7391. enabled: false,
  7392. files: {},
  7393. add: function ( key, file ) {
  7394. if ( this.enabled === false ) return;
  7395. // console.log( 'THREE.Cache', 'Adding key:', key );
  7396. this.files[ key ] = file;
  7397. },
  7398. get: function ( key ) {
  7399. if ( this.enabled === false ) return;
  7400. // console.log( 'THREE.Cache', 'Checking key:', key );
  7401. return this.files[ key ];
  7402. },
  7403. remove: function ( key ) {
  7404. delete this.files[ key ];
  7405. },
  7406. clear: function () {
  7407. this.files = {};
  7408. }
  7409. };
  7410. // File:src/loaders/Loader.js
  7411. /**
  7412. * @author alteredq / http://alteredqualia.com/
  7413. */
  7414. THREE.Loader = function () {
  7415. this.onLoadStart = function () {};
  7416. this.onLoadProgress = function () {};
  7417. this.onLoadComplete = function () {};
  7418. };
  7419. THREE.Loader.prototype = {
  7420. constructor: THREE.Loader,
  7421. crossOrigin: undefined,
  7422. extractUrlBase: function ( url ) {
  7423. var parts = url.split( '/' );
  7424. if ( parts.length === 1 ) return './';
  7425. parts.pop();
  7426. return parts.join( '/' ) + '/';
  7427. },
  7428. initMaterials: function ( materials, texturePath, crossOrigin ) {
  7429. var array = [];
  7430. for ( var i = 0; i < materials.length; ++ i ) {
  7431. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  7432. }
  7433. return array;
  7434. },
  7435. needsTangents: function ( materials ) {
  7436. for ( var i = 0, il = materials.length; i < il; i ++ ) {
  7437. var m = materials[ i ];
  7438. if ( m instanceof THREE.ShaderMaterial ) return true;
  7439. }
  7440. return false;
  7441. },
  7442. createMaterial: ( function () {
  7443. var imageLoader;
  7444. return function createMaterial( m, texturePath, crossOrigin ) {
  7445. var scope = this;
  7446. if ( crossOrigin === undefined && scope.crossOrigin !== undefined ) crossOrigin = scope.crossOrigin;
  7447. if ( imageLoader === undefined ) imageLoader = new THREE.ImageLoader();
  7448. function nearest_pow2( n ) {
  7449. var l = Math.log( n ) / Math.LN2;
  7450. return Math.pow( 2, Math.round( l ) );
  7451. }
  7452. function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
  7453. var fullPath = texturePath + sourceFile;
  7454. var texture;
  7455. var loader = THREE.Loader.Handlers.get( fullPath );
  7456. if ( loader !== null ) {
  7457. texture = loader.load( fullPath );
  7458. } else {
  7459. texture = new THREE.Texture();
  7460. loader = imageLoader;
  7461. loader.setCrossOrigin( crossOrigin );
  7462. loader.load( fullPath, function ( image ) {
  7463. if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
  7464. THREE.Math.isPowerOfTwo( image.height ) === false ) {
  7465. var width = nearest_pow2( image.width );
  7466. var height = nearest_pow2( image.height );
  7467. var canvas = document.createElement( 'canvas' );
  7468. canvas.width = width;
  7469. canvas.height = height;
  7470. var context = canvas.getContext( '2d' );
  7471. context.drawImage( image, 0, 0, width, height );
  7472. texture.image = canvas;
  7473. } else {
  7474. texture.image = image;
  7475. }
  7476. texture.needsUpdate = true;
  7477. } );
  7478. }
  7479. texture.sourceFile = sourceFile;
  7480. if ( repeat ) {
  7481. texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
  7482. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  7483. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  7484. }
  7485. if ( offset ) {
  7486. texture.offset.set( offset[ 0 ], offset[ 1 ] );
  7487. }
  7488. if ( wrap ) {
  7489. var wrapMap = {
  7490. 'repeat': THREE.RepeatWrapping,
  7491. 'mirror': THREE.MirroredRepeatWrapping
  7492. };
  7493. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
  7494. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
  7495. }
  7496. if ( anisotropy ) {
  7497. texture.anisotropy = anisotropy;
  7498. }
  7499. where[ name ] = texture;
  7500. }
  7501. function rgb2hex( rgb ) {
  7502. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  7503. }
  7504. // defaults
  7505. var mtype = 'MeshLambertMaterial';
  7506. var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
  7507. // parameters from model file
  7508. if ( m.shading ) {
  7509. var shading = m.shading.toLowerCase();
  7510. if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
  7511. else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
  7512. }
  7513. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  7514. mpars.blending = THREE[ m.blending ];
  7515. }
  7516. if ( m.transparent !== undefined ) {
  7517. mpars.transparent = m.transparent;
  7518. }
  7519. if ( m.opacity !== undefined && m.opacity < 1.0 ) {
  7520. mpars.transparent = true;
  7521. }
  7522. if ( m.depthTest !== undefined ) {
  7523. mpars.depthTest = m.depthTest;
  7524. }
  7525. if ( m.depthWrite !== undefined ) {
  7526. mpars.depthWrite = m.depthWrite;
  7527. }
  7528. if ( m.visible !== undefined ) {
  7529. mpars.visible = m.visible;
  7530. }
  7531. if ( m.flipSided !== undefined ) {
  7532. mpars.side = THREE.BackSide;
  7533. }
  7534. if ( m.doubleSided !== undefined ) {
  7535. mpars.side = THREE.DoubleSide;
  7536. }
  7537. if ( m.wireframe !== undefined ) {
  7538. mpars.wireframe = m.wireframe;
  7539. }
  7540. if ( m.vertexColors !== undefined ) {
  7541. if ( m.vertexColors === 'face' ) {
  7542. mpars.vertexColors = THREE.FaceColors;
  7543. } else if ( m.vertexColors ) {
  7544. mpars.vertexColors = THREE.VertexColors;
  7545. }
  7546. }
  7547. // colors
  7548. if ( m.colorDiffuse ) {
  7549. mpars.color = rgb2hex( m.colorDiffuse );
  7550. } else if ( m.DbgColor ) {
  7551. mpars.color = m.DbgColor;
  7552. }
  7553. if ( m.colorSpecular ) {
  7554. mpars.specular = rgb2hex( m.colorSpecular );
  7555. }
  7556. if ( m.colorEmissive ) {
  7557. mpars.emissive = rgb2hex( m.colorEmissive );
  7558. }
  7559. // modifiers
  7560. if ( m.transparency !== undefined ) {
  7561. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  7562. m.opacity = m.transparency;
  7563. }
  7564. if ( m.opacity !== undefined ) {
  7565. mpars.opacity = m.opacity;
  7566. }
  7567. if ( m.specularCoef ) {
  7568. mpars.shininess = m.specularCoef;
  7569. }
  7570. // textures
  7571. if ( m.mapDiffuse && texturePath ) {
  7572. create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  7573. }
  7574. if ( m.mapLight && texturePath ) {
  7575. create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  7576. }
  7577. if ( m.mapAO && texturePath ) {
  7578. create_texture( mpars, 'aoMap', m.mapAO, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  7579. }
  7580. if ( m.mapBump && texturePath ) {
  7581. create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  7582. }
  7583. if ( m.mapNormal && texturePath ) {
  7584. create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  7585. }
  7586. if ( m.mapSpecular && texturePath ) {
  7587. create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  7588. }
  7589. if ( m.mapAlpha && texturePath ) {
  7590. create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  7591. }
  7592. //
  7593. if ( m.mapBumpScale ) {
  7594. mpars.bumpScale = m.mapBumpScale;
  7595. }
  7596. if ( m.mapNormalFactor ) {
  7597. mpars.normalScale = new THREE.Vector2( m.mapNormalFactor, m.mapNormalFactor );
  7598. }
  7599. var material = new THREE[ mtype ]( mpars );
  7600. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  7601. return material;
  7602. };
  7603. } )()
  7604. };
  7605. THREE.Loader.Handlers = {
  7606. handlers: [],
  7607. add: function ( regex, loader ) {
  7608. this.handlers.push( regex, loader );
  7609. },
  7610. get: function ( file ) {
  7611. for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
  7612. var regex = this.handlers[ i ];
  7613. var loader = this.handlers[ i + 1 ];
  7614. if ( regex.test( file ) ) {
  7615. return loader;
  7616. }
  7617. }
  7618. return null;
  7619. }
  7620. };
  7621. // File:src/loaders/XHRLoader.js
  7622. /**
  7623. * @author mrdoob / http://mrdoob.com/
  7624. */
  7625. THREE.XHRLoader = function ( manager ) {
  7626. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7627. };
  7628. THREE.XHRLoader.prototype = {
  7629. constructor: THREE.XHRLoader,
  7630. load: function ( url, onLoad, onProgress, onError ) {
  7631. var scope = this;
  7632. var cached = THREE.Cache.get( url );
  7633. if ( cached !== undefined ) {
  7634. if ( onLoad ) {
  7635. setTimeout( function () {
  7636. onLoad( cached );
  7637. }, 0 );
  7638. }
  7639. return cached;
  7640. }
  7641. var request = new XMLHttpRequest();
  7642. request.open( 'GET', url, true );
  7643. request.addEventListener( 'load', function ( event ) {
  7644. THREE.Cache.add( url, this.response );
  7645. if ( onLoad ) onLoad( this.response );
  7646. scope.manager.itemEnd( url );
  7647. }, false );
  7648. if ( onProgress !== undefined ) {
  7649. request.addEventListener( 'progress', function ( event ) {
  7650. onProgress( event );
  7651. }, false );
  7652. }
  7653. if ( onError !== undefined ) {
  7654. request.addEventListener( 'error', function ( event ) {
  7655. onError( event );
  7656. }, false );
  7657. }
  7658. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  7659. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  7660. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  7661. request.send( null );
  7662. scope.manager.itemStart( url );
  7663. return request;
  7664. },
  7665. setResponseType: function ( value ) {
  7666. this.responseType = value;
  7667. },
  7668. setCrossOrigin: function ( value ) {
  7669. this.crossOrigin = value;
  7670. },
  7671. setWithCredentials: function ( value ) {
  7672. this.withCredentials = value;
  7673. }
  7674. };
  7675. // File:src/loaders/ImageLoader.js
  7676. /**
  7677. * @author mrdoob / http://mrdoob.com/
  7678. */
  7679. THREE.ImageLoader = function ( manager ) {
  7680. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7681. };
  7682. THREE.ImageLoader.prototype = {
  7683. constructor: THREE.ImageLoader,
  7684. load: function ( url, onLoad, onProgress, onError ) {
  7685. var scope = this;
  7686. var cached = THREE.Cache.get( url );
  7687. if ( cached !== undefined ) {
  7688. if ( onLoad ) {
  7689. setTimeout( function () {
  7690. onLoad( cached );
  7691. }, 0 );
  7692. }
  7693. return cached;
  7694. }
  7695. var image = document.createElement( 'img' );
  7696. image.addEventListener( 'load', function ( event ) {
  7697. THREE.Cache.add( url, this );
  7698. if ( onLoad ) onLoad( this );
  7699. scope.manager.itemEnd( url );
  7700. }, false );
  7701. if ( onProgress !== undefined ) {
  7702. image.addEventListener( 'progress', function ( event ) {
  7703. onProgress( event );
  7704. }, false );
  7705. }
  7706. if ( onError !== undefined ) {
  7707. image.addEventListener( 'error', function ( event ) {
  7708. onError( event );
  7709. }, false );
  7710. }
  7711. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  7712. scope.manager.itemStart( url );
  7713. image.src = url;
  7714. return image;
  7715. },
  7716. setCrossOrigin: function ( value ) {
  7717. this.crossOrigin = value;
  7718. }
  7719. };
  7720. // File:src/loaders/JSONLoader.js
  7721. /**
  7722. * @author mrdoob / http://mrdoob.com/
  7723. * @author alteredq / http://alteredqualia.com/
  7724. */
  7725. THREE.JSONLoader = function ( manager ) {
  7726. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7727. this.withCredentials = false;
  7728. };
  7729. THREE.JSONLoader.prototype = {
  7730. constructor: THREE.JSONLoader,
  7731. load: function( url, onLoad, onProgress, onError ) {
  7732. var scope = this;
  7733. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  7734. var loader = new THREE.XHRLoader( this.manager );
  7735. loader.setCrossOrigin( this.crossOrigin );
  7736. loader.setWithCredentials( this.withCredentials );
  7737. loader.load( url, function ( text ) {
  7738. var json = JSON.parse( text );
  7739. var metadata = json.metadata;
  7740. if ( metadata !== undefined ) {
  7741. if ( metadata.type === 'object' ) {
  7742. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  7743. return;
  7744. }
  7745. if ( metadata.type === 'scene' ) {
  7746. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  7747. return;
  7748. }
  7749. }
  7750. var object = scope.parse( json, texturePath );
  7751. onLoad( object.geometry, object.materials );
  7752. } );
  7753. },
  7754. setCrossOrigin: function ( value ) {
  7755. this.crossOrigin = value;
  7756. },
  7757. setTexturePath: function ( value ) {
  7758. this.texturePath = value;
  7759. },
  7760. parse: function ( json, texturePath ) {
  7761. var geometry = new THREE.Geometry(),
  7762. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  7763. parseModel( scale );
  7764. parseSkin();
  7765. parseMorphing( scale );
  7766. geometry.computeFaceNormals();
  7767. geometry.computeBoundingSphere();
  7768. function parseModel( scale ) {
  7769. function isBitSet( value, position ) {
  7770. return value & ( 1 << position );
  7771. }
  7772. var i, j, fi,
  7773. offset, zLength,
  7774. colorIndex, normalIndex, uvIndex, materialIndex,
  7775. type,
  7776. isQuad,
  7777. hasMaterial,
  7778. hasFaceVertexUv,
  7779. hasFaceNormal, hasFaceVertexNormal,
  7780. hasFaceColor, hasFaceVertexColor,
  7781. vertex, face, faceA, faceB, hex, normal,
  7782. uvLayer, uv, u, v,
  7783. faces = json.faces,
  7784. vertices = json.vertices,
  7785. normals = json.normals,
  7786. colors = json.colors,
  7787. nUvLayers = 0;
  7788. if ( json.uvs !== undefined ) {
  7789. // disregard empty arrays
  7790. for ( i = 0; i < json.uvs.length; i ++ ) {
  7791. if ( json.uvs[ i ].length ) nUvLayers ++;
  7792. }
  7793. for ( i = 0; i < nUvLayers; i ++ ) {
  7794. geometry.faceVertexUvs[ i ] = [];
  7795. }
  7796. }
  7797. offset = 0;
  7798. zLength = vertices.length;
  7799. while ( offset < zLength ) {
  7800. vertex = new THREE.Vector3();
  7801. vertex.x = vertices[ offset ++ ] * scale;
  7802. vertex.y = vertices[ offset ++ ] * scale;
  7803. vertex.z = vertices[ offset ++ ] * scale;
  7804. geometry.vertices.push( vertex );
  7805. }
  7806. offset = 0;
  7807. zLength = faces.length;
  7808. while ( offset < zLength ) {
  7809. type = faces[ offset ++ ];
  7810. isQuad = isBitSet( type, 0 );
  7811. hasMaterial = isBitSet( type, 1 );
  7812. hasFaceVertexUv = isBitSet( type, 3 );
  7813. hasFaceNormal = isBitSet( type, 4 );
  7814. hasFaceVertexNormal = isBitSet( type, 5 );
  7815. hasFaceColor = isBitSet( type, 6 );
  7816. hasFaceVertexColor = isBitSet( type, 7 );
  7817. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  7818. if ( isQuad ) {
  7819. faceA = new THREE.Face3();
  7820. faceA.a = faces[ offset ];
  7821. faceA.b = faces[ offset + 1 ];
  7822. faceA.c = faces[ offset + 3 ];
  7823. faceB = new THREE.Face3();
  7824. faceB.a = faces[ offset + 1 ];
  7825. faceB.b = faces[ offset + 2 ];
  7826. faceB.c = faces[ offset + 3 ];
  7827. offset += 4;
  7828. if ( hasMaterial ) {
  7829. materialIndex = faces[ offset ++ ];
  7830. faceA.materialIndex = materialIndex;
  7831. faceB.materialIndex = materialIndex;
  7832. }
  7833. // to get face <=> uv index correspondence
  7834. fi = geometry.faces.length;
  7835. if ( hasFaceVertexUv ) {
  7836. for ( i = 0; i < nUvLayers; i ++ ) {
  7837. uvLayer = json.uvs[ i ];
  7838. geometry.faceVertexUvs[ i ][ fi ] = [];
  7839. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  7840. for ( j = 0; j < 4; j ++ ) {
  7841. uvIndex = faces[ offset ++ ];
  7842. u = uvLayer[ uvIndex * 2 ];
  7843. v = uvLayer[ uvIndex * 2 + 1 ];
  7844. uv = new THREE.Vector2( u, v );
  7845. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7846. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  7847. }
  7848. }
  7849. }
  7850. if ( hasFaceNormal ) {
  7851. normalIndex = faces[ offset ++ ] * 3;
  7852. faceA.normal.set(
  7853. normals[ normalIndex ++ ],
  7854. normals[ normalIndex ++ ],
  7855. normals[ normalIndex ]
  7856. );
  7857. faceB.normal.copy( faceA.normal );
  7858. }
  7859. if ( hasFaceVertexNormal ) {
  7860. for ( i = 0; i < 4; i ++ ) {
  7861. normalIndex = faces[ offset ++ ] * 3;
  7862. normal = new THREE.Vector3(
  7863. normals[ normalIndex ++ ],
  7864. normals[ normalIndex ++ ],
  7865. normals[ normalIndex ]
  7866. );
  7867. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  7868. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  7869. }
  7870. }
  7871. if ( hasFaceColor ) {
  7872. colorIndex = faces[ offset ++ ];
  7873. hex = colors[ colorIndex ];
  7874. faceA.color.setHex( hex );
  7875. faceB.color.setHex( hex );
  7876. }
  7877. if ( hasFaceVertexColor ) {
  7878. for ( i = 0; i < 4; i ++ ) {
  7879. colorIndex = faces[ offset ++ ];
  7880. hex = colors[ colorIndex ];
  7881. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  7882. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  7883. }
  7884. }
  7885. geometry.faces.push( faceA );
  7886. geometry.faces.push( faceB );
  7887. } else {
  7888. face = new THREE.Face3();
  7889. face.a = faces[ offset ++ ];
  7890. face.b = faces[ offset ++ ];
  7891. face.c = faces[ offset ++ ];
  7892. if ( hasMaterial ) {
  7893. materialIndex = faces[ offset ++ ];
  7894. face.materialIndex = materialIndex;
  7895. }
  7896. // to get face <=> uv index correspondence
  7897. fi = geometry.faces.length;
  7898. if ( hasFaceVertexUv ) {
  7899. for ( i = 0; i < nUvLayers; i ++ ) {
  7900. uvLayer = json.uvs[ i ];
  7901. geometry.faceVertexUvs[ i ][ fi ] = [];
  7902. for ( j = 0; j < 3; j ++ ) {
  7903. uvIndex = faces[ offset ++ ];
  7904. u = uvLayer[ uvIndex * 2 ];
  7905. v = uvLayer[ uvIndex * 2 + 1 ];
  7906. uv = new THREE.Vector2( u, v );
  7907. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7908. }
  7909. }
  7910. }
  7911. if ( hasFaceNormal ) {
  7912. normalIndex = faces[ offset ++ ] * 3;
  7913. face.normal.set(
  7914. normals[ normalIndex ++ ],
  7915. normals[ normalIndex ++ ],
  7916. normals[ normalIndex ]
  7917. );
  7918. }
  7919. if ( hasFaceVertexNormal ) {
  7920. for ( i = 0; i < 3; i ++ ) {
  7921. normalIndex = faces[ offset ++ ] * 3;
  7922. normal = new THREE.Vector3(
  7923. normals[ normalIndex ++ ],
  7924. normals[ normalIndex ++ ],
  7925. normals[ normalIndex ]
  7926. );
  7927. face.vertexNormals.push( normal );
  7928. }
  7929. }
  7930. if ( hasFaceColor ) {
  7931. colorIndex = faces[ offset ++ ];
  7932. face.color.setHex( colors[ colorIndex ] );
  7933. }
  7934. if ( hasFaceVertexColor ) {
  7935. for ( i = 0; i < 3; i ++ ) {
  7936. colorIndex = faces[ offset ++ ];
  7937. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  7938. }
  7939. }
  7940. geometry.faces.push( face );
  7941. }
  7942. }
  7943. };
  7944. function parseSkin() {
  7945. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  7946. if ( json.skinWeights ) {
  7947. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  7948. var x = json.skinWeights[ i ];
  7949. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  7950. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  7951. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  7952. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  7953. }
  7954. }
  7955. if ( json.skinIndices ) {
  7956. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  7957. var a = json.skinIndices[ i ];
  7958. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  7959. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  7960. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  7961. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  7962. }
  7963. }
  7964. geometry.bones = json.bones;
  7965. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  7966. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  7967. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  7968. }
  7969. // could change this to json.animations[0] or remove completely
  7970. geometry.animation = json.animation;
  7971. geometry.animations = json.animations;
  7972. };
  7973. function parseMorphing( scale ) {
  7974. if ( json.morphTargets !== undefined ) {
  7975. var i, l, v, vl, dstVertices, srcVertices;
  7976. for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  7977. geometry.morphTargets[ i ] = {};
  7978. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  7979. geometry.morphTargets[ i ].vertices = [];
  7980. dstVertices = geometry.morphTargets[ i ].vertices;
  7981. srcVertices = json.morphTargets[ i ].vertices;
  7982. for ( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  7983. var vertex = new THREE.Vector3();
  7984. vertex.x = srcVertices[ v ] * scale;
  7985. vertex.y = srcVertices[ v + 1 ] * scale;
  7986. vertex.z = srcVertices[ v + 2 ] * scale;
  7987. dstVertices.push( vertex );
  7988. }
  7989. }
  7990. }
  7991. if ( json.morphColors !== undefined ) {
  7992. var i, l, c, cl, dstColors, srcColors, color;
  7993. for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
  7994. geometry.morphColors[ i ] = {};
  7995. geometry.morphColors[ i ].name = json.morphColors[ i ].name;
  7996. geometry.morphColors[ i ].colors = [];
  7997. dstColors = geometry.morphColors[ i ].colors;
  7998. srcColors = json.morphColors[ i ].colors;
  7999. for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
  8000. color = new THREE.Color( 0xffaa00 );
  8001. color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
  8002. dstColors.push( color );
  8003. }
  8004. }
  8005. }
  8006. };
  8007. if ( json.materials === undefined || json.materials.length === 0 ) {
  8008. return { geometry: geometry };
  8009. } else {
  8010. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  8011. if ( THREE.Loader.prototype.needsTangents( materials ) ) {
  8012. geometry.computeTangents();
  8013. }
  8014. return { geometry: geometry, materials: materials };
  8015. }
  8016. }
  8017. };
  8018. // File:src/loaders/LoadingManager.js
  8019. /**
  8020. * @author mrdoob / http://mrdoob.com/
  8021. */
  8022. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  8023. var scope = this;
  8024. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  8025. this.onLoad = onLoad;
  8026. this.onProgress = onProgress;
  8027. this.onError = onError;
  8028. this.itemStart = function ( url ) {
  8029. itemsTotal ++;
  8030. if ( isLoading === false ) {
  8031. if ( scope.onStart !== undefined ) {
  8032. scope.onStart( url, itemsLoaded, itemsTotal );
  8033. }
  8034. }
  8035. isLoading = true;
  8036. };
  8037. this.itemEnd = function ( url ) {
  8038. itemsLoaded ++;
  8039. if ( scope.onProgress !== undefined ) {
  8040. scope.onProgress( url, itemsLoaded, itemsTotal );
  8041. }
  8042. if ( itemsLoaded === itemsTotal ) {
  8043. isLoading = false;
  8044. if ( scope.onLoad !== undefined ) {
  8045. scope.onLoad();
  8046. }
  8047. }
  8048. };
  8049. };
  8050. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  8051. // File:src/loaders/BufferGeometryLoader.js
  8052. /**
  8053. * @author mrdoob / http://mrdoob.com/
  8054. */
  8055. THREE.BufferGeometryLoader = function ( manager ) {
  8056. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8057. };
  8058. THREE.BufferGeometryLoader.prototype = {
  8059. constructor: THREE.BufferGeometryLoader,
  8060. load: function ( url, onLoad, onProgress, onError ) {
  8061. var scope = this;
  8062. var loader = new THREE.XHRLoader( scope.manager );
  8063. loader.setCrossOrigin( this.crossOrigin );
  8064. loader.load( url, function ( text ) {
  8065. onLoad( scope.parse( JSON.parse( text ) ) );
  8066. }, onProgress, onError );
  8067. },
  8068. setCrossOrigin: function ( value ) {
  8069. this.crossOrigin = value;
  8070. },
  8071. parse: function ( json ) {
  8072. var geometry = new THREE.BufferGeometry();
  8073. var attributes = json.data.attributes;
  8074. for ( var key in attributes ) {
  8075. var attribute = attributes[ key ];
  8076. var typedArray = new self[ attribute.type ]( attribute.array );
  8077. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  8078. }
  8079. var drawcalls = json.data.drawcalls || json.data.offsets;
  8080. if ( drawcalls !== undefined ) {
  8081. for ( var i = 0, n = drawcalls.length; i !== n; ++ i ) {
  8082. var drawcall = drawcalls[ i ];
  8083. var indexStart = drawcall.start;
  8084. var indexCount = drawcall.count;
  8085. var indexOffset = drawcall.index;
  8086. geometry.addDrawcall( indexStart, indexCount, indexOffset );
  8087. }
  8088. }
  8089. var boundingSphere = json.data.boundingSphere;
  8090. if ( boundingSphere !== undefined ) {
  8091. var center = new THREE.Vector3();
  8092. if ( boundingSphere.center !== undefined ) {
  8093. center.fromArray( boundingSphere.center );
  8094. }
  8095. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  8096. }
  8097. return geometry;
  8098. }
  8099. };
  8100. // File:src/loaders/MaterialLoader.js
  8101. /**
  8102. * @author mrdoob / http://mrdoob.com/
  8103. */
  8104. THREE.MaterialLoader = function ( manager ) {
  8105. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8106. };
  8107. THREE.MaterialLoader.prototype = {
  8108. constructor: THREE.MaterialLoader,
  8109. load: function ( url, onLoad, onProgress, onError ) {
  8110. var scope = this;
  8111. var loader = new THREE.XHRLoader( scope.manager );
  8112. loader.setCrossOrigin( this.crossOrigin );
  8113. loader.load( url, function ( text ) {
  8114. onLoad( scope.parse( JSON.parse( text ) ) );
  8115. }, onProgress, onError );
  8116. },
  8117. setCrossOrigin: function ( value ) {
  8118. this.crossOrigin = value;
  8119. },
  8120. parse: function ( json ) {
  8121. var material = new THREE[ json.type ];
  8122. if ( json.color !== undefined ) material.color.setHex( json.color );
  8123. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  8124. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  8125. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  8126. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  8127. if ( json.attributes !== undefined ) material.attributes = json.attributes;
  8128. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  8129. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  8130. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  8131. if ( json.shading !== undefined ) material.shading = json.shading;
  8132. if ( json.blending !== undefined ) material.blending = json.blending;
  8133. if ( json.side !== undefined ) material.side = json.side;
  8134. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  8135. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  8136. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  8137. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  8138. // for PointCloudMaterial
  8139. if ( json.size !== undefined ) material.size = json.size;
  8140. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  8141. if ( json.materials !== undefined ) {
  8142. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  8143. material.materials.push( this.parse( json.materials[ i ] ) );
  8144. }
  8145. }
  8146. return material;
  8147. }
  8148. };
  8149. // File:src/loaders/ObjectLoader.js
  8150. /**
  8151. * @author mrdoob / http://mrdoob.com/
  8152. */
  8153. THREE.ObjectLoader = function ( manager ) {
  8154. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8155. this.texturePath = '';
  8156. };
  8157. THREE.ObjectLoader.prototype = {
  8158. constructor: THREE.ObjectLoader,
  8159. load: function ( url, onLoad, onProgress, onError ) {
  8160. if ( this.texturePath === '' ) {
  8161. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  8162. }
  8163. var scope = this;
  8164. var loader = new THREE.XHRLoader( scope.manager );
  8165. loader.setCrossOrigin( this.crossOrigin );
  8166. loader.load( url, function ( text ) {
  8167. scope.parse( JSON.parse( text ), onLoad );
  8168. }, onProgress, onError );
  8169. },
  8170. setTexturePath: function ( value ) {
  8171. this.texturePath = value;
  8172. },
  8173. setCrossOrigin: function ( value ) {
  8174. this.crossOrigin = value;
  8175. },
  8176. parse: function ( json, onLoad ) {
  8177. var geometries = this.parseGeometries( json.geometries );
  8178. var images = this.parseImages( json.images, function () {
  8179. if ( onLoad !== undefined ) onLoad( object );
  8180. } );
  8181. var textures = this.parseTextures( json.textures, images );
  8182. var materials = this.parseMaterials( json.materials, textures );
  8183. var object = this.parseObject( json.object, geometries, materials );
  8184. if ( json.images === undefined || json.images.length === 0 ) {
  8185. if ( onLoad !== undefined ) onLoad( object );
  8186. }
  8187. return object;
  8188. },
  8189. parseGeometries: function ( json ) {
  8190. var geometries = {};
  8191. if ( json !== undefined ) {
  8192. var geometryLoader = new THREE.JSONLoader();
  8193. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  8194. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8195. var geometry;
  8196. var data = json[ i ];
  8197. switch ( data.type ) {
  8198. case 'PlaneGeometry':
  8199. case 'PlaneBufferGeometry':
  8200. geometry = new THREE[ data.type ](
  8201. data.width,
  8202. data.height,
  8203. data.widthSegments,
  8204. data.heightSegments
  8205. );
  8206. break;
  8207. case 'BoxGeometry':
  8208. case 'CubeGeometry': // backwards compatible
  8209. geometry = new THREE.BoxGeometry(
  8210. data.width,
  8211. data.height,
  8212. data.depth,
  8213. data.widthSegments,
  8214. data.heightSegments,
  8215. data.depthSegments
  8216. );
  8217. break;
  8218. case 'CircleBufferGeometry':
  8219. geometry = new THREE.CircleBufferGeometry(
  8220. data.radius,
  8221. data.segments,
  8222. data.thetaStart,
  8223. data.thetaLength
  8224. );
  8225. break;
  8226. case 'CircleGeometry':
  8227. geometry = new THREE.CircleGeometry(
  8228. data.radius,
  8229. data.segments,
  8230. data.thetaStart,
  8231. data.thetaLength
  8232. );
  8233. break;
  8234. case 'CylinderGeometry':
  8235. geometry = new THREE.CylinderGeometry(
  8236. data.radiusTop,
  8237. data.radiusBottom,
  8238. data.height,
  8239. data.radialSegments,
  8240. data.heightSegments,
  8241. data.openEnded,
  8242. data.thetaStart,
  8243. data.thetaLength
  8244. );
  8245. break;
  8246. case 'SphereGeometry':
  8247. geometry = new THREE.SphereGeometry(
  8248. data.radius,
  8249. data.widthSegments,
  8250. data.heightSegments,
  8251. data.phiStart,
  8252. data.phiLength,
  8253. data.thetaStart,
  8254. data.thetaLength
  8255. );
  8256. break;
  8257. case 'SphereBufferGeometry':
  8258. geometry = new THREE.SphereBufferGeometry(
  8259. data.radius,
  8260. data.widthSegments,
  8261. data.heightSegments,
  8262. data.phiStart,
  8263. data.phiLength,
  8264. data.thetaStart,
  8265. data.thetaLength
  8266. );
  8267. break;
  8268. case 'DodecahedronGeometry':
  8269. geometry = new THREE.DodecahedronGeometry(
  8270. data.radius,
  8271. data.detail
  8272. );
  8273. break;
  8274. case 'IcosahedronGeometry':
  8275. geometry = new THREE.IcosahedronGeometry(
  8276. data.radius,
  8277. data.detail
  8278. );
  8279. break;
  8280. case 'OctahedronGeometry':
  8281. geometry = new THREE.OctahedronGeometry(
  8282. data.radius,
  8283. data.detail
  8284. );
  8285. break;
  8286. case 'TetrahedronGeometry':
  8287. geometry = new THREE.TetrahedronGeometry(
  8288. data.radius,
  8289. data.detail
  8290. );
  8291. break;
  8292. case 'RingGeometry':
  8293. geometry = new THREE.RingGeometry(
  8294. data.innerRadius,
  8295. data.outerRadius,
  8296. data.thetaSegments,
  8297. data.phiSegments,
  8298. data.thetaStart,
  8299. data.thetaLength
  8300. );
  8301. break;
  8302. case 'TorusGeometry':
  8303. geometry = new THREE.TorusGeometry(
  8304. data.radius,
  8305. data.tube,
  8306. data.radialSegments,
  8307. data.tubularSegments,
  8308. data.arc
  8309. );
  8310. break;
  8311. case 'TorusKnotGeometry':
  8312. geometry = new THREE.TorusKnotGeometry(
  8313. data.radius,
  8314. data.tube,
  8315. data.radialSegments,
  8316. data.tubularSegments,
  8317. data.p,
  8318. data.q,
  8319. data.heightScale
  8320. );
  8321. break;
  8322. case 'BufferGeometry':
  8323. geometry = bufferGeometryLoader.parse( data );
  8324. break;
  8325. case 'Geometry':
  8326. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  8327. break;
  8328. case 'TextGeometry':
  8329. geometry = new THREE.TextGeometry(
  8330. data.text,
  8331. data.data
  8332. );
  8333. break;
  8334. }
  8335. geometry.uuid = data.uuid;
  8336. if ( data.name !== undefined ) geometry.name = data.name;
  8337. geometries[ data.uuid ] = geometry;
  8338. }
  8339. }
  8340. return geometries;
  8341. },
  8342. parseMaterials: function ( json, textures ) {
  8343. var materials = {};
  8344. if ( json !== undefined ) {
  8345. var getTexture = function ( name ) {
  8346. if ( textures[ name ] === undefined ) {
  8347. console.warn( 'THREE.ObjectLoader: Undefined texture', name );
  8348. }
  8349. return textures[ name ];
  8350. };
  8351. var loader = new THREE.MaterialLoader();
  8352. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8353. var data = json[ i ];
  8354. var material = loader.parse( data );
  8355. material.uuid = data.uuid;
  8356. if ( data.depthTest !== undefined ) material.depthTest = data.depthTest;
  8357. if ( data.depthWrite !== undefined ) material.depthWrite = data.depthWrite;
  8358. if ( data.name !== undefined ) material.name = data.name;
  8359. if ( data.map !== undefined ) material.map = getTexture( data.map );
  8360. if ( data.alphaMap !== undefined ) {
  8361. material.alphaMap = getTexture( data.alphaMap );
  8362. material.transparent = true;
  8363. }
  8364. if ( data.bumpMap !== undefined ) material.bumpMap = getTexture( data.bumpMap );
  8365. if ( data.bumpScale !== undefined ) material.bumpScale = data.bumpScale;
  8366. if ( data.normalMap !== undefined ) material.normalMap = getTexture( data.normalMap );
  8367. if ( data.normalScale ) material.normalScale = new THREE.Vector2( data.normalScale, data.normalScale );
  8368. if ( data.specularMap !== undefined ) material.specularMap = getTexture( data.specularMap );
  8369. if ( data.envMap !== undefined ) {
  8370. material.envMap = getTexture( data.envMap );
  8371. material.combine = THREE.MultiplyOperation;
  8372. }
  8373. if ( data.reflectivity ) material.reflectivity = data.reflectivity;
  8374. if ( data.lightMap !== undefined ) material.lightMap = getTexture( data.lightMap );
  8375. if ( data.lightMapIntensity !== undefined ) material.lightMapIntensity = data.lightMapIntensity;
  8376. if ( data.aoMap !== undefined ) material.aoMap = getTexture( data.aoMap );
  8377. if ( data.aoMapIntensity !== undefined ) material.aoMapIntensity = data.aoMapIntensity;
  8378. materials[ data.uuid ] = material;
  8379. }
  8380. }
  8381. return materials;
  8382. },
  8383. parseImages: function ( json, onLoad ) {
  8384. var scope = this;
  8385. var images = {};
  8386. if ( json !== undefined && json.length > 0 ) {
  8387. var manager = new THREE.LoadingManager( onLoad );
  8388. var loader = new THREE.ImageLoader( manager );
  8389. loader.setCrossOrigin( this.crossOrigin );
  8390. var loadImage = function ( url ) {
  8391. url = scope.texturePath + url;
  8392. scope.manager.itemStart( url );
  8393. return loader.load( url, function () {
  8394. scope.manager.itemEnd( url );
  8395. } );
  8396. };
  8397. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8398. var image = json[ i ];
  8399. images[ image.uuid ] = loadImage( image.url );
  8400. }
  8401. }
  8402. return images;
  8403. },
  8404. parseTextures: function ( json, images ) {
  8405. function parseConstant( value ) {
  8406. if ( typeof( value ) === 'number' ) return value;
  8407. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  8408. return THREE[ value ];
  8409. }
  8410. var textures = {};
  8411. if ( json !== undefined ) {
  8412. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8413. var data = json[ i ];
  8414. if ( data.image === undefined ) {
  8415. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  8416. }
  8417. if ( images[ data.image ] === undefined ) {
  8418. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  8419. }
  8420. var texture = new THREE.Texture( images[ data.image ] );
  8421. texture.needsUpdate = true;
  8422. texture.uuid = data.uuid;
  8423. if ( data.name !== undefined ) texture.name = data.name;
  8424. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  8425. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  8426. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  8427. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  8428. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  8429. if ( Array.isArray( data.wrap ) ) {
  8430. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  8431. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  8432. }
  8433. textures[ data.uuid ] = texture;
  8434. }
  8435. }
  8436. return textures;
  8437. },
  8438. parseObject: function () {
  8439. var matrix = new THREE.Matrix4();
  8440. return function ( data, geometries, materials ) {
  8441. var object;
  8442. var getGeometry = function ( name ) {
  8443. if ( geometries[ name ] === undefined ) {
  8444. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  8445. }
  8446. return geometries[ name ];
  8447. };
  8448. var getMaterial = function ( name ) {
  8449. if ( materials[ name ] === undefined ) {
  8450. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  8451. }
  8452. return materials[ name ];
  8453. };
  8454. switch ( data.type ) {
  8455. case 'Scene':
  8456. object = new THREE.Scene();
  8457. break;
  8458. case 'PerspectiveCamera':
  8459. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  8460. break;
  8461. case 'OrthographicCamera':
  8462. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  8463. break;
  8464. case 'AmbientLight':
  8465. object = new THREE.AmbientLight( data.color );
  8466. break;
  8467. case 'DirectionalLight':
  8468. object = new THREE.DirectionalLight( data.color, data.intensity );
  8469. break;
  8470. case 'PointLight':
  8471. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  8472. break;
  8473. case 'SpotLight':
  8474. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  8475. break;
  8476. case 'HemisphereLight':
  8477. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  8478. break;
  8479. case 'Mesh':
  8480. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  8481. break;
  8482. case 'Line':
  8483. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  8484. break;
  8485. case 'PointCloud':
  8486. object = new THREE.PointCloud( getGeometry( data.geometry ), getMaterial( data.material ) );
  8487. break;
  8488. case 'Sprite':
  8489. object = new THREE.Sprite( getMaterial( data.material ) );
  8490. break;
  8491. case 'Group':
  8492. object = new THREE.Group();
  8493. break;
  8494. default:
  8495. object = new THREE.Object3D();
  8496. }
  8497. object.uuid = data.uuid;
  8498. if ( data.name !== undefined ) object.name = data.name;
  8499. if ( data.matrix !== undefined ) {
  8500. matrix.fromArray( data.matrix );
  8501. matrix.decompose( object.position, object.quaternion, object.scale );
  8502. } else {
  8503. if ( data.position !== undefined ) object.position.fromArray( data.position );
  8504. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  8505. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  8506. }
  8507. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  8508. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  8509. if ( data.visible !== undefined ) object.visible = data.visible;
  8510. if ( data.userData !== undefined ) object.userData = data.userData;
  8511. if ( data.children !== undefined ) {
  8512. for ( var child in data.children ) {
  8513. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  8514. }
  8515. }
  8516. return object;
  8517. }
  8518. }()
  8519. };
  8520. // File:src/loaders/TextureLoader.js
  8521. /**
  8522. * @author mrdoob / http://mrdoob.com/
  8523. */
  8524. THREE.TextureLoader = function ( manager ) {
  8525. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8526. };
  8527. THREE.TextureLoader.prototype = {
  8528. constructor: THREE.TextureLoader,
  8529. load: function ( url, onLoad, onProgress, onError ) {
  8530. var scope = this;
  8531. var loader = new THREE.ImageLoader( scope.manager );
  8532. loader.setCrossOrigin( this.crossOrigin );
  8533. loader.load( url, function ( image ) {
  8534. var texture = new THREE.Texture( image );
  8535. texture.needsUpdate = true;
  8536. if ( onLoad !== undefined ) {
  8537. onLoad( texture );
  8538. }
  8539. }, onProgress, onError );
  8540. },
  8541. setCrossOrigin: function ( value ) {
  8542. this.crossOrigin = value;
  8543. }
  8544. };
  8545. // File:src/loaders/BinaryTextureLoader.js
  8546. /**
  8547. * @author Nikos M. / https://github.com/foo123/
  8548. *
  8549. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  8550. */
  8551. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  8552. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8553. // override in sub classes
  8554. this._parser = null;
  8555. };
  8556. THREE.BinaryTextureLoader.prototype = {
  8557. constructor: THREE.BinaryTextureLoader,
  8558. load: function ( url, onLoad, onProgress, onError ) {
  8559. var scope = this;
  8560. var texture = new THREE.DataTexture( );
  8561. var loader = new THREE.XHRLoader( this.manager );
  8562. loader.setCrossOrigin( this.crossOrigin );
  8563. loader.setResponseType( 'arraybuffer' );
  8564. loader.load( url, function ( buffer ) {
  8565. var texData = scope._parser( buffer );
  8566. if ( ! texData ) return;
  8567. if ( undefined !== texData.image ) {
  8568. texture.image = texData.image;
  8569. } else if ( undefined !== texData.data ) {
  8570. texture.image.width = texData.width;
  8571. texture.image.height = texData.height;
  8572. texture.image.data = texData.data;
  8573. }
  8574. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  8575. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  8576. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  8577. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  8578. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  8579. if ( undefined !== texData.format ) {
  8580. texture.format = texData.format;
  8581. }
  8582. if ( undefined !== texData.type ) {
  8583. texture.type = texData.type;
  8584. }
  8585. if ( undefined !== texData.mipmaps ) {
  8586. texture.mipmaps = texData.mipmaps;
  8587. }
  8588. if ( 1 === texData.mipmapCount ) {
  8589. texture.minFilter = THREE.LinearFilter;
  8590. }
  8591. texture.needsUpdate = true;
  8592. if ( onLoad ) onLoad( texture, texData );
  8593. }, onProgress, onError );
  8594. return texture;
  8595. },
  8596. setCrossOrigin: function ( value ) {
  8597. this.crossOrigin = value;
  8598. }
  8599. };
  8600. // File:src/loaders/CompressedTextureLoader.js
  8601. /**
  8602. * @author mrdoob / http://mrdoob.com/
  8603. *
  8604. * Abstract Base class to block based textures loader (dds, pvr, ...)
  8605. */
  8606. THREE.CompressedTextureLoader = function ( manager ) {
  8607. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8608. // override in sub classes
  8609. this._parser = null;
  8610. };
  8611. THREE.CompressedTextureLoader.prototype = {
  8612. constructor: THREE.CompressedTextureLoader,
  8613. load: function ( url, onLoad, onProgress, onError ) {
  8614. var scope = this;
  8615. var images = [];
  8616. var texture = new THREE.CompressedTexture();
  8617. texture.image = images;
  8618. var loader = new THREE.XHRLoader( this.manager );
  8619. loader.setCrossOrigin( this.crossOrigin );
  8620. loader.setResponseType( 'arraybuffer' );
  8621. if ( Array.isArray( url ) ) {
  8622. var loaded = 0;
  8623. var loadTexture = function ( i ) {
  8624. loader.load( url[ i ], function ( buffer ) {
  8625. var texDatas = scope._parser( buffer, true );
  8626. images[ i ] = {
  8627. width: texDatas.width,
  8628. height: texDatas.height,
  8629. format: texDatas.format,
  8630. mipmaps: texDatas.mipmaps
  8631. };
  8632. loaded += 1;
  8633. if ( loaded === 6 ) {
  8634. if ( texDatas.mipmapCount === 1 )
  8635. texture.minFilter = THREE.LinearFilter;
  8636. texture.format = texDatas.format;
  8637. texture.needsUpdate = true;
  8638. if ( onLoad ) onLoad( texture );
  8639. }
  8640. }, onProgress, onError );
  8641. };
  8642. for ( var i = 0, il = url.length; i < il; ++ i ) {
  8643. loadTexture( i );
  8644. }
  8645. } else {
  8646. // compressed cubemap texture stored in a single DDS file
  8647. loader.load( url, function ( buffer ) {
  8648. var texDatas = scope._parser( buffer, true );
  8649. if ( texDatas.isCubemap ) {
  8650. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  8651. for ( var f = 0; f < faces; f ++ ) {
  8652. images[ f ] = { mipmaps : [] };
  8653. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  8654. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  8655. images[ f ].format = texDatas.format;
  8656. images[ f ].width = texDatas.width;
  8657. images[ f ].height = texDatas.height;
  8658. }
  8659. }
  8660. } else {
  8661. texture.image.width = texDatas.width;
  8662. texture.image.height = texDatas.height;
  8663. texture.mipmaps = texDatas.mipmaps;
  8664. }
  8665. if ( texDatas.mipmapCount === 1 ) {
  8666. texture.minFilter = THREE.LinearFilter;
  8667. }
  8668. texture.format = texDatas.format;
  8669. texture.needsUpdate = true;
  8670. if ( onLoad ) onLoad( texture );
  8671. }, onProgress, onError );
  8672. }
  8673. return texture;
  8674. },
  8675. setCrossOrigin: function ( value ) {
  8676. this.crossOrigin = value;
  8677. }
  8678. };
  8679. // File:src/materials/Material.js
  8680. /**
  8681. * @author mrdoob / http://mrdoob.com/
  8682. * @author alteredq / http://alteredqualia.com/
  8683. */
  8684. THREE.Material = function () {
  8685. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  8686. this.uuid = THREE.Math.generateUUID();
  8687. this.name = '';
  8688. this.type = 'Material';
  8689. this.side = THREE.FrontSide;
  8690. this.opacity = 1;
  8691. this.transparent = false;
  8692. this.blending = THREE.NormalBlending;
  8693. this.blendSrc = THREE.SrcAlphaFactor;
  8694. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  8695. this.blendEquation = THREE.AddEquation;
  8696. this.blendSrcAlpha = null;
  8697. this.blendDstAlpha = null;
  8698. this.blendEquationAlpha = null;
  8699. this.depthFunc = THREE.LessEqualDepth;
  8700. this.depthTest = true;
  8701. this.depthWrite = true;
  8702. this.colorWrite = true;
  8703. this.polygonOffset = false;
  8704. this.polygonOffsetFactor = 0;
  8705. this.polygonOffsetUnits = 0;
  8706. this.alphaTest = 0;
  8707. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  8708. this.visible = true;
  8709. this._needsUpdate = true;
  8710. };
  8711. THREE.Material.prototype = {
  8712. constructor: THREE.Material,
  8713. get needsUpdate () {
  8714. return this._needsUpdate;
  8715. },
  8716. set needsUpdate ( value ) {
  8717. if ( value === true ) this.update();
  8718. this._needsUpdate = value;
  8719. },
  8720. setValues: function ( values ) {
  8721. if ( values === undefined ) return;
  8722. for ( var key in values ) {
  8723. var newValue = values[ key ];
  8724. if ( newValue === undefined ) {
  8725. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  8726. continue;
  8727. }
  8728. if ( key in this ) {
  8729. var currentValue = this[ key ];
  8730. if ( currentValue instanceof THREE.Color ) {
  8731. currentValue.set( newValue );
  8732. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  8733. currentValue.copy( newValue );
  8734. } else if ( key === 'overdraw' ) {
  8735. // ensure overdraw is backwards-compatible with legacy boolean type
  8736. this[ key ] = Number( newValue );
  8737. } else {
  8738. this[ key ] = newValue;
  8739. }
  8740. }
  8741. }
  8742. },
  8743. toJSON: function ( meta ) {
  8744. var data = {
  8745. metadata: {
  8746. version: 4.4,
  8747. type: 'Material',
  8748. generator: 'Material.toJSON'
  8749. }
  8750. };
  8751. // standard Material serialization
  8752. data.uuid = this.uuid;
  8753. data.type = this.type;
  8754. if ( this.name !== '' ) data.name = this.name;
  8755. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  8756. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  8757. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  8758. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  8759. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  8760. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  8761. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  8762. if ( this.bumpMap instanceof THREE.Texture ) {
  8763. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  8764. data.bumpScale = this.bumpScale;
  8765. }
  8766. if ( this.normalMap instanceof THREE.Texture ) {
  8767. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  8768. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  8769. }
  8770. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  8771. if ( this.envMap instanceof THREE.Texture ) {
  8772. data.envMap = this.envMap.toJSON( meta ).uuid;
  8773. data.reflectivity = this.reflectivity; // Scale behind envMap
  8774. }
  8775. if ( this.size !== undefined ) data.size = this.size;
  8776. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  8777. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  8778. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  8779. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  8780. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  8781. if ( this.opacity < 1 ) data.opacity = this.opacity;
  8782. if ( this.transparent === true ) data.transparent = this.transparent;
  8783. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  8784. return data;
  8785. },
  8786. clone: function () {
  8787. return new THREE.Material().copy( this );
  8788. },
  8789. copy: function ( source ) {
  8790. this.name = source.name;
  8791. this.side = source.side;
  8792. this.opacity = source.opacity;
  8793. this.transparent = source.transparent;
  8794. this.blending = source.blending;
  8795. this.blendSrc = source.blendSrc;
  8796. this.blendDst = source.blendDst;
  8797. this.blendEquation = source.blendEquation;
  8798. this.blendSrcAlpha = source.blendSrcAlpha;
  8799. this.blendDstAlpha = source.blendDstAlpha;
  8800. this.blendEquationAlpha = source.blendEquationAlpha;
  8801. this.depthFunc = source.depthFunc;
  8802. this.depthTest = source.depthTest;
  8803. this.depthWrite = source.depthWrite;
  8804. this.polygonOffset = source.polygonOffset;
  8805. this.polygonOffsetFactor = source.polygonOffsetFactor;
  8806. this.polygonOffsetUnits = source.polygonOffsetUnits;
  8807. this.alphaTest = source.alphaTest;
  8808. this.overdraw = source.overdraw;
  8809. this.visible = source.visible;
  8810. return this;
  8811. },
  8812. update: function () {
  8813. this.dispatchEvent( { type: 'update' } );
  8814. },
  8815. dispose: function () {
  8816. this.dispatchEvent( { type: 'dispose' } );
  8817. }
  8818. };
  8819. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  8820. THREE.MaterialIdCount = 0;
  8821. // File:src/materials/LineBasicMaterial.js
  8822. /**
  8823. * @author mrdoob / http://mrdoob.com/
  8824. * @author alteredq / http://alteredqualia.com/
  8825. *
  8826. * parameters = {
  8827. * color: <hex>,
  8828. * opacity: <float>,
  8829. *
  8830. * blending: THREE.NormalBlending,
  8831. * depthTest: <bool>,
  8832. * depthWrite: <bool>,
  8833. *
  8834. * linewidth: <float>,
  8835. * linecap: "round",
  8836. * linejoin: "round",
  8837. *
  8838. * vertexColors: <bool>
  8839. *
  8840. * fog: <bool>
  8841. * }
  8842. */
  8843. THREE.LineBasicMaterial = function ( parameters ) {
  8844. THREE.Material.call( this );
  8845. this.type = 'LineBasicMaterial';
  8846. this.color = new THREE.Color( 0xffffff );
  8847. this.linewidth = 1;
  8848. this.linecap = 'round';
  8849. this.linejoin = 'round';
  8850. this.vertexColors = THREE.NoColors;
  8851. this.fog = true;
  8852. this.setValues( parameters );
  8853. };
  8854. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8855. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  8856. THREE.LineBasicMaterial.prototype.clone = function () {
  8857. var material = new THREE.LineBasicMaterial();
  8858. material.copy( this );
  8859. material.color.copy( this.color );
  8860. material.linewidth = this.linewidth;
  8861. material.linecap = this.linecap;
  8862. material.linejoin = this.linejoin;
  8863. material.vertexColors = this.vertexColors;
  8864. material.fog = this.fog;
  8865. return material;
  8866. };
  8867. // File:src/materials/LineDashedMaterial.js
  8868. /**
  8869. * @author alteredq / http://alteredqualia.com/
  8870. *
  8871. * parameters = {
  8872. * color: <hex>,
  8873. * opacity: <float>,
  8874. *
  8875. * blending: THREE.NormalBlending,
  8876. * depthTest: <bool>,
  8877. * depthWrite: <bool>,
  8878. *
  8879. * linewidth: <float>,
  8880. *
  8881. * scale: <float>,
  8882. * dashSize: <float>,
  8883. * gapSize: <float>,
  8884. *
  8885. * vertexColors: <bool>
  8886. *
  8887. * fog: <bool>
  8888. * }
  8889. */
  8890. THREE.LineDashedMaterial = function ( parameters ) {
  8891. THREE.Material.call( this );
  8892. this.type = 'LineDashedMaterial';
  8893. this.color = new THREE.Color( 0xffffff );
  8894. this.linewidth = 1;
  8895. this.scale = 1;
  8896. this.dashSize = 3;
  8897. this.gapSize = 1;
  8898. this.vertexColors = false;
  8899. this.fog = true;
  8900. this.setValues( parameters );
  8901. };
  8902. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  8903. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  8904. THREE.LineDashedMaterial.prototype.clone = function () {
  8905. var material = new THREE.LineDashedMaterial();
  8906. material.copy( this );
  8907. material.color.copy( this.color );
  8908. material.linewidth = this.linewidth;
  8909. material.scale = this.scale;
  8910. material.dashSize = this.dashSize;
  8911. material.gapSize = this.gapSize;
  8912. material.vertexColors = this.vertexColors;
  8913. material.fog = this.fog;
  8914. return material;
  8915. };
  8916. // File:src/materials/MeshBasicMaterial.js
  8917. /**
  8918. * @author mrdoob / http://mrdoob.com/
  8919. * @author alteredq / http://alteredqualia.com/
  8920. *
  8921. * parameters = {
  8922. * color: <hex>,
  8923. * opacity: <float>,
  8924. * map: new THREE.Texture( <Image> ),
  8925. *
  8926. * aoMap: new THREE.Texture( <Image> ),
  8927. * aoMapIntensity: <float>
  8928. *
  8929. * specularMap: new THREE.Texture( <Image> ),
  8930. *
  8931. * alphaMap: new THREE.Texture( <Image> ),
  8932. *
  8933. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8934. * combine: THREE.Multiply,
  8935. * reflectivity: <float>,
  8936. * refractionRatio: <float>,
  8937. *
  8938. * shading: THREE.SmoothShading,
  8939. * blending: THREE.NormalBlending,
  8940. * depthTest: <bool>,
  8941. * depthWrite: <bool>,
  8942. *
  8943. * wireframe: <boolean>,
  8944. * wireframeLinewidth: <float>,
  8945. *
  8946. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8947. *
  8948. * skinning: <bool>,
  8949. * morphTargets: <bool>,
  8950. *
  8951. * fog: <bool>
  8952. * }
  8953. */
  8954. THREE.MeshBasicMaterial = function ( parameters ) {
  8955. THREE.Material.call( this );
  8956. this.type = 'MeshBasicMaterial';
  8957. this.color = new THREE.Color( 0xffffff ); // emissive
  8958. this.map = null;
  8959. this.aoMap = null;
  8960. this.aoMapIntensity = 1.0;
  8961. this.specularMap = null;
  8962. this.alphaMap = null;
  8963. this.envMap = null;
  8964. this.combine = THREE.MultiplyOperation;
  8965. this.reflectivity = 1;
  8966. this.refractionRatio = 0.98;
  8967. this.fog = true;
  8968. this.shading = THREE.SmoothShading;
  8969. this.wireframe = false;
  8970. this.wireframeLinewidth = 1;
  8971. this.wireframeLinecap = 'round';
  8972. this.wireframeLinejoin = 'round';
  8973. this.vertexColors = THREE.NoColors;
  8974. this.skinning = false;
  8975. this.morphTargets = false;
  8976. this.setValues( parameters );
  8977. };
  8978. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8979. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  8980. THREE.MeshBasicMaterial.prototype.clone = function () {
  8981. var material = new THREE.MeshBasicMaterial();
  8982. material.copy( this );
  8983. material.color.copy( this.color );
  8984. material.map = this.map;
  8985. material.aoMap = this.aoMap;
  8986. material.aoMapIntensity = this.aoMapIntensity;
  8987. material.specularMap = this.specularMap;
  8988. material.alphaMap = this.alphaMap;
  8989. material.envMap = this.envMap;
  8990. material.combine = this.combine;
  8991. material.reflectivity = this.reflectivity;
  8992. material.refractionRatio = this.refractionRatio;
  8993. material.fog = this.fog;
  8994. material.shading = this.shading;
  8995. material.wireframe = this.wireframe;
  8996. material.wireframeLinewidth = this.wireframeLinewidth;
  8997. material.wireframeLinecap = this.wireframeLinecap;
  8998. material.wireframeLinejoin = this.wireframeLinejoin;
  8999. material.vertexColors = this.vertexColors;
  9000. material.skinning = this.skinning;
  9001. material.morphTargets = this.morphTargets;
  9002. return material;
  9003. };
  9004. // File:src/materials/MeshLambertMaterial.js
  9005. /**
  9006. * @author mrdoob / http://mrdoob.com/
  9007. * @author alteredq / http://alteredqualia.com/
  9008. *
  9009. * parameters = {
  9010. * color: <hex>,
  9011. * emissive: <hex>,
  9012. * opacity: <float>,
  9013. *
  9014. * map: new THREE.Texture( <Image> ),
  9015. *
  9016. * specularMap: new THREE.Texture( <Image> ),
  9017. *
  9018. * alphaMap: new THREE.Texture( <Image> ),
  9019. *
  9020. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  9021. * combine: THREE.Multiply,
  9022. * reflectivity: <float>,
  9023. * refractionRatio: <float>,
  9024. *
  9025. * shading: THREE.SmoothShading,
  9026. * blending: THREE.NormalBlending,
  9027. * depthTest: <bool>,
  9028. * depthWrite: <bool>,
  9029. *
  9030. * wireframe: <boolean>,
  9031. * wireframeLinewidth: <float>,
  9032. *
  9033. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9034. *
  9035. * skinning: <bool>,
  9036. * morphTargets: <bool>,
  9037. * morphNormals: <bool>,
  9038. *
  9039. * fog: <bool>
  9040. * }
  9041. */
  9042. THREE.MeshLambertMaterial = function ( parameters ) {
  9043. THREE.Material.call( this );
  9044. this.type = 'MeshLambertMaterial';
  9045. this.color = new THREE.Color( 0xffffff ); // diffuse
  9046. this.emissive = new THREE.Color( 0x000000 );
  9047. this.map = null;
  9048. this.specularMap = null;
  9049. this.alphaMap = null;
  9050. this.envMap = null;
  9051. this.combine = THREE.MultiplyOperation;
  9052. this.reflectivity = 1;
  9053. this.refractionRatio = 0.98;
  9054. this.fog = true;
  9055. this.shading = THREE.SmoothShading;
  9056. this.wireframe = false;
  9057. this.wireframeLinewidth = 1;
  9058. this.wireframeLinecap = 'round';
  9059. this.wireframeLinejoin = 'round';
  9060. this.vertexColors = THREE.NoColors;
  9061. this.skinning = false;
  9062. this.morphTargets = false;
  9063. this.morphNormals = false;
  9064. this.setValues( parameters );
  9065. };
  9066. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  9067. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  9068. THREE.MeshLambertMaterial.prototype.clone = function () {
  9069. var material = new THREE.MeshLambertMaterial();
  9070. material.copy( this );
  9071. material.color.copy( this.color );
  9072. material.emissive.copy( this.emissive );
  9073. material.map = this.map;
  9074. material.specularMap = this.specularMap;
  9075. material.alphaMap = this.alphaMap;
  9076. material.envMap = this.envMap;
  9077. material.combine = this.combine;
  9078. material.reflectivity = this.reflectivity;
  9079. material.refractionRatio = this.refractionRatio;
  9080. material.fog = this.fog;
  9081. material.shading = this.shading;
  9082. material.wireframe = this.wireframe;
  9083. material.wireframeLinewidth = this.wireframeLinewidth;
  9084. material.wireframeLinecap = this.wireframeLinecap;
  9085. material.wireframeLinejoin = this.wireframeLinejoin;
  9086. material.vertexColors = this.vertexColors;
  9087. material.skinning = this.skinning;
  9088. material.morphTargets = this.morphTargets;
  9089. material.morphNormals = this.morphNormals;
  9090. return material;
  9091. };
  9092. // File:src/materials/MeshPhongMaterial.js
  9093. /**
  9094. * @author mrdoob / http://mrdoob.com/
  9095. * @author alteredq / http://alteredqualia.com/
  9096. *
  9097. * parameters = {
  9098. * color: <hex>,
  9099. * emissive: <hex>,
  9100. * specular: <hex>,
  9101. * shininess: <float>,
  9102. * opacity: <float>,
  9103. *
  9104. * map: new THREE.Texture( <Image> ),
  9105. *
  9106. * lightMap: new THREE.Texture( <Image> ),
  9107. * lightMapIntensity: <float>
  9108. *
  9109. * aoMap: new THREE.Texture( <Image> ),
  9110. * aoMapIntensity: <float>
  9111. *
  9112. * emissiveMap: new THREE.Texture( <Image> ),
  9113. *
  9114. * bumpMap: new THREE.Texture( <Image> ),
  9115. * bumpScale: <float>,
  9116. *
  9117. * normalMap: new THREE.Texture( <Image> ),
  9118. * normalScale: <Vector2>,
  9119. *
  9120. * specularMap: new THREE.Texture( <Image> ),
  9121. *
  9122. * alphaMap: new THREE.Texture( <Image> ),
  9123. *
  9124. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  9125. * combine: THREE.Multiply,
  9126. * reflectivity: <float>,
  9127. * refractionRatio: <float>,
  9128. *
  9129. * shading: THREE.SmoothShading,
  9130. * blending: THREE.NormalBlending,
  9131. * depthTest: <bool>,
  9132. * depthWrite: <bool>,
  9133. *
  9134. * wireframe: <boolean>,
  9135. * wireframeLinewidth: <float>,
  9136. *
  9137. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9138. *
  9139. * skinning: <bool>,
  9140. * morphTargets: <bool>,
  9141. * morphNormals: <bool>,
  9142. *
  9143. * fog: <bool>
  9144. * }
  9145. */
  9146. THREE.MeshPhongMaterial = function ( parameters ) {
  9147. THREE.Material.call( this );
  9148. this.type = 'MeshPhongMaterial';
  9149. this.color = new THREE.Color( 0xffffff ); // diffuse
  9150. this.emissive = new THREE.Color( 0x000000 );
  9151. this.specular = new THREE.Color( 0x111111 );
  9152. this.shininess = 30;
  9153. this.metal = false;
  9154. this.map = null;
  9155. this.lightMap = null;
  9156. this.lightMapIntensity = 1.0;
  9157. this.aoMap = null;
  9158. this.aoMapIntensity = 1.0;
  9159. this.emissiveMap = null;
  9160. this.bumpMap = null;
  9161. this.bumpScale = 1;
  9162. this.normalMap = null;
  9163. this.normalScale = new THREE.Vector2( 1, 1 );
  9164. this.specularMap = null;
  9165. this.alphaMap = null;
  9166. this.envMap = null;
  9167. this.combine = THREE.MultiplyOperation;
  9168. this.reflectivity = 1;
  9169. this.refractionRatio = 0.98;
  9170. this.fog = true;
  9171. this.shading = THREE.SmoothShading;
  9172. this.wireframe = false;
  9173. this.wireframeLinewidth = 1;
  9174. this.wireframeLinecap = 'round';
  9175. this.wireframeLinejoin = 'round';
  9176. this.vertexColors = THREE.NoColors;
  9177. this.skinning = false;
  9178. this.morphTargets = false;
  9179. this.morphNormals = false;
  9180. this.setValues( parameters );
  9181. };
  9182. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  9183. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  9184. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  9185. THREE.Material.prototype.copy.call( this, source );
  9186. this.color.copy( source.color );
  9187. this.emissive.copy( source.emissive );
  9188. this.specular.copy( source.specular );
  9189. this.shininess = source.shininess;
  9190. this.metal = source.metal;
  9191. this.map = source.map;
  9192. this.lightMap = source.lightMap;
  9193. this.lightMapIntensity = source.lightMapIntensity;
  9194. this.aoMap = source.aoMap;
  9195. this.aoMapIntensity = source.aoMapIntensity;
  9196. this.emissiveMap = source.emissiveMap;
  9197. this.bumpMap = source.bumpMap;
  9198. this.bumpScale = source.bumpScale;
  9199. this.normalMap = source.normalMap;
  9200. this.normalScale.copy( source.normalScale );
  9201. this.specularMap = source.specularMap;
  9202. this.alphaMap = source.alphaMap;
  9203. this.envMap = source.envMap;
  9204. this.combine = source.combine;
  9205. this.reflectivity = source.reflectivity;
  9206. this.refractionRatio = source.refractionRatio;
  9207. this.fog = source.fog;
  9208. this.shading = source.shading;
  9209. this.wireframe = source.wireframe;
  9210. this.wireframeLinewidth = source.wireframeLinewidth;
  9211. this.wireframeLinecap = source.wireframeLinecap;
  9212. this.wireframeLinejoin = source.wireframeLinejoin;
  9213. this.vertexColors = source.vertexColors;
  9214. this.skinning = source.skinning;
  9215. this.morphTargets = source.morphTargets;
  9216. this.morphNormals = source.morphNormals;
  9217. return this;
  9218. };
  9219. THREE.MeshPhongMaterial.prototype.clone = function () {
  9220. return new THREE.MeshPhongMaterial().copy( this );
  9221. };
  9222. // File:src/materials/MeshDepthMaterial.js
  9223. /**
  9224. * @author mrdoob / http://mrdoob.com/
  9225. * @author alteredq / http://alteredqualia.com/
  9226. *
  9227. * parameters = {
  9228. * opacity: <float>,
  9229. *
  9230. * blending: THREE.NormalBlending,
  9231. * depthTest: <bool>,
  9232. * depthWrite: <bool>,
  9233. *
  9234. * wireframe: <boolean>,
  9235. * wireframeLinewidth: <float>
  9236. * }
  9237. */
  9238. THREE.MeshDepthMaterial = function ( parameters ) {
  9239. THREE.Material.call( this );
  9240. this.type = 'MeshDepthMaterial';
  9241. this.morphTargets = false;
  9242. this.wireframe = false;
  9243. this.wireframeLinewidth = 1;
  9244. this.setValues( parameters );
  9245. };
  9246. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  9247. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  9248. THREE.MeshDepthMaterial.prototype.clone = function () {
  9249. var material = new THREE.MeshDepthMaterial();
  9250. material.copy( this );
  9251. material.wireframe = this.wireframe;
  9252. material.wireframeLinewidth = this.wireframeLinewidth;
  9253. return material;
  9254. };
  9255. // File:src/materials/MeshNormalMaterial.js
  9256. /**
  9257. * @author mrdoob / http://mrdoob.com/
  9258. *
  9259. * parameters = {
  9260. * opacity: <float>,
  9261. *
  9262. * shading: THREE.FlatShading,
  9263. * blending: THREE.NormalBlending,
  9264. * depthTest: <bool>,
  9265. * depthWrite: <bool>,
  9266. *
  9267. * wireframe: <boolean>,
  9268. * wireframeLinewidth: <float>
  9269. * }
  9270. */
  9271. THREE.MeshNormalMaterial = function ( parameters ) {
  9272. THREE.Material.call( this, parameters );
  9273. this.type = 'MeshNormalMaterial';
  9274. this.wireframe = false;
  9275. this.wireframeLinewidth = 1;
  9276. this.morphTargets = false;
  9277. this.setValues( parameters );
  9278. };
  9279. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  9280. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  9281. THREE.MeshNormalMaterial.prototype.clone = function () {
  9282. var material = new THREE.MeshNormalMaterial();
  9283. material.copy( this );
  9284. material.wireframe = this.wireframe;
  9285. material.wireframeLinewidth = this.wireframeLinewidth;
  9286. return material;
  9287. };
  9288. // File:src/materials/MeshFaceMaterial.js
  9289. /**
  9290. * @author mrdoob / http://mrdoob.com/
  9291. */
  9292. THREE.MeshFaceMaterial = function ( materials ) {
  9293. this.uuid = THREE.Math.generateUUID();
  9294. this.type = 'MeshFaceMaterial';
  9295. this.materials = materials instanceof Array ? materials : [];
  9296. };
  9297. THREE.MeshFaceMaterial.prototype = {
  9298. constructor: THREE.MeshFaceMaterial,
  9299. toJSON: function () {
  9300. var output = {
  9301. metadata: {
  9302. version: 4.2,
  9303. type: 'material',
  9304. generator: 'MaterialExporter'
  9305. },
  9306. uuid: this.uuid,
  9307. type: this.type,
  9308. materials: []
  9309. };
  9310. for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
  9311. output.materials.push( this.materials[ i ].toJSON() );
  9312. }
  9313. return output;
  9314. },
  9315. clone: function () {
  9316. var material = new THREE.MeshFaceMaterial();
  9317. for ( var i = 0; i < this.materials.length; i ++ ) {
  9318. material.materials.push( this.materials[ i ].clone() );
  9319. }
  9320. return material;
  9321. }
  9322. };
  9323. // File:src/materials/PointCloudMaterial.js
  9324. /**
  9325. * @author mrdoob / http://mrdoob.com/
  9326. * @author alteredq / http://alteredqualia.com/
  9327. *
  9328. * parameters = {
  9329. * color: <hex>,
  9330. * opacity: <float>,
  9331. * map: new THREE.Texture( <Image> ),
  9332. *
  9333. * size: <float>,
  9334. * sizeAttenuation: <bool>,
  9335. *
  9336. * blending: THREE.NormalBlending,
  9337. * depthTest: <bool>,
  9338. * depthWrite: <bool>,
  9339. *
  9340. * vertexColors: <bool>,
  9341. *
  9342. * fog: <bool>
  9343. * }
  9344. */
  9345. THREE.PointCloudMaterial = function ( parameters ) {
  9346. THREE.Material.call( this );
  9347. this.type = 'PointCloudMaterial';
  9348. this.color = new THREE.Color( 0xffffff );
  9349. this.map = null;
  9350. this.size = 1;
  9351. this.sizeAttenuation = true;
  9352. this.vertexColors = THREE.NoColors;
  9353. this.fog = true;
  9354. this.setValues( parameters );
  9355. };
  9356. THREE.PointCloudMaterial.prototype = Object.create( THREE.Material.prototype );
  9357. THREE.PointCloudMaterial.prototype.constructor = THREE.PointCloudMaterial;
  9358. THREE.PointCloudMaterial.prototype.clone = function () {
  9359. var material = new THREE.PointCloudMaterial();
  9360. material.copy( this );
  9361. material.color.copy( this.color );
  9362. material.map = this.map;
  9363. material.size = this.size;
  9364. material.sizeAttenuation = this.sizeAttenuation;
  9365. material.vertexColors = this.vertexColors;
  9366. material.fog = this.fog;
  9367. return material;
  9368. };
  9369. // backwards compatibility
  9370. THREE.ParticleBasicMaterial = function ( parameters ) {
  9371. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointCloudMaterial.' );
  9372. return new THREE.PointCloudMaterial( parameters );
  9373. };
  9374. THREE.ParticleSystemMaterial = function ( parameters ) {
  9375. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointCloudMaterial.' );
  9376. return new THREE.PointCloudMaterial( parameters );
  9377. };
  9378. // File:src/materials/ShaderMaterial.js
  9379. /**
  9380. * @author alteredq / http://alteredqualia.com/
  9381. *
  9382. * parameters = {
  9383. * defines: { "label" : "value" },
  9384. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  9385. *
  9386. * fragmentShader: <string>,
  9387. * vertexShader: <string>,
  9388. *
  9389. * shading: THREE.SmoothShading,
  9390. * blending: THREE.NormalBlending,
  9391. * depthTest: <bool>,
  9392. * depthWrite: <bool>,
  9393. *
  9394. * wireframe: <boolean>,
  9395. * wireframeLinewidth: <float>,
  9396. *
  9397. * lights: <bool>,
  9398. *
  9399. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9400. *
  9401. * skinning: <bool>,
  9402. * morphTargets: <bool>,
  9403. * morphNormals: <bool>,
  9404. *
  9405. * fog: <bool>
  9406. * }
  9407. */
  9408. THREE.ShaderMaterial = function ( parameters ) {
  9409. THREE.Material.call( this );
  9410. this.type = 'ShaderMaterial';
  9411. this.defines = {};
  9412. this.uniforms = {};
  9413. this.attributes = [];
  9414. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  9415. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  9416. this.shading = THREE.SmoothShading;
  9417. this.linewidth = 1;
  9418. this.wireframe = false;
  9419. this.wireframeLinewidth = 1;
  9420. this.fog = false; // set to use scene fog
  9421. this.lights = false; // set to use scene lights
  9422. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  9423. this.skinning = false; // set to use skinning attribute streams
  9424. this.morphTargets = false; // set to use morph targets
  9425. this.morphNormals = false; // set to use morph normals
  9426. this.derivatives = false; // set to use derivatives
  9427. // When rendered geometry doesn't include these attributes but the material does,
  9428. // use these default values in WebGL. This avoids errors when buffer data is missing.
  9429. this.defaultAttributeValues = {
  9430. 'color': [ 1, 1, 1 ],
  9431. 'uv': [ 0, 0 ],
  9432. 'uv2': [ 0, 0 ]
  9433. };
  9434. this.index0AttributeName = undefined;
  9435. if ( parameters !== undefined ) {
  9436. if ( parameters.attributes !== undefined && Array.isArray( parameters.attributes ) === false ) {
  9437. console.warn( 'THREE.ShaderMaterial: attributes should now be an array of attribute names.' );
  9438. parameters.attributes = Object.keys( parameters.attributes );
  9439. }
  9440. this.setValues( parameters );
  9441. }
  9442. };
  9443. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  9444. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  9445. THREE.ShaderMaterial.prototype.clone = function () {
  9446. var material = new THREE.ShaderMaterial();
  9447. return material.copy( this );
  9448. };
  9449. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  9450. THREE.Material.prototype.copy.call( this, source );
  9451. this.fragmentShader = source.fragmentShader;
  9452. this.vertexShader = source.vertexShader;
  9453. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  9454. this.attributes = source.attributes;
  9455. this.defines = source.defines;
  9456. this.shading = source.shading;
  9457. this.wireframe = source.wireframe;
  9458. this.wireframeLinewidth = source.wireframeLinewidth;
  9459. this.fog = source.fog;
  9460. this.lights = source.lights;
  9461. this.vertexColors = source.vertexColors;
  9462. this.skinning = source.skinning;
  9463. this.morphTargets = source.morphTargets;
  9464. this.morphNormals = source.morphNormals;
  9465. return this;
  9466. };
  9467. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  9468. var data = THREE.Material.prototype.toJSON.call( this, meta );
  9469. data.uniforms = this.uniforms;
  9470. data.attributes = this.attributes;
  9471. data.vertexShader = this.vertexShader;
  9472. data.fragmentShader = this.fragmentShader;
  9473. return data;
  9474. };
  9475. // File:src/materials/RawShaderMaterial.js
  9476. /**
  9477. * @author mrdoob / http://mrdoob.com/
  9478. */
  9479. THREE.RawShaderMaterial = function ( parameters ) {
  9480. THREE.ShaderMaterial.call( this, parameters );
  9481. this.type = 'RawShaderMaterial';
  9482. };
  9483. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  9484. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  9485. THREE.RawShaderMaterial.prototype.clone = function () {
  9486. var material = new THREE.RawShaderMaterial();
  9487. material.copy( this );
  9488. return material;
  9489. };
  9490. // File:src/materials/SpriteMaterial.js
  9491. /**
  9492. * @author alteredq / http://alteredqualia.com/
  9493. *
  9494. * parameters = {
  9495. * color: <hex>,
  9496. * opacity: <float>,
  9497. * map: new THREE.Texture( <Image> ),
  9498. *
  9499. * blending: THREE.NormalBlending,
  9500. * depthTest: <bool>,
  9501. * depthWrite: <bool>,
  9502. *
  9503. * uvOffset: new THREE.Vector2(),
  9504. * uvScale: new THREE.Vector2(),
  9505. *
  9506. * fog: <bool>
  9507. * }
  9508. */
  9509. THREE.SpriteMaterial = function ( parameters ) {
  9510. THREE.Material.call( this );
  9511. this.type = 'SpriteMaterial';
  9512. this.color = new THREE.Color( 0xffffff );
  9513. this.map = null;
  9514. this.rotation = 0;
  9515. this.fog = false;
  9516. // set parameters
  9517. this.setValues( parameters );
  9518. };
  9519. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  9520. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  9521. THREE.SpriteMaterial.prototype.clone = function () {
  9522. var material = new THREE.SpriteMaterial();
  9523. material.copy( this );
  9524. material.color.copy( this.color );
  9525. material.map = this.map;
  9526. material.rotation = this.rotation;
  9527. material.fog = this.fog;
  9528. return material;
  9529. };
  9530. // File:src/textures/Texture.js
  9531. /**
  9532. * @author mrdoob / http://mrdoob.com/
  9533. * @author alteredq / http://alteredqualia.com/
  9534. * @author szimek / https://github.com/szimek/
  9535. */
  9536. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9537. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  9538. this.uuid = THREE.Math.generateUUID();
  9539. this.name = '';
  9540. this.sourceFile = '';
  9541. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  9542. this.mipmaps = [];
  9543. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  9544. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  9545. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  9546. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  9547. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  9548. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  9549. this.format = format !== undefined ? format : THREE.RGBAFormat;
  9550. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  9551. this.offset = new THREE.Vector2( 0, 0 );
  9552. this.repeat = new THREE.Vector2( 1, 1 );
  9553. this.generateMipmaps = true;
  9554. this.premultiplyAlpha = false;
  9555. this.flipY = true;
  9556. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  9557. this.version = 0;
  9558. this.onUpdate = null;
  9559. };
  9560. THREE.Texture.DEFAULT_IMAGE = undefined;
  9561. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  9562. THREE.Texture.prototype = {
  9563. constructor: THREE.Texture,
  9564. set needsUpdate ( value ) {
  9565. if ( value === true ) this.version ++;
  9566. },
  9567. clone: function () {
  9568. return new THREE.Texture().copy( this );
  9569. },
  9570. copy: function ( source ) {
  9571. this.image = source.image;
  9572. this.mipmaps = source.mipmaps.slice( 0 );
  9573. this.mapping = source.mapping;
  9574. this.wrapS = source.wrapS;
  9575. this.wrapT = source.wrapT;
  9576. this.magFilter = source.magFilter;
  9577. this.minFilter = source.minFilter;
  9578. this.anisotropy = source.anisotropy;
  9579. this.format = source.format;
  9580. this.type = source.type;
  9581. this.offset.copy( source.offset );
  9582. this.repeat.copy( source.repeat );
  9583. this.generateMipmaps = source.generateMipmaps;
  9584. this.premultiplyAlpha = source.premultiplyAlpha;
  9585. this.flipY = source.flipY;
  9586. this.unpackAlignment = source.unpackAlignment;
  9587. return this;
  9588. },
  9589. toJSON: function ( meta ) {
  9590. if ( meta.textures[ this.uuid ] !== undefined ) {
  9591. return meta.textures[ this.uuid ];
  9592. }
  9593. function getDataURL( image ) {
  9594. var canvas;
  9595. if ( image.toDataURL !== undefined ) {
  9596. canvas = image;
  9597. } else {
  9598. canvas = document.createElement( 'canvas' );
  9599. canvas.width = image.width;
  9600. canvas.height = image.height;
  9601. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  9602. }
  9603. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  9604. return canvas.toDataURL( 'image/jpeg', 0.6 );
  9605. } else {
  9606. return canvas.toDataURL( 'image/png' );
  9607. }
  9608. }
  9609. var output = {
  9610. metadata: {
  9611. version: 4.4,
  9612. type: 'Texture',
  9613. generator: 'Texture.toJSON'
  9614. },
  9615. uuid: this.uuid,
  9616. name: this.name,
  9617. mapping: this.mapping,
  9618. repeat: [ this.repeat.x, this.repeat.y ],
  9619. offset: [ this.offset.x, this.offset.y ],
  9620. wrap: [ this.wrapS, this.wrapT ],
  9621. minFilter: this.minFilter,
  9622. magFilter: this.magFilter,
  9623. anisotropy: this.anisotropy
  9624. };
  9625. if ( this.image !== undefined ) {
  9626. // TODO: Move to THREE.Image
  9627. var image = this.image;
  9628. if ( image.uuid === undefined ) {
  9629. image.uuid = THREE.Math.generateUUID(); // UGH
  9630. }
  9631. if ( meta.images[ image.uuid ] === undefined ) {
  9632. meta.images[ image.uuid ] = {
  9633. uuid: image.uuid,
  9634. url: getDataURL( image )
  9635. };
  9636. }
  9637. output.image = image.uuid;
  9638. }
  9639. meta.textures[ this.uuid ] = output;
  9640. return output;
  9641. },
  9642. dispose: function () {
  9643. this.dispatchEvent( { type: 'dispose' } );
  9644. }
  9645. };
  9646. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  9647. THREE.TextureIdCount = 0;
  9648. // File:src/textures/CubeTexture.js
  9649. /**
  9650. * @author mrdoob / http://mrdoob.com/
  9651. */
  9652. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9653. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  9654. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9655. this.images = images;
  9656. this.flipY = false;
  9657. };
  9658. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  9659. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  9660. THREE.CubeTexture.clone = function () {
  9661. var texture = new THREE.CubeTexture();
  9662. texture.copy( this );
  9663. texture.images = this.images;
  9664. return texture;
  9665. };
  9666. // File:src/textures/CompressedTexture.js
  9667. /**
  9668. * @author alteredq / http://alteredqualia.com/
  9669. */
  9670. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9671. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9672. this.image = { width: width, height: height };
  9673. this.mipmaps = mipmaps;
  9674. // no flipping for cube textures
  9675. // (also flipping doesn't work for compressed textures )
  9676. this.flipY = false;
  9677. // can't generate mipmaps for compressed textures
  9678. // mips must be embedded in DDS files
  9679. this.generateMipmaps = false;
  9680. };
  9681. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  9682. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  9683. THREE.CompressedTexture.prototype.clone = function () {
  9684. var texture = new THREE.CompressedTexture();
  9685. texture.copy( this );
  9686. return texture;
  9687. };
  9688. // File:src/textures/DataTexture.js
  9689. /**
  9690. * @author alteredq / http://alteredqualia.com/
  9691. */
  9692. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9693. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9694. this.image = { data: data, width: width, height: height };
  9695. };
  9696. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  9697. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  9698. THREE.DataTexture.prototype.clone = function () {
  9699. var texture = new THREE.DataTexture();
  9700. texture.copy( this );
  9701. return texture;
  9702. };
  9703. // File:src/textures/VideoTexture.js
  9704. /**
  9705. * @author mrdoob / http://mrdoob.com/
  9706. */
  9707. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9708. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9709. this.generateMipmaps = false;
  9710. var scope = this;
  9711. var update = function () {
  9712. requestAnimationFrame( update );
  9713. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  9714. scope.needsUpdate = true;
  9715. }
  9716. };
  9717. update();
  9718. };
  9719. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  9720. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  9721. // File:src/objects/Group.js
  9722. /**
  9723. * @author mrdoob / http://mrdoob.com/
  9724. */
  9725. THREE.Group = function () {
  9726. THREE.Object3D.call( this );
  9727. this.type = 'Group';
  9728. };
  9729. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  9730. THREE.Group.prototype.constructor = THREE.Group;
  9731. THREE.Group.prototype.clone = function () {
  9732. var group = new THREE.Group();
  9733. return group.copy( this );
  9734. };
  9735. THREE.Group.prototype.copy = function ( source ) {
  9736. THREE.Object3D.prototype.copy.call( this, source );
  9737. return this;
  9738. };
  9739. // File:src/objects/PointCloud.js
  9740. /**
  9741. * @author alteredq / http://alteredqualia.com/
  9742. */
  9743. THREE.PointCloud = function ( geometry, material ) {
  9744. THREE.Object3D.call( this );
  9745. this.type = 'PointCloud';
  9746. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9747. this.material = material !== undefined ? material : new THREE.PointCloudMaterial( { color: Math.random() * 0xffffff } );
  9748. };
  9749. THREE.PointCloud.prototype = Object.create( THREE.Object3D.prototype );
  9750. THREE.PointCloud.prototype.constructor = THREE.PointCloud;
  9751. THREE.PointCloud.prototype.raycast = ( function () {
  9752. var inverseMatrix = new THREE.Matrix4();
  9753. var ray = new THREE.Ray();
  9754. return function raycast( raycaster, intersects ) {
  9755. var object = this;
  9756. var geometry = object.geometry;
  9757. var threshold = raycaster.params.PointCloud.threshold;
  9758. inverseMatrix.getInverse( this.matrixWorld );
  9759. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9760. if ( geometry.boundingBox !== null ) {
  9761. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  9762. return;
  9763. }
  9764. }
  9765. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  9766. var localThresholdSq = localThreshold * localThreshold;
  9767. var position = new THREE.Vector3();
  9768. var testPoint = function ( point, index ) {
  9769. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  9770. if ( rayPointDistanceSq < localThresholdSq ) {
  9771. var intersectPoint = ray.closestPointToPoint( point );
  9772. intersectPoint.applyMatrix4( object.matrixWorld );
  9773. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  9774. if ( distance < raycaster.near || distance > raycaster.far ) return;
  9775. intersects.push( {
  9776. distance: distance,
  9777. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  9778. point: intersectPoint.clone(),
  9779. index: index,
  9780. face: null,
  9781. object: object
  9782. } );
  9783. }
  9784. };
  9785. if ( geometry instanceof THREE.BufferGeometry ) {
  9786. var attributes = geometry.attributes;
  9787. var positions = attributes.position.array;
  9788. if ( attributes.index !== undefined ) {
  9789. var indices = attributes.index.array;
  9790. var offsets = geometry.drawcalls;
  9791. if ( offsets.length === 0 ) {
  9792. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9793. }
  9794. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  9795. var offset = offsets[ oi ];
  9796. var start = offset.start;
  9797. var count = offset.count;
  9798. var index = offset.index;
  9799. for ( var i = start, il = start + count; i < il; i ++ ) {
  9800. var a = index + indices[ i ];
  9801. position.fromArray( positions, a * 3 );
  9802. testPoint( position, a );
  9803. }
  9804. }
  9805. } else {
  9806. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  9807. position.fromArray( positions, i * 3 );
  9808. testPoint( position, i );
  9809. }
  9810. }
  9811. } else {
  9812. var vertices = geometry.vertices;
  9813. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  9814. testPoint( vertices[ i ], i );
  9815. }
  9816. }
  9817. };
  9818. }() );
  9819. THREE.PointCloud.prototype.clone = function () {
  9820. var pointCloud = new THREE.PointCloud( this.geometry, this.material );
  9821. return pointCloud.copy( this );
  9822. };
  9823. THREE.PointCloud.prototype.copy = function ( source ) {
  9824. THREE.Object3D.prototype.copy.call( this, source );
  9825. return this;
  9826. };
  9827. THREE.PointCloud.prototype.toJSON = function ( meta ) {
  9828. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9829. // only serialize if not in meta geometries cache
  9830. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9831. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9832. }
  9833. // only serialize if not in meta materials cache
  9834. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9835. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9836. }
  9837. data.object.geometry = this.geometry.uuid;
  9838. data.object.material = this.material.uuid;
  9839. return data;
  9840. };
  9841. // Backwards compatibility
  9842. THREE.ParticleSystem = function ( geometry, material ) {
  9843. console.warn( 'THREE.ParticleSystem has been renamed to THREE.PointCloud.' );
  9844. return new THREE.PointCloud( geometry, material );
  9845. };
  9846. // File:src/objects/Line.js
  9847. /**
  9848. * @author mrdoob / http://mrdoob.com/
  9849. */
  9850. THREE.Line = function ( geometry, material, mode ) {
  9851. if ( mode === 1 ) {
  9852. console.error( 'THREE.Line: THREE.LinePieces mode has been removed. Use THREE.LineSegments instead.' );
  9853. }
  9854. THREE.Object3D.call( this );
  9855. this.type = 'Line';
  9856. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9857. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  9858. };
  9859. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  9860. THREE.Line.prototype.constructor = THREE.Line;
  9861. THREE.Line.prototype.raycast = ( function () {
  9862. var inverseMatrix = new THREE.Matrix4();
  9863. var ray = new THREE.Ray();
  9864. var sphere = new THREE.Sphere();
  9865. return function raycast( raycaster, intersects ) {
  9866. var precision = raycaster.linePrecision;
  9867. var precisionSq = precision * precision;
  9868. var geometry = this.geometry;
  9869. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9870. // Checking boundingSphere distance to ray
  9871. sphere.copy( geometry.boundingSphere );
  9872. sphere.applyMatrix4( this.matrixWorld );
  9873. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  9874. return;
  9875. }
  9876. inverseMatrix.getInverse( this.matrixWorld );
  9877. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9878. var vStart = new THREE.Vector3();
  9879. var vEnd = new THREE.Vector3();
  9880. var interSegment = new THREE.Vector3();
  9881. var interRay = new THREE.Vector3();
  9882. var step = this instanceof THREE.LineSegments ? 2 : 1;
  9883. if ( geometry instanceof THREE.BufferGeometry ) {
  9884. var attributes = geometry.attributes;
  9885. if ( attributes.index !== undefined ) {
  9886. var indices = attributes.index.array;
  9887. var positions = attributes.position.array;
  9888. var offsets = geometry.drawcalls;
  9889. if ( offsets.length === 0 ) {
  9890. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9891. }
  9892. for ( var oi = 0; oi < offsets.length; oi ++ ) {
  9893. var start = offsets[ oi ].start;
  9894. var count = offsets[ oi ].count;
  9895. var index = offsets[ oi ].index;
  9896. for ( var i = start; i < start + count - 1; i += step ) {
  9897. var a = index + indices[ i ];
  9898. var b = index + indices[ i + 1 ];
  9899. vStart.fromArray( positions, a * 3 );
  9900. vEnd.fromArray( positions, b * 3 );
  9901. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9902. if ( distSq > precisionSq ) continue;
  9903. var distance = ray.origin.distanceTo( interRay );
  9904. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9905. intersects.push( {
  9906. distance: distance,
  9907. // What do we want? intersection point on the ray or on the segment??
  9908. // point: raycaster.ray.at( distance ),
  9909. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9910. index: i,
  9911. offsetIndex: oi,
  9912. face: null,
  9913. faceIndex: null,
  9914. object: this
  9915. } );
  9916. }
  9917. }
  9918. } else {
  9919. var positions = attributes.position.array;
  9920. for ( var i = 0; i < positions.length / 3 - 1; i += step ) {
  9921. vStart.fromArray( positions, 3 * i );
  9922. vEnd.fromArray( positions, 3 * i + 3 );
  9923. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9924. if ( distSq > precisionSq ) continue;
  9925. var distance = ray.origin.distanceTo( interRay );
  9926. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9927. intersects.push( {
  9928. distance: distance,
  9929. // What do we want? intersection point on the ray or on the segment??
  9930. // point: raycaster.ray.at( distance ),
  9931. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9932. index: i,
  9933. face: null,
  9934. faceIndex: null,
  9935. object: this
  9936. } );
  9937. }
  9938. }
  9939. } else if ( geometry instanceof THREE.Geometry ) {
  9940. var vertices = geometry.vertices;
  9941. var nbVertices = vertices.length;
  9942. for ( var i = 0; i < nbVertices - 1; i += step ) {
  9943. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  9944. if ( distSq > precisionSq ) continue;
  9945. var distance = ray.origin.distanceTo( interRay );
  9946. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9947. intersects.push( {
  9948. distance: distance,
  9949. // What do we want? intersection point on the ray or on the segment??
  9950. // point: raycaster.ray.at( distance ),
  9951. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9952. index: i,
  9953. face: null,
  9954. faceIndex: null,
  9955. object: this
  9956. } );
  9957. }
  9958. }
  9959. };
  9960. }() );
  9961. THREE.Line.prototype.clone = function () {
  9962. var line = new THREE.Line( this.geometry, this.material );
  9963. return line.copy( this );
  9964. };
  9965. THREE.Line.prototype.copy = function ( source ) {
  9966. THREE.Object3D.prototype.copy.call( this, source );
  9967. return this;
  9968. };
  9969. THREE.Line.prototype.toJSON = function ( meta ) {
  9970. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9971. // only serialize if not in meta geometries cache
  9972. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9973. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9974. }
  9975. // only serialize if not in meta materials cache
  9976. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9977. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9978. }
  9979. data.object.geometry = this.geometry.uuid;
  9980. data.object.material = this.material.uuid;
  9981. return data;
  9982. };
  9983. // DEPRECATED
  9984. THREE.LineStrip = 0;
  9985. THREE.LinePieces = 1;
  9986. // File:src/objects/LineSegments.js
  9987. /**
  9988. * @author mrdoob / http://mrdoob.com/
  9989. */
  9990. THREE.LineSegments = function ( geometry, material ) {
  9991. THREE.Line.call( this, geometry, material );
  9992. this.type = 'LineSegments';
  9993. };
  9994. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  9995. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  9996. THREE.LineSegments.prototype.clone = function () {
  9997. var line = new THREE.LineSegments( this.geometry, this.material );
  9998. line.copy( this );
  9999. return line;
  10000. };
  10001. // File:src/objects/Mesh.js
  10002. /**
  10003. * @author mrdoob / http://mrdoob.com/
  10004. * @author alteredq / http://alteredqualia.com/
  10005. * @author mikael emtinger / http://gomo.se/
  10006. * @author jonobr1 / http://jonobr1.com/
  10007. */
  10008. THREE.Mesh = function ( geometry, material ) {
  10009. THREE.Object3D.call( this );
  10010. this.type = 'Mesh';
  10011. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  10012. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  10013. this.updateMorphTargets();
  10014. };
  10015. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  10016. THREE.Mesh.prototype.constructor = THREE.Mesh;
  10017. THREE.Mesh.prototype.updateMorphTargets = function () {
  10018. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  10019. this.morphTargetBase = - 1;
  10020. this.morphTargetForcedOrder = [];
  10021. this.morphTargetInfluences = [];
  10022. this.morphTargetDictionary = {};
  10023. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  10024. this.morphTargetInfluences.push( 0 );
  10025. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  10026. }
  10027. }
  10028. };
  10029. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  10030. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  10031. return this.morphTargetDictionary[ name ];
  10032. }
  10033. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  10034. return 0;
  10035. };
  10036. THREE.Mesh.prototype.raycast = ( function () {
  10037. var inverseMatrix = new THREE.Matrix4();
  10038. var ray = new THREE.Ray();
  10039. var sphere = new THREE.Sphere();
  10040. var vA = new THREE.Vector3();
  10041. var vB = new THREE.Vector3();
  10042. var vC = new THREE.Vector3();
  10043. var tempA = new THREE.Vector3();
  10044. var tempB = new THREE.Vector3();
  10045. var tempC = new THREE.Vector3();
  10046. return function raycast( raycaster, intersects ) {
  10047. var geometry = this.geometry;
  10048. var material = this.material;
  10049. if ( material === undefined ) return;
  10050. // Checking boundingSphere distance to ray
  10051. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10052. sphere.copy( geometry.boundingSphere );
  10053. sphere.applyMatrix4( this.matrixWorld );
  10054. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  10055. return;
  10056. }
  10057. // Check boundingBox before continuing
  10058. inverseMatrix.getInverse( this.matrixWorld );
  10059. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  10060. if ( geometry.boundingBox !== null ) {
  10061. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  10062. return;
  10063. }
  10064. }
  10065. var a, b, c;
  10066. if ( geometry instanceof THREE.BufferGeometry ) {
  10067. var attributes = geometry.attributes;
  10068. if ( attributes.index !== undefined ) {
  10069. var indices = attributes.index.array;
  10070. var positions = attributes.position.array;
  10071. var offsets = geometry.drawcalls;
  10072. if ( offsets.length === 0 ) {
  10073. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  10074. }
  10075. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  10076. var start = offsets[ oi ].start;
  10077. var count = offsets[ oi ].count;
  10078. var index = offsets[ oi ].index;
  10079. for ( var i = start, il = start + count; i < il; i += 3 ) {
  10080. a = index + indices[ i ];
  10081. b = index + indices[ i + 1 ];
  10082. c = index + indices[ i + 2 ];
  10083. vA.fromArray( positions, a * 3 );
  10084. vB.fromArray( positions, b * 3 );
  10085. vC.fromArray( positions, c * 3 );
  10086. if ( material.side === THREE.BackSide ) {
  10087. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  10088. } else {
  10089. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  10090. }
  10091. if ( intersectionPoint === null ) continue;
  10092. intersectionPoint.applyMatrix4( this.matrixWorld );
  10093. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10094. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10095. intersects.push( {
  10096. distance: distance,
  10097. point: intersectionPoint,
  10098. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  10099. faceIndex: Math.floor( i / 3 ), // triangle number in indices buffer semantics
  10100. object: this
  10101. } );
  10102. }
  10103. }
  10104. } else {
  10105. var positions = attributes.position.array;
  10106. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  10107. vA.fromArray( positions, i );
  10108. vB.fromArray( positions, i + 3 );
  10109. vC.fromArray( positions, i + 6 );
  10110. if ( material.side === THREE.BackSide ) {
  10111. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  10112. } else {
  10113. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  10114. }
  10115. if ( intersectionPoint === null ) continue;
  10116. intersectionPoint.applyMatrix4( this.matrixWorld );
  10117. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10118. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10119. a = i / 3;
  10120. b = a + 1;
  10121. c = a + 2;
  10122. intersects.push( {
  10123. distance: distance,
  10124. point: intersectionPoint,
  10125. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  10126. index: a, // triangle number in positions buffer semantics
  10127. object: this
  10128. } );
  10129. }
  10130. }
  10131. } else if ( geometry instanceof THREE.Geometry ) {
  10132. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  10133. var materials = isFaceMaterial === true ? material.materials : null;
  10134. var vertices = geometry.vertices;
  10135. var faces = geometry.faces;
  10136. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  10137. var face = faces[ f ];
  10138. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  10139. if ( faceMaterial === undefined ) continue;
  10140. a = vertices[ face.a ];
  10141. b = vertices[ face.b ];
  10142. c = vertices[ face.c ];
  10143. if ( faceMaterial.morphTargets === true ) {
  10144. var morphTargets = geometry.morphTargets;
  10145. var morphInfluences = this.morphTargetInfluences;
  10146. vA.set( 0, 0, 0 );
  10147. vB.set( 0, 0, 0 );
  10148. vC.set( 0, 0, 0 );
  10149. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  10150. var influence = morphInfluences[ t ];
  10151. if ( influence === 0 ) continue;
  10152. var targets = morphTargets[ t ].vertices;
  10153. vA.addScaledVector( tempA.subVectors( targets[ face.a ], a ), influence );
  10154. vB.addScaledVector( tempB.subVectors( targets[ face.b ], b ), influence );
  10155. vC.addScaledVector( tempC.subVectors( targets[ face.c ], c ), influence );
  10156. }
  10157. vA.add( a );
  10158. vB.add( b );
  10159. vC.add( c );
  10160. a = vA;
  10161. b = vB;
  10162. c = vC;
  10163. }
  10164. if ( faceMaterial.side === THREE.BackSide ) {
  10165. var intersectionPoint = ray.intersectTriangle( c, b, a, true );
  10166. } else {
  10167. var intersectionPoint = ray.intersectTriangle( a, b, c, faceMaterial.side !== THREE.DoubleSide );
  10168. }
  10169. if ( intersectionPoint === null ) continue;
  10170. intersectionPoint.applyMatrix4( this.matrixWorld );
  10171. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10172. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10173. intersects.push( {
  10174. distance: distance,
  10175. point: intersectionPoint,
  10176. face: face,
  10177. faceIndex: f,
  10178. object: this
  10179. } );
  10180. }
  10181. }
  10182. };
  10183. }() );
  10184. THREE.Mesh.prototype.clone = function () {
  10185. var mesh = new THREE.Mesh( this.geometry, this.material );
  10186. return mesh.copy( this );
  10187. };
  10188. THREE.Mesh.prototype.copy = function ( source ) {
  10189. THREE.Object3D.prototype.copy.call( this, source );
  10190. return this;
  10191. };
  10192. THREE.Mesh.prototype.toJSON = function ( meta ) {
  10193. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10194. // only serialize if not in meta geometries cache
  10195. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  10196. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  10197. }
  10198. // only serialize if not in meta materials cache
  10199. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10200. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  10201. }
  10202. data.object.geometry = this.geometry.uuid;
  10203. data.object.material = this.material.uuid;
  10204. return data;
  10205. };
  10206. // File:src/objects/Bone.js
  10207. /**
  10208. * @author mikael emtinger / http://gomo.se/
  10209. * @author alteredq / http://alteredqualia.com/
  10210. * @author ikerr / http://verold.com
  10211. */
  10212. THREE.Bone = function ( skin ) {
  10213. THREE.Object3D.call( this );
  10214. this.type = 'Bone';
  10215. this.skin = skin;
  10216. };
  10217. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  10218. THREE.Bone.prototype.constructor = THREE.Bone;
  10219. THREE.Bone.prototype.clone = function () {
  10220. var bone = new THREE.Bone( this.skin );
  10221. return bone.copy( this );
  10222. };
  10223. THREE.Bone.prototype.copy = function ( source ) {
  10224. THREE.Object3D.prototype.copy.call( this, source );
  10225. this.skin = source.skin;
  10226. return this;
  10227. };
  10228. // File:src/objects/Skeleton.js
  10229. /**
  10230. * @author mikael emtinger / http://gomo.se/
  10231. * @author alteredq / http://alteredqualia.com/
  10232. * @author michael guerrero / http://realitymeltdown.com
  10233. * @author ikerr / http://verold.com
  10234. */
  10235. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  10236. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  10237. this.identityMatrix = new THREE.Matrix4();
  10238. // copy the bone array
  10239. bones = bones || [];
  10240. this.bones = bones.slice( 0 );
  10241. // create a bone texture or an array of floats
  10242. if ( this.useVertexTexture ) {
  10243. // layout (1 matrix = 4 pixels)
  10244. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  10245. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  10246. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  10247. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  10248. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  10249. var size = THREE.Math.nextPowerOfTwo( Math.sqrt( this.bones.length * 4 ) ); // 4 pixels needed for 1 matrix
  10250. if ( size === 0 ) size = 2; // Avoid creating empty texture
  10251. this.boneTextureWidth = size;
  10252. this.boneTextureHeight = size;
  10253. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  10254. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  10255. this.boneTexture.minFilter = THREE.NearestFilter;
  10256. this.boneTexture.magFilter = THREE.NearestFilter;
  10257. this.boneTexture.generateMipmaps = false;
  10258. this.boneTexture.flipY = false;
  10259. } else {
  10260. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  10261. }
  10262. // use the supplied bone inverses or calculate the inverses
  10263. if ( boneInverses === undefined ) {
  10264. this.calculateInverses();
  10265. } else {
  10266. if ( this.bones.length === boneInverses.length ) {
  10267. this.boneInverses = boneInverses.slice( 0 );
  10268. } else {
  10269. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  10270. this.boneInverses = [];
  10271. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10272. this.boneInverses.push( new THREE.Matrix4() );
  10273. }
  10274. }
  10275. }
  10276. };
  10277. THREE.Skeleton.prototype.calculateInverses = function () {
  10278. this.boneInverses = [];
  10279. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10280. var inverse = new THREE.Matrix4();
  10281. if ( this.bones[ b ] ) {
  10282. inverse.getInverse( this.bones[ b ].matrixWorld );
  10283. }
  10284. this.boneInverses.push( inverse );
  10285. }
  10286. };
  10287. THREE.Skeleton.prototype.pose = function () {
  10288. var bone;
  10289. // recover the bind-time world matrices
  10290. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10291. bone = this.bones[ b ];
  10292. if ( bone ) {
  10293. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  10294. }
  10295. }
  10296. // compute the local matrices, positions, rotations and scales
  10297. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10298. bone = this.bones[ b ];
  10299. if ( bone ) {
  10300. if ( bone.parent ) {
  10301. bone.matrix.getInverse( bone.parent.matrixWorld );
  10302. bone.matrix.multiply( bone.matrixWorld );
  10303. } else {
  10304. bone.matrix.copy( bone.matrixWorld );
  10305. }
  10306. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  10307. }
  10308. }
  10309. };
  10310. THREE.Skeleton.prototype.update = ( function () {
  10311. var offsetMatrix = new THREE.Matrix4();
  10312. return function update() {
  10313. // flatten bone matrices to array
  10314. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10315. // compute the offset between the current and the original transform
  10316. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  10317. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  10318. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  10319. }
  10320. if ( this.useVertexTexture ) {
  10321. this.boneTexture.needsUpdate = true;
  10322. }
  10323. };
  10324. } )();
  10325. THREE.Skeleton.prototype.clone = function () {
  10326. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  10327. };
  10328. // File:src/objects/SkinnedMesh.js
  10329. /**
  10330. * @author mikael emtinger / http://gomo.se/
  10331. * @author alteredq / http://alteredqualia.com/
  10332. * @author ikerr / http://verold.com
  10333. */
  10334. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  10335. THREE.Mesh.call( this, geometry, material );
  10336. this.type = 'SkinnedMesh';
  10337. this.bindMode = "attached";
  10338. this.bindMatrix = new THREE.Matrix4();
  10339. this.bindMatrixInverse = new THREE.Matrix4();
  10340. // init bones
  10341. // TODO: remove bone creation as there is no reason (other than
  10342. // convenience) for THREE.SkinnedMesh to do this.
  10343. var bones = [];
  10344. if ( this.geometry && this.geometry.bones !== undefined ) {
  10345. var bone, gbone;
  10346. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10347. gbone = this.geometry.bones[ b ];
  10348. bone = new THREE.Bone( this );
  10349. bones.push( bone );
  10350. bone.name = gbone.name;
  10351. bone.position.fromArray( gbone.pos );
  10352. bone.quaternion.fromArray( gbone.rotq );
  10353. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  10354. }
  10355. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10356. gbone = this.geometry.bones[ b ];
  10357. if ( gbone.parent !== - 1 ) {
  10358. bones[ gbone.parent ].add( bones[ b ] );
  10359. } else {
  10360. this.add( bones[ b ] );
  10361. }
  10362. }
  10363. }
  10364. this.normalizeSkinWeights();
  10365. this.updateMatrixWorld( true );
  10366. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  10367. };
  10368. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  10369. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  10370. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  10371. this.skeleton = skeleton;
  10372. if ( bindMatrix === undefined ) {
  10373. this.updateMatrixWorld( true );
  10374. this.skeleton.calculateInverses();
  10375. bindMatrix = this.matrixWorld;
  10376. }
  10377. this.bindMatrix.copy( bindMatrix );
  10378. this.bindMatrixInverse.getInverse( bindMatrix );
  10379. };
  10380. THREE.SkinnedMesh.prototype.pose = function () {
  10381. this.skeleton.pose();
  10382. };
  10383. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  10384. if ( this.geometry instanceof THREE.Geometry ) {
  10385. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  10386. var sw = this.geometry.skinWeights[ i ];
  10387. var scale = 1.0 / sw.lengthManhattan();
  10388. if ( scale !== Infinity ) {
  10389. sw.multiplyScalar( scale );
  10390. } else {
  10391. sw.set( 1 ); // this will be normalized by the shader anyway
  10392. }
  10393. }
  10394. } else {
  10395. // skinning weights assumed to be normalized for THREE.BufferGeometry
  10396. }
  10397. };
  10398. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  10399. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  10400. if ( this.bindMode === "attached" ) {
  10401. this.bindMatrixInverse.getInverse( this.matrixWorld );
  10402. } else if ( this.bindMode === "detached" ) {
  10403. this.bindMatrixInverse.getInverse( this.bindMatrix );
  10404. } else {
  10405. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  10406. }
  10407. };
  10408. THREE.SkinnedMesh.prototype.clone = function() {
  10409. var skinMesh = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
  10410. return skinMesh.copy( this );
  10411. };
  10412. THREE.SkinnedMesh.prototype.copy = function( source ) {
  10413. THREE.Mesh.prototype.copy.call( this, source );
  10414. return this;
  10415. };
  10416. // File:src/objects/MorphAnimMesh.js
  10417. /**
  10418. * @author alteredq / http://alteredqualia.com/
  10419. */
  10420. THREE.MorphAnimMesh = function ( geometry, material ) {
  10421. THREE.Mesh.call( this, geometry, material );
  10422. this.type = 'MorphAnimMesh';
  10423. // API
  10424. this.duration = 1000; // milliseconds
  10425. this.mirroredLoop = false;
  10426. this.time = 0;
  10427. // internals
  10428. this.lastKeyframe = 0;
  10429. this.currentKeyframe = 0;
  10430. this.direction = 1;
  10431. this.directionBackwards = false;
  10432. this.setFrameRange( 0, geometry.morphTargets.length - 1 );
  10433. };
  10434. THREE.MorphAnimMesh.prototype = Object.create( THREE.Mesh.prototype );
  10435. THREE.MorphAnimMesh.prototype.constructor = THREE.MorphAnimMesh;
  10436. THREE.MorphAnimMesh.prototype.setFrameRange = function ( start, end ) {
  10437. this.startKeyframe = start;
  10438. this.endKeyframe = end;
  10439. this.length = this.endKeyframe - this.startKeyframe + 1;
  10440. };
  10441. THREE.MorphAnimMesh.prototype.setDirectionForward = function () {
  10442. this.direction = 1;
  10443. this.directionBackwards = false;
  10444. };
  10445. THREE.MorphAnimMesh.prototype.setDirectionBackward = function () {
  10446. this.direction = - 1;
  10447. this.directionBackwards = true;
  10448. };
  10449. THREE.MorphAnimMesh.prototype.parseAnimations = function () {
  10450. var geometry = this.geometry;
  10451. if ( ! geometry.animations ) geometry.animations = {};
  10452. var firstAnimation, animations = geometry.animations;
  10453. var pattern = /([a-z]+)_?(\d+)/;
  10454. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  10455. var morph = geometry.morphTargets[ i ];
  10456. var parts = morph.name.match( pattern );
  10457. if ( parts && parts.length > 1 ) {
  10458. var label = parts[ 1 ];
  10459. if ( ! animations[ label ] ) animations[ label ] = { start: Infinity, end: - Infinity };
  10460. var animation = animations[ label ];
  10461. if ( i < animation.start ) animation.start = i;
  10462. if ( i > animation.end ) animation.end = i;
  10463. if ( ! firstAnimation ) firstAnimation = label;
  10464. }
  10465. }
  10466. geometry.firstAnimation = firstAnimation;
  10467. };
  10468. THREE.MorphAnimMesh.prototype.setAnimationLabel = function ( label, start, end ) {
  10469. if ( ! this.geometry.animations ) this.geometry.animations = {};
  10470. this.geometry.animations[ label ] = { start: start, end: end };
  10471. };
  10472. THREE.MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {
  10473. var animation = this.geometry.animations[ label ];
  10474. if ( animation ) {
  10475. this.setFrameRange( animation.start, animation.end );
  10476. this.duration = 1000 * ( ( animation.end - animation.start ) / fps );
  10477. this.time = 0;
  10478. } else {
  10479. console.warn( 'THREE.MorphAnimMesh: animation[' + label + '] undefined in .playAnimation()' );
  10480. }
  10481. };
  10482. THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
  10483. var frameTime = this.duration / this.length;
  10484. this.time += this.direction * delta;
  10485. if ( this.mirroredLoop ) {
  10486. if ( this.time > this.duration || this.time < 0 ) {
  10487. this.direction *= - 1;
  10488. if ( this.time > this.duration ) {
  10489. this.time = this.duration;
  10490. this.directionBackwards = true;
  10491. }
  10492. if ( this.time < 0 ) {
  10493. this.time = 0;
  10494. this.directionBackwards = false;
  10495. }
  10496. }
  10497. } else {
  10498. this.time = this.time % this.duration;
  10499. if ( this.time < 0 ) this.time += this.duration;
  10500. }
  10501. var keyframe = this.startKeyframe + THREE.Math.clamp( Math.floor( this.time / frameTime ), 0, this.length - 1 );
  10502. var influences = this.morphTargetInfluences;
  10503. if ( keyframe !== this.currentKeyframe ) {
  10504. influences[ this.lastKeyframe ] = 0;
  10505. influences[ this.currentKeyframe ] = 1;
  10506. influences[ keyframe ] = 0;
  10507. this.lastKeyframe = this.currentKeyframe;
  10508. this.currentKeyframe = keyframe;
  10509. }
  10510. var mix = ( this.time % frameTime ) / frameTime;
  10511. if ( this.directionBackwards ) {
  10512. mix = 1 - mix;
  10513. }
  10514. influences[ this.currentKeyframe ] = mix;
  10515. influences[ this.lastKeyframe ] = 1 - mix;
  10516. };
  10517. THREE.MorphAnimMesh.prototype.interpolateTargets = function ( a, b, t ) {
  10518. var influences = this.morphTargetInfluences;
  10519. for ( var i = 0, l = influences.length; i < l; i ++ ) {
  10520. influences[ i ] = 0;
  10521. }
  10522. if ( a > - 1 ) influences[ a ] = 1 - t;
  10523. if ( b > - 1 ) influences[ b ] = t;
  10524. };
  10525. THREE.MorphAnimMesh.prototype.clone = function () {
  10526. var morph = new THREE.MorphAnimMesh( this.geometry, this.material );
  10527. return morph.copy( this );
  10528. };
  10529. THREE.MorphAnimMesh.prototype.copy = function ( source ) {
  10530. this.duration = source.duration;
  10531. this.mirroredLoop = source.mirroredLoop;
  10532. this.time = source.time;
  10533. this.lastKeyframe = source.lastKeyframe;
  10534. this.currentKeyframe = source.currentKeyframe;
  10535. this.direction = source.direction;
  10536. this.directionBackwards = source.directionBackwards;
  10537. THREE.Mesh.prototype.copy.call( this, source );
  10538. return this;
  10539. };
  10540. // File:src/objects/LOD.js
  10541. /**
  10542. * @author mikael emtinger / http://gomo.se/
  10543. * @author alteredq / http://alteredqualia.com/
  10544. * @author mrdoob / http://mrdoob.com/
  10545. */
  10546. THREE.LOD = function () {
  10547. THREE.Object3D.call( this );
  10548. Object.defineProperties( this, {
  10549. levels: {
  10550. enumerable: true,
  10551. value: []
  10552. },
  10553. objects: {
  10554. get: function () {
  10555. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  10556. return this.levels;
  10557. }
  10558. }
  10559. } );
  10560. };
  10561. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  10562. THREE.LOD.prototype.constructor = THREE.LOD;
  10563. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  10564. if ( distance === undefined ) distance = 0;
  10565. distance = Math.abs( distance );
  10566. var levels = this.levels;
  10567. for ( var l = 0; l < levels.length; l ++ ) {
  10568. if ( distance < levels[ l ].distance ) {
  10569. break;
  10570. }
  10571. }
  10572. levels.splice( l, 0, { distance: distance, object: object } );
  10573. this.add( object );
  10574. };
  10575. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  10576. var levels = this.levels;
  10577. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10578. if ( distance < levels[ i ].distance ) {
  10579. break;
  10580. }
  10581. }
  10582. return levels[ i - 1 ].object;
  10583. };
  10584. THREE.LOD.prototype.raycast = ( function () {
  10585. var matrixPosition = new THREE.Vector3();
  10586. return function raycast( raycaster, intersects ) {
  10587. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10588. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  10589. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  10590. };
  10591. }() );
  10592. THREE.LOD.prototype.update = function () {
  10593. var v1 = new THREE.Vector3();
  10594. var v2 = new THREE.Vector3();
  10595. return function update( camera ) {
  10596. var levels = this.levels;
  10597. if ( levels.length > 1 ) {
  10598. v1.setFromMatrixPosition( camera.matrixWorld );
  10599. v2.setFromMatrixPosition( this.matrixWorld );
  10600. var distance = v1.distanceTo( v2 );
  10601. levels[ 0 ].object.visible = true;
  10602. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10603. if ( distance >= levels[ i ].distance ) {
  10604. levels[ i - 1 ].object.visible = false;
  10605. levels[ i ].object.visible = true;
  10606. } else {
  10607. break;
  10608. }
  10609. }
  10610. for ( ; i < l; i ++ ) {
  10611. levels[ i ].object.visible = false;
  10612. }
  10613. }
  10614. };
  10615. }();
  10616. THREE.LOD.prototype.clone = function () {
  10617. var lod = new THREE.LOD();
  10618. return lod.copy( this );
  10619. };
  10620. THREE.LOD.prototype.copy = function ( source ) {
  10621. THREE.Object3D.prototype.copy.call( this, source, false );
  10622. var levels = source.levels;
  10623. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  10624. var level = levels[ i ];
  10625. this.addLevel( level.object.clone(), level.distance );
  10626. }
  10627. return this;
  10628. };
  10629. // File:src/objects/Sprite.js
  10630. /**
  10631. * @author mikael emtinger / http://gomo.se/
  10632. * @author alteredq / http://alteredqualia.com/
  10633. */
  10634. THREE.Sprite = ( function () {
  10635. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  10636. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  10637. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  10638. var geometry = new THREE.BufferGeometry();
  10639. geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  10640. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  10641. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  10642. return function Sprite( material ) {
  10643. THREE.Object3D.call( this );
  10644. this.type = 'Sprite';
  10645. this.geometry = geometry;
  10646. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  10647. };
  10648. } )();
  10649. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  10650. THREE.Sprite.prototype.constructor = THREE.Sprite;
  10651. THREE.Sprite.prototype.raycast = ( function () {
  10652. var matrixPosition = new THREE.Vector3();
  10653. return function raycast( raycaster, intersects ) {
  10654. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10655. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  10656. var guessSizeSq = this.scale.x * this.scale.y;
  10657. if ( distanceSq > guessSizeSq ) {
  10658. return;
  10659. }
  10660. intersects.push( {
  10661. distance: Math.sqrt( distanceSq ),
  10662. point: this.position,
  10663. face: null,
  10664. object: this
  10665. } );
  10666. };
  10667. }() );
  10668. THREE.Sprite.prototype.clone = function () {
  10669. var sprite = new THREE.Sprite( this.material );
  10670. return sprite.copy( this );
  10671. };
  10672. THREE.Sprite.prototype.copy = function ( source ) {
  10673. THREE.Object3D.prototype.copy.call( this, source );
  10674. return this;
  10675. };
  10676. THREE.Sprite.prototype.toJSON = function ( meta ) {
  10677. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10678. // only serialize if not in meta materials cache
  10679. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10680. meta.materials[ this.material.uuid ] = this.material.toJSON();
  10681. }
  10682. data.object.material = this.material.uuid;
  10683. return data;
  10684. };
  10685. // Backwards compatibility
  10686. THREE.Particle = THREE.Sprite;
  10687. // File:src/objects/LensFlare.js
  10688. /**
  10689. * @author mikael emtinger / http://gomo.se/
  10690. * @author alteredq / http://alteredqualia.com/
  10691. */
  10692. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  10693. THREE.Object3D.call( this );
  10694. this.lensFlares = [];
  10695. this.positionScreen = new THREE.Vector3();
  10696. this.customUpdateCallback = undefined;
  10697. if ( texture !== undefined ) {
  10698. this.add( texture, size, distance, blending, color );
  10699. }
  10700. };
  10701. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  10702. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  10703. /*
  10704. * Add: adds another flare
  10705. */
  10706. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  10707. if ( size === undefined ) size = - 1;
  10708. if ( distance === undefined ) distance = 0;
  10709. if ( opacity === undefined ) opacity = 1;
  10710. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  10711. if ( blending === undefined ) blending = THREE.NormalBlending;
  10712. distance = Math.min( distance, Math.max( 0, distance ) );
  10713. this.lensFlares.push( {
  10714. texture: texture, // THREE.Texture
  10715. size: size, // size in pixels (-1 = use texture.width)
  10716. distance: distance, // distance (0-1) from light source (0=at light source)
  10717. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  10718. scale: 1, // scale
  10719. rotation: 0, // rotation
  10720. opacity: opacity, // opacity
  10721. color: color, // color
  10722. blending: blending // blending
  10723. } );
  10724. };
  10725. /*
  10726. * Update lens flares update positions on all flares based on the screen position
  10727. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  10728. */
  10729. THREE.LensFlare.prototype.updateLensFlares = function () {
  10730. var f, fl = this.lensFlares.length;
  10731. var flare;
  10732. var vecX = - this.positionScreen.x * 2;
  10733. var vecY = - this.positionScreen.y * 2;
  10734. for ( f = 0; f < fl; f ++ ) {
  10735. flare = this.lensFlares[ f ];
  10736. flare.x = this.positionScreen.x + vecX * flare.distance;
  10737. flare.y = this.positionScreen.y + vecY * flare.distance;
  10738. flare.wantedRotation = flare.x * Math.PI * 0.25;
  10739. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  10740. }
  10741. };
  10742. THREE.LensFlare.prototype.clone = function () {
  10743. var flare = new THREE.LensFlare();
  10744. return flare.copy( this );
  10745. };
  10746. THREE.LensFlare.prototype.copy = function ( source ) {
  10747. THREE.Object3D.prototype.copy.call( this, source );
  10748. this.positionScreen.copy( source.positionScreen );
  10749. this.customUpdateCallback = source.customUpdateCallback;
  10750. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  10751. this.lensFlares.push( source.lensFlares[ i ] );
  10752. }
  10753. return this;
  10754. };
  10755. // File:src/scenes/Scene.js
  10756. /**
  10757. * @author mrdoob / http://mrdoob.com/
  10758. */
  10759. THREE.Scene = function () {
  10760. THREE.Object3D.call( this );
  10761. this.type = 'Scene';
  10762. this.fog = null;
  10763. this.overrideMaterial = null;
  10764. this.autoUpdate = true; // checked by the renderer
  10765. };
  10766. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  10767. THREE.Scene.prototype.constructor = THREE.Scene;
  10768. THREE.Scene.prototype.clone = function () {
  10769. var scene = new THREE.Scene();
  10770. return scene.copy( this );
  10771. };
  10772. THREE.Scene.prototype.copy = function ( source ) {
  10773. THREE.Object3D.prototype.copy.call( this, source );
  10774. if ( source.fog !== null ) this.fog = source.fog.clone();
  10775. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  10776. this.autoUpdate = source.autoUpdate;
  10777. this.matrixAutoUpdate = source.matrixAutoUpdate;
  10778. return this;
  10779. };
  10780. // File:src/scenes/Fog.js
  10781. /**
  10782. * @author mrdoob / http://mrdoob.com/
  10783. * @author alteredq / http://alteredqualia.com/
  10784. */
  10785. THREE.Fog = function ( color, near, far ) {
  10786. this.name = '';
  10787. this.color = new THREE.Color( color );
  10788. this.near = ( near !== undefined ) ? near : 1;
  10789. this.far = ( far !== undefined ) ? far : 1000;
  10790. };
  10791. THREE.Fog.prototype.clone = function () {
  10792. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  10793. };
  10794. // File:src/scenes/FogExp2.js
  10795. /**
  10796. * @author mrdoob / http://mrdoob.com/
  10797. * @author alteredq / http://alteredqualia.com/
  10798. */
  10799. THREE.FogExp2 = function ( color, density ) {
  10800. this.name = '';
  10801. this.color = new THREE.Color( color );
  10802. this.density = ( density !== undefined ) ? density : 0.00025;
  10803. };
  10804. THREE.FogExp2.prototype.clone = function () {
  10805. return new THREE.FogExp2( this.color.getHex(), this.density );
  10806. };
  10807. // File:src/renderers/shaders/ShaderChunk.js
  10808. THREE.ShaderChunk = {};
  10809. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  10810. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  10811. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  10812. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  10813. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  10814. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  10815. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  10816. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  10817. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  10818. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  10819. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  10820. 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";
  10821. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  10822. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  10823. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  10824. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  10825. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  10826. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  10827. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  10828. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = color.xyz;\n\n#endif";
  10829. // File:src/renderers/shaders/ShaderChunk/common.glsl
  10830. 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";
  10831. // File:src/renderers/shaders/ShaderChunk/default_vertex.glsl
  10832. 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";
  10833. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  10834. 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";
  10835. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  10836. 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";
  10837. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  10838. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n";
  10839. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  10840. 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";
  10841. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  10842. 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";
  10843. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  10844. 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";
  10845. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  10846. 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";
  10847. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  10848. 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";
  10849. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  10850. 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";
  10851. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  10852. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  10853. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  10854. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  10855. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  10856. 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";
  10857. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  10858. 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";
  10859. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  10860. 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";
  10861. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  10862. 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";
  10863. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  10864. 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";
  10865. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  10866. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif";
  10867. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  10868. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  10869. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  10870. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  10871. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  10872. 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";
  10873. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  10874. 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";
  10875. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  10876. 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";
  10877. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  10878. 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";
  10879. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  10880. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  10881. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  10882. 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";
  10883. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  10884. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  10885. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  10886. 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";
  10887. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  10888. 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";
  10889. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  10890. 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";
  10891. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  10892. 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";
  10893. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  10894. 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 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 bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\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 if ( inFrustum ) outgoingLight *= frustumColors[ i ];\n\n #endif\n\n }\n\n outgoingLight = outgoingLight * shadowColor;\n\n#endif\n";
  10895. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  10896. 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";
  10897. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  10898. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n\n#endif";
  10899. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  10900. 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";
  10901. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  10902. 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";
  10903. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  10904. 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";
  10905. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  10906. 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";
  10907. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  10908. 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";
  10909. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  10910. 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";
  10911. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  10912. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  10913. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  10914. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  10915. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  10916. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  10917. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  10918. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  10919. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  10920. 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";
  10921. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  10922. 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";
  10923. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  10924. 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";
  10925. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  10926. 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";
  10927. // File:src/renderers/shaders/UniformsUtils.js
  10928. /**
  10929. * Uniform Utilities
  10930. */
  10931. THREE.UniformsUtils = {
  10932. merge: function ( uniforms ) {
  10933. var merged = {};
  10934. for ( var u = 0; u < uniforms.length; u ++ ) {
  10935. var tmp = this.clone( uniforms[ u ] );
  10936. for ( var p in tmp ) {
  10937. merged[ p ] = tmp[ p ];
  10938. }
  10939. }
  10940. return merged;
  10941. },
  10942. clone: function ( uniforms_src ) {
  10943. var uniforms_dst = {};
  10944. for ( var u in uniforms_src ) {
  10945. uniforms_dst[ u ] = {};
  10946. for ( var p in uniforms_src[ u ] ) {
  10947. var parameter_src = uniforms_src[ u ][ p ];
  10948. if ( parameter_src instanceof THREE.Color ||
  10949. parameter_src instanceof THREE.Vector2 ||
  10950. parameter_src instanceof THREE.Vector3 ||
  10951. parameter_src instanceof THREE.Vector4 ||
  10952. parameter_src instanceof THREE.Matrix3 ||
  10953. parameter_src instanceof THREE.Matrix4 ||
  10954. parameter_src instanceof THREE.Texture ) {
  10955. uniforms_dst[ u ][ p ] = parameter_src.clone();
  10956. } else if ( Array.isArray( parameter_src ) ) {
  10957. uniforms_dst[ u ][ p ] = parameter_src.slice();
  10958. } else {
  10959. uniforms_dst[ u ][ p ] = parameter_src;
  10960. }
  10961. }
  10962. }
  10963. return uniforms_dst;
  10964. }
  10965. };
  10966. // File:src/renderers/shaders/UniformsLib.js
  10967. /**
  10968. * Uniforms library for shared webgl shaders
  10969. */
  10970. THREE.UniformsLib = {
  10971. common: {
  10972. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  10973. "opacity" : { type: "f", value: 1.0 },
  10974. "map" : { type: "t", value: null },
  10975. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  10976. "specularMap" : { type: "t", value: null },
  10977. "alphaMap" : { type: "t", value: null },
  10978. "envMap" : { type: "t", value: null },
  10979. "flipEnvMap" : { type: "f", value: - 1 },
  10980. "reflectivity" : { type: "f", value: 1.0 },
  10981. "refractionRatio" : { type: "f", value: 0.98 }
  10982. },
  10983. aomap: {
  10984. "aoMap" : { type: "t", value: null },
  10985. "aoMapIntensity" : { type: "f", value: 1 },
  10986. },
  10987. lightmap: {
  10988. "lightMap" : { type: "t", value: null },
  10989. "lightMapIntensity" : { type: "f", value: 1 },
  10990. },
  10991. emissivemap: {
  10992. "emissiveMap" : { type: "t", value: null },
  10993. },
  10994. bump: {
  10995. "bumpMap" : { type: "t", value: null },
  10996. "bumpScale" : { type: "f", value: 1 }
  10997. },
  10998. normalmap: {
  10999. "normalMap" : { type: "t", value: null },
  11000. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  11001. },
  11002. fog : {
  11003. "fogDensity" : { type: "f", value: 0.00025 },
  11004. "fogNear" : { type: "f", value: 1 },
  11005. "fogFar" : { type: "f", value: 2000 },
  11006. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  11007. },
  11008. lights: {
  11009. "ambientLightColor" : { type: "fv", value: [] },
  11010. "directionalLightDirection" : { type: "fv", value: [] },
  11011. "directionalLightColor" : { type: "fv", value: [] },
  11012. "hemisphereLightDirection" : { type: "fv", value: [] },
  11013. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  11014. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  11015. "pointLightColor" : { type: "fv", value: [] },
  11016. "pointLightPosition" : { type: "fv", value: [] },
  11017. "pointLightDistance" : { type: "fv1", value: [] },
  11018. "pointLightDecay" : { type: "fv1", value: [] },
  11019. "spotLightColor" : { type: "fv", value: [] },
  11020. "spotLightPosition" : { type: "fv", value: [] },
  11021. "spotLightDirection" : { type: "fv", value: [] },
  11022. "spotLightDistance" : { type: "fv1", value: [] },
  11023. "spotLightAngleCos" : { type: "fv1", value: [] },
  11024. "spotLightExponent" : { type: "fv1", value: [] },
  11025. "spotLightDecay" : { type: "fv1", value: [] }
  11026. },
  11027. particle: {
  11028. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  11029. "opacity" : { type: "f", value: 1.0 },
  11030. "size" : { type: "f", value: 1.0 },
  11031. "scale" : { type: "f", value: 1.0 },
  11032. "map" : { type: "t", value: null },
  11033. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  11034. "fogDensity" : { type: "f", value: 0.00025 },
  11035. "fogNear" : { type: "f", value: 1 },
  11036. "fogFar" : { type: "f", value: 2000 },
  11037. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  11038. },
  11039. shadowmap: {
  11040. "shadowMap": { type: "tv", value: [] },
  11041. "shadowMapSize": { type: "v2v", value: [] },
  11042. "shadowBias" : { type: "fv1", value: [] },
  11043. "shadowDarkness": { type: "fv1", value: [] },
  11044. "shadowMatrix" : { type: "m4v", value: [] }
  11045. }
  11046. };
  11047. // File:src/renderers/shaders/ShaderLib.js
  11048. /**
  11049. * Webgl Shader Library for three.js
  11050. *
  11051. * @author alteredq / http://alteredqualia.com/
  11052. * @author mrdoob / http://mrdoob.com/
  11053. * @author mikael emtinger / http://gomo.se/
  11054. */
  11055. THREE.ShaderLib = {
  11056. 'basic': {
  11057. uniforms: THREE.UniformsUtils.merge( [
  11058. THREE.UniformsLib[ "common" ],
  11059. THREE.UniformsLib[ "aomap" ],
  11060. THREE.UniformsLib[ "fog" ],
  11061. THREE.UniformsLib[ "shadowmap" ]
  11062. ] ),
  11063. vertexShader: [
  11064. THREE.ShaderChunk[ "common" ],
  11065. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11066. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11067. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11068. THREE.ShaderChunk[ "color_pars_vertex" ],
  11069. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11070. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11071. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11072. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11073. "void main() {",
  11074. THREE.ShaderChunk[ "uv_vertex" ],
  11075. THREE.ShaderChunk[ "uv2_vertex" ],
  11076. THREE.ShaderChunk[ "color_vertex" ],
  11077. THREE.ShaderChunk[ "skinbase_vertex" ],
  11078. " #ifdef USE_ENVMAP",
  11079. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11080. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11081. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11082. " #endif",
  11083. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11084. THREE.ShaderChunk[ "skinning_vertex" ],
  11085. THREE.ShaderChunk[ "default_vertex" ],
  11086. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11087. THREE.ShaderChunk[ "worldpos_vertex" ],
  11088. THREE.ShaderChunk[ "envmap_vertex" ],
  11089. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11090. "}"
  11091. ].join( "\n" ),
  11092. fragmentShader: [
  11093. "uniform vec3 diffuse;",
  11094. "uniform float opacity;",
  11095. THREE.ShaderChunk[ "common" ],
  11096. THREE.ShaderChunk[ "color_pars_fragment" ],
  11097. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11098. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11099. THREE.ShaderChunk[ "map_pars_fragment" ],
  11100. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11101. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  11102. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11103. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11104. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11105. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11106. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11107. "void main() {",
  11108. " vec3 outgoingLight = vec3( 0.0 );",
  11109. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11110. " vec3 totalAmbientLight = vec3( 1.0 );", // hardwired
  11111. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11112. THREE.ShaderChunk[ "map_fragment" ],
  11113. THREE.ShaderChunk[ "color_fragment" ],
  11114. THREE.ShaderChunk[ "alphamap_fragment" ],
  11115. THREE.ShaderChunk[ "alphatest_fragment" ],
  11116. THREE.ShaderChunk[ "specularmap_fragment" ],
  11117. THREE.ShaderChunk[ "aomap_fragment" ],
  11118. " outgoingLight = diffuseColor.rgb * totalAmbientLight;", // simple shader
  11119. THREE.ShaderChunk[ "envmap_fragment" ],
  11120. THREE.ShaderChunk[ "shadowmap_fragment" ], // TODO: Shadows on an otherwise unlit surface doesn't make sense.
  11121. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11122. THREE.ShaderChunk[ "fog_fragment" ],
  11123. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11124. "}"
  11125. ].join( "\n" )
  11126. },
  11127. 'lambert': {
  11128. uniforms: THREE.UniformsUtils.merge( [
  11129. THREE.UniformsLib[ "common" ],
  11130. THREE.UniformsLib[ "fog" ],
  11131. THREE.UniformsLib[ "lights" ],
  11132. THREE.UniformsLib[ "shadowmap" ],
  11133. {
  11134. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  11135. }
  11136. ] ),
  11137. vertexShader: [
  11138. "#define LAMBERT",
  11139. "varying vec3 vLightFront;",
  11140. "#ifdef DOUBLE_SIDED",
  11141. " varying vec3 vLightBack;",
  11142. "#endif",
  11143. THREE.ShaderChunk[ "common" ],
  11144. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11145. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11146. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11147. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  11148. THREE.ShaderChunk[ "color_pars_vertex" ],
  11149. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11150. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11151. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11152. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11153. "void main() {",
  11154. THREE.ShaderChunk[ "uv_vertex" ],
  11155. THREE.ShaderChunk[ "uv2_vertex" ],
  11156. THREE.ShaderChunk[ "color_vertex" ],
  11157. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11158. THREE.ShaderChunk[ "skinbase_vertex" ],
  11159. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11160. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11161. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11162. THREE.ShaderChunk[ "skinning_vertex" ],
  11163. THREE.ShaderChunk[ "default_vertex" ],
  11164. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11165. THREE.ShaderChunk[ "worldpos_vertex" ],
  11166. THREE.ShaderChunk[ "envmap_vertex" ],
  11167. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  11168. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11169. "}"
  11170. ].join( "\n" ),
  11171. fragmentShader: [
  11172. "uniform vec3 diffuse;",
  11173. "uniform vec3 emissive;",
  11174. "uniform float opacity;",
  11175. "varying vec3 vLightFront;",
  11176. "#ifdef DOUBLE_SIDED",
  11177. " varying vec3 vLightBack;",
  11178. "#endif",
  11179. THREE.ShaderChunk[ "common" ],
  11180. THREE.ShaderChunk[ "color_pars_fragment" ],
  11181. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11182. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11183. THREE.ShaderChunk[ "map_pars_fragment" ],
  11184. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11185. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11186. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11187. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11188. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11189. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11190. "void main() {",
  11191. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  11192. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11193. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11194. THREE.ShaderChunk[ "map_fragment" ],
  11195. THREE.ShaderChunk[ "color_fragment" ],
  11196. THREE.ShaderChunk[ "alphamap_fragment" ],
  11197. THREE.ShaderChunk[ "alphatest_fragment" ],
  11198. THREE.ShaderChunk[ "specularmap_fragment" ],
  11199. " #ifdef DOUBLE_SIDED",
  11200. " if ( gl_FrontFacing )",
  11201. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11202. " else",
  11203. " outgoingLight += diffuseColor.rgb * vLightBack + emissive;",
  11204. " #else",
  11205. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11206. " #endif",
  11207. THREE.ShaderChunk[ "envmap_fragment" ],
  11208. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11209. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11210. THREE.ShaderChunk[ "fog_fragment" ],
  11211. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11212. "}"
  11213. ].join( "\n" )
  11214. },
  11215. 'phong': {
  11216. uniforms: THREE.UniformsUtils.merge( [
  11217. THREE.UniformsLib[ "common" ],
  11218. THREE.UniformsLib[ "aomap" ],
  11219. THREE.UniformsLib[ "lightmap" ],
  11220. THREE.UniformsLib[ "emissivemap" ],
  11221. THREE.UniformsLib[ "bump" ],
  11222. THREE.UniformsLib[ "normalmap" ],
  11223. THREE.UniformsLib[ "fog" ],
  11224. THREE.UniformsLib[ "lights" ],
  11225. THREE.UniformsLib[ "shadowmap" ],
  11226. {
  11227. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  11228. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  11229. "shininess": { type: "f", value: 30 }
  11230. }
  11231. ] ),
  11232. vertexShader: [
  11233. "#define PHONG",
  11234. "varying vec3 vViewPosition;",
  11235. "#ifndef FLAT_SHADED",
  11236. " varying vec3 vNormal;",
  11237. "#endif",
  11238. THREE.ShaderChunk[ "common" ],
  11239. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11240. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11241. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11242. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  11243. THREE.ShaderChunk[ "color_pars_vertex" ],
  11244. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11245. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11246. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11247. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11248. "void main() {",
  11249. THREE.ShaderChunk[ "uv_vertex" ],
  11250. THREE.ShaderChunk[ "uv2_vertex" ],
  11251. THREE.ShaderChunk[ "color_vertex" ],
  11252. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11253. THREE.ShaderChunk[ "skinbase_vertex" ],
  11254. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11255. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11256. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  11257. " vNormal = normalize( transformedNormal );",
  11258. "#endif",
  11259. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11260. THREE.ShaderChunk[ "skinning_vertex" ],
  11261. THREE.ShaderChunk[ "default_vertex" ],
  11262. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11263. " vViewPosition = - mvPosition.xyz;",
  11264. THREE.ShaderChunk[ "worldpos_vertex" ],
  11265. THREE.ShaderChunk[ "envmap_vertex" ],
  11266. THREE.ShaderChunk[ "lights_phong_vertex" ],
  11267. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11268. "}"
  11269. ].join( "\n" ),
  11270. fragmentShader: [
  11271. "#define PHONG",
  11272. "uniform vec3 diffuse;",
  11273. "uniform vec3 emissive;",
  11274. "uniform vec3 specular;",
  11275. "uniform float shininess;",
  11276. "uniform float opacity;",
  11277. THREE.ShaderChunk[ "common" ],
  11278. THREE.ShaderChunk[ "color_pars_fragment" ],
  11279. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11280. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11281. THREE.ShaderChunk[ "map_pars_fragment" ],
  11282. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11283. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  11284. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  11285. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  11286. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11287. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11288. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  11289. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11290. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  11291. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  11292. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11293. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11294. "void main() {",
  11295. " vec3 outgoingLight = vec3( 0.0 );",
  11296. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11297. " vec3 totalAmbientLight = ambientLightColor;",
  11298. " vec3 totalEmissiveLight = emissive;",
  11299. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11300. THREE.ShaderChunk[ "map_fragment" ],
  11301. THREE.ShaderChunk[ "color_fragment" ],
  11302. THREE.ShaderChunk[ "alphamap_fragment" ],
  11303. THREE.ShaderChunk[ "alphatest_fragment" ],
  11304. THREE.ShaderChunk[ "specularmap_fragment" ],
  11305. THREE.ShaderChunk[ "lightmap_fragment" ],
  11306. THREE.ShaderChunk[ "aomap_fragment" ],
  11307. THREE.ShaderChunk[ "emissivemap_fragment" ],
  11308. THREE.ShaderChunk[ "lights_phong_fragment" ],
  11309. THREE.ShaderChunk[ "envmap_fragment" ],
  11310. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11311. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11312. THREE.ShaderChunk[ "fog_fragment" ],
  11313. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11314. "}"
  11315. ].join( "\n" )
  11316. },
  11317. 'particle_basic': {
  11318. uniforms: THREE.UniformsUtils.merge( [
  11319. THREE.UniformsLib[ "particle" ],
  11320. THREE.UniformsLib[ "shadowmap" ]
  11321. ] ),
  11322. vertexShader: [
  11323. "uniform float size;",
  11324. "uniform float scale;",
  11325. THREE.ShaderChunk[ "common" ],
  11326. THREE.ShaderChunk[ "color_pars_vertex" ],
  11327. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11328. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11329. "void main() {",
  11330. THREE.ShaderChunk[ "color_vertex" ],
  11331. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11332. " #ifdef USE_SIZEATTENUATION",
  11333. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  11334. " #else",
  11335. " gl_PointSize = size;",
  11336. " #endif",
  11337. " gl_Position = projectionMatrix * mvPosition;",
  11338. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11339. THREE.ShaderChunk[ "worldpos_vertex" ],
  11340. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11341. "}"
  11342. ].join( "\n" ),
  11343. fragmentShader: [
  11344. "uniform vec3 psColor;",
  11345. "uniform float opacity;",
  11346. THREE.ShaderChunk[ "common" ],
  11347. THREE.ShaderChunk[ "color_pars_fragment" ],
  11348. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  11349. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11350. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11351. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11352. "void main() {",
  11353. " vec3 outgoingLight = vec3( 0.0 );",
  11354. " vec4 diffuseColor = vec4( psColor, opacity );",
  11355. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11356. THREE.ShaderChunk[ "map_particle_fragment" ],
  11357. THREE.ShaderChunk[ "color_fragment" ],
  11358. THREE.ShaderChunk[ "alphatest_fragment" ],
  11359. " outgoingLight = diffuseColor.rgb;", // simple shader
  11360. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11361. THREE.ShaderChunk[ "fog_fragment" ],
  11362. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11363. "}"
  11364. ].join( "\n" )
  11365. },
  11366. 'dashed': {
  11367. uniforms: THREE.UniformsUtils.merge( [
  11368. THREE.UniformsLib[ "common" ],
  11369. THREE.UniformsLib[ "fog" ],
  11370. {
  11371. "scale" : { type: "f", value: 1 },
  11372. "dashSize" : { type: "f", value: 1 },
  11373. "totalSize": { type: "f", value: 2 }
  11374. }
  11375. ] ),
  11376. vertexShader: [
  11377. "uniform float scale;",
  11378. "attribute float lineDistance;",
  11379. "varying float vLineDistance;",
  11380. THREE.ShaderChunk[ "common" ],
  11381. THREE.ShaderChunk[ "color_pars_vertex" ],
  11382. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11383. "void main() {",
  11384. THREE.ShaderChunk[ "color_vertex" ],
  11385. " vLineDistance = scale * lineDistance;",
  11386. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11387. " gl_Position = projectionMatrix * mvPosition;",
  11388. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11389. "}"
  11390. ].join( "\n" ),
  11391. fragmentShader: [
  11392. "uniform vec3 diffuse;",
  11393. "uniform float opacity;",
  11394. "uniform float dashSize;",
  11395. "uniform float totalSize;",
  11396. "varying float vLineDistance;",
  11397. THREE.ShaderChunk[ "common" ],
  11398. THREE.ShaderChunk[ "color_pars_fragment" ],
  11399. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11400. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11401. "void main() {",
  11402. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  11403. " discard;",
  11404. " }",
  11405. " vec3 outgoingLight = vec3( 0.0 );",
  11406. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11407. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11408. THREE.ShaderChunk[ "color_fragment" ],
  11409. " outgoingLight = diffuseColor.rgb;", // simple shader
  11410. THREE.ShaderChunk[ "fog_fragment" ],
  11411. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11412. "}"
  11413. ].join( "\n" )
  11414. },
  11415. 'depth': {
  11416. uniforms: {
  11417. "mNear": { type: "f", value: 1.0 },
  11418. "mFar" : { type: "f", value: 2000.0 },
  11419. "opacity" : { type: "f", value: 1.0 }
  11420. },
  11421. vertexShader: [
  11422. THREE.ShaderChunk[ "common" ],
  11423. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11424. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11425. "void main() {",
  11426. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11427. THREE.ShaderChunk[ "default_vertex" ],
  11428. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11429. "}"
  11430. ].join( "\n" ),
  11431. fragmentShader: [
  11432. "uniform float mNear;",
  11433. "uniform float mFar;",
  11434. "uniform float opacity;",
  11435. THREE.ShaderChunk[ "common" ],
  11436. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11437. "void main() {",
  11438. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11439. " #ifdef USE_LOGDEPTHBUF_EXT",
  11440. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  11441. " #else",
  11442. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  11443. " #endif",
  11444. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  11445. " gl_FragColor = vec4( vec3( color ), opacity );",
  11446. "}"
  11447. ].join( "\n" )
  11448. },
  11449. 'normal': {
  11450. uniforms: {
  11451. "opacity" : { type: "f", value: 1.0 }
  11452. },
  11453. vertexShader: [
  11454. "varying vec3 vNormal;",
  11455. THREE.ShaderChunk[ "common" ],
  11456. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11457. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11458. "void main() {",
  11459. " vNormal = normalize( normalMatrix * normal );",
  11460. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11461. THREE.ShaderChunk[ "default_vertex" ],
  11462. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11463. "}"
  11464. ].join( "\n" ),
  11465. fragmentShader: [
  11466. "uniform float opacity;",
  11467. "varying vec3 vNormal;",
  11468. THREE.ShaderChunk[ "common" ],
  11469. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11470. "void main() {",
  11471. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  11472. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11473. "}"
  11474. ].join( "\n" )
  11475. },
  11476. /* -------------------------------------------------------------------------
  11477. // Cube map shader
  11478. ------------------------------------------------------------------------- */
  11479. 'cube': {
  11480. uniforms: { "tCube": { type: "t", value: null },
  11481. "tFlip": { type: "f", value: - 1 } },
  11482. vertexShader: [
  11483. "varying vec3 vWorldPosition;",
  11484. THREE.ShaderChunk[ "common" ],
  11485. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11486. "void main() {",
  11487. " vWorldPosition = transformDirection( position, modelMatrix );",
  11488. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11489. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11490. "}"
  11491. ].join( "\n" ),
  11492. fragmentShader: [
  11493. "uniform samplerCube tCube;",
  11494. "uniform float tFlip;",
  11495. "varying vec3 vWorldPosition;",
  11496. THREE.ShaderChunk[ "common" ],
  11497. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11498. "void main() {",
  11499. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11500. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11501. "}"
  11502. ].join( "\n" )
  11503. },
  11504. /* -------------------------------------------------------------------------
  11505. // Cube map shader
  11506. ------------------------------------------------------------------------- */
  11507. 'equirect': {
  11508. uniforms: { "tEquirect": { type: "t", value: null },
  11509. "tFlip": { type: "f", value: - 1 } },
  11510. vertexShader: [
  11511. "varying vec3 vWorldPosition;",
  11512. THREE.ShaderChunk[ "common" ],
  11513. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11514. "void main() {",
  11515. " vWorldPosition = transformDirection( position, modelMatrix );",
  11516. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11517. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11518. "}"
  11519. ].join( "\n" ),
  11520. fragmentShader: [
  11521. "uniform sampler2D tEquirect;",
  11522. "uniform float tFlip;",
  11523. "varying vec3 vWorldPosition;",
  11524. THREE.ShaderChunk[ "common" ],
  11525. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11526. "void main() {",
  11527. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11528. "vec3 direction = normalize( vWorldPosition );",
  11529. "vec2 sampleUV;",
  11530. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  11531. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  11532. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  11533. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11534. "}"
  11535. ].join( "\n" )
  11536. },
  11537. /* Depth encoding into RGBA texture
  11538. *
  11539. * based on SpiderGL shadow map example
  11540. * http://spidergl.org/example.php?id=6
  11541. *
  11542. * originally from
  11543. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  11544. *
  11545. * see also
  11546. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  11547. */
  11548. 'depthRGBA': {
  11549. uniforms: {},
  11550. vertexShader: [
  11551. THREE.ShaderChunk[ "common" ],
  11552. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11553. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11554. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11555. "void main() {",
  11556. THREE.ShaderChunk[ "skinbase_vertex" ],
  11557. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11558. THREE.ShaderChunk[ "skinning_vertex" ],
  11559. THREE.ShaderChunk[ "default_vertex" ],
  11560. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11561. "}"
  11562. ].join( "\n" ),
  11563. fragmentShader: [
  11564. THREE.ShaderChunk[ "common" ],
  11565. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11566. "vec4 pack_depth( const in float depth ) {",
  11567. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  11568. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  11569. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  11570. " res -= res.xxyz * bit_mask;",
  11571. " return res;",
  11572. "}",
  11573. "void main() {",
  11574. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11575. " #ifdef USE_LOGDEPTHBUF_EXT",
  11576. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  11577. " #else",
  11578. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  11579. " #endif",
  11580. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  11581. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  11582. //"gl_FragData[ 0 ] = pack_depth( z );",
  11583. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  11584. "}"
  11585. ].join( "\n" )
  11586. }
  11587. };
  11588. // File:src/renderers/WebGLRenderer.js
  11589. /**
  11590. * @author supereggbert / http://www.paulbrunt.co.uk/
  11591. * @author mrdoob / http://mrdoob.com/
  11592. * @author alteredq / http://alteredqualia.com/
  11593. * @author szimek / https://github.com/szimek/
  11594. */
  11595. THREE.WebGLRenderer = function ( parameters ) {
  11596. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  11597. parameters = parameters || {};
  11598. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  11599. _context = parameters.context !== undefined ? parameters.context : null,
  11600. _width = _canvas.width,
  11601. _height = _canvas.height,
  11602. pixelRatio = 1,
  11603. _precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  11604. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  11605. _depth = parameters.depth !== undefined ? parameters.depth : true,
  11606. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  11607. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  11608. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  11609. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  11610. _logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false,
  11611. _clearColor = new THREE.Color( 0x000000 ),
  11612. _clearAlpha = 0;
  11613. var lights = [];
  11614. var opaqueObjects = [];
  11615. var transparentObjects = [];
  11616. var opaqueImmediateObjects = [];
  11617. var transparentImmediateObjects = [];
  11618. var morphInfluences = new Float32Array( 8 );
  11619. var sprites = [];
  11620. var lensFlares = [];
  11621. // public properties
  11622. this.domElement = _canvas;
  11623. this.context = null;
  11624. // clearing
  11625. this.autoClear = true;
  11626. this.autoClearColor = true;
  11627. this.autoClearDepth = true;
  11628. this.autoClearStencil = true;
  11629. // scene graph
  11630. this.sortObjects = true;
  11631. // physically based shading
  11632. this.gammaFactor = 2.0; // for backwards compatibility
  11633. this.gammaInput = false;
  11634. this.gammaOutput = false;
  11635. // morphs
  11636. this.maxMorphTargets = 8;
  11637. this.maxMorphNormals = 4;
  11638. // flags
  11639. this.autoScaleCubemaps = true;
  11640. // internal properties
  11641. var _this = this,
  11642. _programs = [],
  11643. // internal state cache
  11644. _currentProgram = null,
  11645. _currentFramebuffer = null,
  11646. _currentMaterialId = - 1,
  11647. _currentGeometryProgram = '',
  11648. _currentCamera = null,
  11649. _usedTextureUnits = 0,
  11650. _viewportX = 0,
  11651. _viewportY = 0,
  11652. _viewportWidth = _canvas.width,
  11653. _viewportHeight = _canvas.height,
  11654. _currentWidth = 0,
  11655. _currentHeight = 0,
  11656. // frustum
  11657. _frustum = new THREE.Frustum(),
  11658. // camera matrices cache
  11659. _projScreenMatrix = new THREE.Matrix4(),
  11660. _vector3 = new THREE.Vector3(),
  11661. // light arrays cache
  11662. _direction = new THREE.Vector3(),
  11663. _lightsNeedUpdate = true,
  11664. _lights = {
  11665. ambient: [ 0, 0, 0 ],
  11666. directional: { length: 0, colors: [], positions: [] },
  11667. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  11668. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  11669. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  11670. },
  11671. // info
  11672. _infoMemory = {
  11673. programs: 0,
  11674. geometries: 0,
  11675. textures: 0
  11676. },
  11677. _infoRender = {
  11678. calls: 0,
  11679. vertices: 0,
  11680. faces: 0,
  11681. points: 0
  11682. };
  11683. this.info = {
  11684. render: _infoRender,
  11685. memory: _infoMemory,
  11686. programs: _programs
  11687. };
  11688. // initialize
  11689. var _gl;
  11690. try {
  11691. var attributes = {
  11692. alpha: _alpha,
  11693. depth: _depth,
  11694. stencil: _stencil,
  11695. antialias: _antialias,
  11696. premultipliedAlpha: _premultipliedAlpha,
  11697. preserveDrawingBuffer: _preserveDrawingBuffer
  11698. };
  11699. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  11700. if ( _gl === null ) {
  11701. if ( _canvas.getContext( 'webgl' ) !== null ) {
  11702. throw 'Error creating WebGL context with your selected attributes.';
  11703. } else {
  11704. throw 'Error creating WebGL context.';
  11705. }
  11706. }
  11707. _canvas.addEventListener( 'webglcontextlost', function ( event ) {
  11708. event.preventDefault();
  11709. resetGLState();
  11710. setDefaultGLState();
  11711. objects.clear();
  11712. properties.clear();
  11713. }, false );
  11714. } catch ( error ) {
  11715. console.error( 'THREE.WebGLRenderer: ' + error );
  11716. }
  11717. var state = new THREE.WebGLState( _gl, paramThreeToGL );
  11718. if ( _gl.getShaderPrecisionFormat === undefined ) {
  11719. _gl.getShaderPrecisionFormat = function () {
  11720. return {
  11721. 'rangeMin': 1,
  11722. 'rangeMax': 1,
  11723. 'precision': 1
  11724. };
  11725. }
  11726. }
  11727. var properties = new THREE.WebGLProperties();
  11728. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  11729. var extensions = new THREE.WebGLExtensions( _gl );
  11730. extensions.get( 'OES_texture_float' );
  11731. extensions.get( 'OES_texture_float_linear' );
  11732. extensions.get( 'OES_texture_half_float' );
  11733. extensions.get( 'OES_texture_half_float_linear' );
  11734. extensions.get( 'OES_standard_derivatives' );
  11735. extensions.get( 'ANGLE_instanced_arrays' );
  11736. if ( extensions.get( 'OES_element_index_uint' ) ) {
  11737. THREE.BufferGeometry.MaxIndex = 4294967296;
  11738. }
  11739. if ( _logarithmicDepthBuffer ) {
  11740. extensions.get( 'EXT_frag_depth' );
  11741. }
  11742. //
  11743. function glClearColor( r, g, b, a ) {
  11744. if ( _premultipliedAlpha === true ) {
  11745. r *= a; g *= a; b *= a;
  11746. }
  11747. _gl.clearColor( r, g, b, a );
  11748. }
  11749. function setDefaultGLState() {
  11750. state.init();
  11751. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11752. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11753. }
  11754. function resetGLState() {
  11755. _currentProgram = null;
  11756. _currentCamera = null;
  11757. _currentGeometryProgram = '';
  11758. _currentMaterialId = - 1;
  11759. _lightsNeedUpdate = true;
  11760. state.reset();
  11761. }
  11762. setDefaultGLState();
  11763. this.context = _gl;
  11764. this.extensions = extensions;
  11765. this.state = state;
  11766. // shadow map
  11767. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  11768. this.shadowMap = shadowMap;
  11769. // GPU capabilities
  11770. var _maxTextures = _gl.getParameter( _gl.MAX_TEXTURE_IMAGE_UNITS );
  11771. var _maxVertexTextures = _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  11772. var _maxTextureSize = _gl.getParameter( _gl.MAX_TEXTURE_SIZE );
  11773. var _maxCubemapSize = _gl.getParameter( _gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  11774. var _supportsVertexTextures = _maxVertexTextures > 0;
  11775. var _supportsBoneTextures = _supportsVertexTextures && extensions.get( 'OES_texture_float' );
  11776. var _supportsInstancedArrays = extensions.get( 'ANGLE_instanced_arrays' );
  11777. //
  11778. var _vertexShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.HIGH_FLOAT );
  11779. var _vertexShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.MEDIUM_FLOAT );
  11780. var _fragmentShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.HIGH_FLOAT );
  11781. var _fragmentShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.MEDIUM_FLOAT );
  11782. var getCompressedTextureFormats = ( function () {
  11783. var array;
  11784. return function getCompressedTextureFormats() {
  11785. if ( array !== undefined ) {
  11786. return array;
  11787. }
  11788. array = [];
  11789. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) || extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  11790. var formats = _gl.getParameter( _gl.COMPRESSED_TEXTURE_FORMATS );
  11791. for ( var i = 0; i < formats.length; i ++ ) {
  11792. array.push( formats[ i ] );
  11793. }
  11794. }
  11795. return array;
  11796. };
  11797. } )();
  11798. // clamp precision to maximum available
  11799. var highpAvailable = _vertexShaderPrecisionHighpFloat.precision > 0 && _fragmentShaderPrecisionHighpFloat.precision > 0;
  11800. var mediumpAvailable = _vertexShaderPrecisionMediumpFloat.precision > 0 && _fragmentShaderPrecisionMediumpFloat.precision > 0;
  11801. if ( _precision === 'highp' && ! highpAvailable ) {
  11802. if ( mediumpAvailable ) {
  11803. _precision = 'mediump';
  11804. console.warn( 'THREE.WebGLRenderer: highp not supported, using mediump.' );
  11805. } else {
  11806. _precision = 'lowp';
  11807. console.warn( 'THREE.WebGLRenderer: highp and mediump not supported, using lowp.' );
  11808. }
  11809. }
  11810. if ( _precision === 'mediump' && ! mediumpAvailable ) {
  11811. _precision = 'lowp';
  11812. console.warn( 'THREE.WebGLRenderer: mediump not supported, using lowp.' );
  11813. }
  11814. // Plugins
  11815. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  11816. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  11817. // API
  11818. this.getContext = function () {
  11819. return _gl;
  11820. };
  11821. this.getContextAttributes = function () {
  11822. return _gl.getContextAttributes();
  11823. };
  11824. this.forceContextLoss = function () {
  11825. extensions.get( 'WEBGL_lose_context' ).loseContext();
  11826. };
  11827. this.supportsVertexTextures = function () {
  11828. return _supportsVertexTextures;
  11829. };
  11830. this.supportsInstancedArrays = function () {
  11831. return _supportsInstancedArrays;
  11832. };
  11833. this.supportsFloatTextures = function () {
  11834. return extensions.get( 'OES_texture_float' );
  11835. };
  11836. this.supportsHalfFloatTextures = function () {
  11837. return extensions.get( 'OES_texture_half_float' );
  11838. };
  11839. this.supportsStandardDerivatives = function () {
  11840. return extensions.get( 'OES_standard_derivatives' );
  11841. };
  11842. this.supportsCompressedTextureS3TC = function () {
  11843. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  11844. };
  11845. this.supportsCompressedTexturePVRTC = function () {
  11846. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  11847. };
  11848. this.supportsBlendMinMax = function () {
  11849. return extensions.get( 'EXT_blend_minmax' );
  11850. };
  11851. this.getMaxAnisotropy = ( function () {
  11852. var value;
  11853. return function getMaxAnisotropy() {
  11854. if ( value !== undefined ) return value;
  11855. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  11856. if ( extension !== null ) {
  11857. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  11858. } else {
  11859. value = 0;
  11860. }
  11861. return value;
  11862. }
  11863. } )();
  11864. this.getPrecision = function () {
  11865. return _precision;
  11866. };
  11867. this.getPixelRatio = function () {
  11868. return pixelRatio;
  11869. };
  11870. this.setPixelRatio = function ( value ) {
  11871. if ( value !== undefined ) pixelRatio = value;
  11872. };
  11873. this.getSize = function () {
  11874. return {
  11875. width: _width,
  11876. height: _height
  11877. };
  11878. };
  11879. this.setSize = function ( width, height, updateStyle ) {
  11880. _width = width;
  11881. _height = height;
  11882. _canvas.width = width * pixelRatio;
  11883. _canvas.height = height * pixelRatio;
  11884. if ( updateStyle !== false ) {
  11885. _canvas.style.width = width + 'px';
  11886. _canvas.style.height = height + 'px';
  11887. }
  11888. this.setViewport( 0, 0, width, height );
  11889. };
  11890. this.setViewport = function ( x, y, width, height ) {
  11891. _viewportX = x * pixelRatio;
  11892. _viewportY = y * pixelRatio;
  11893. _viewportWidth = width * pixelRatio;
  11894. _viewportHeight = height * pixelRatio;
  11895. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11896. };
  11897. this.setScissor = function ( x, y, width, height ) {
  11898. _gl.scissor(
  11899. x * pixelRatio,
  11900. y * pixelRatio,
  11901. width * pixelRatio,
  11902. height * pixelRatio
  11903. );
  11904. };
  11905. this.enableScissorTest = function ( boolean ) {
  11906. state.setScissorTest( boolean );
  11907. };
  11908. // Clearing
  11909. this.getClearColor = function () {
  11910. return _clearColor;
  11911. };
  11912. this.setClearColor = function ( color, alpha ) {
  11913. _clearColor.set( color );
  11914. _clearAlpha = alpha !== undefined ? alpha : 1;
  11915. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11916. };
  11917. this.getClearAlpha = function () {
  11918. return _clearAlpha;
  11919. };
  11920. this.setClearAlpha = function ( alpha ) {
  11921. _clearAlpha = alpha;
  11922. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11923. };
  11924. this.clear = function ( color, depth, stencil ) {
  11925. var bits = 0;
  11926. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  11927. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  11928. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  11929. _gl.clear( bits );
  11930. };
  11931. this.clearColor = function () {
  11932. _gl.clear( _gl.COLOR_BUFFER_BIT );
  11933. };
  11934. this.clearDepth = function () {
  11935. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  11936. };
  11937. this.clearStencil = function () {
  11938. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  11939. };
  11940. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  11941. this.setRenderTarget( renderTarget );
  11942. this.clear( color, depth, stencil );
  11943. };
  11944. // Reset
  11945. this.resetGLState = resetGLState;
  11946. // Events
  11947. function onTextureDispose( event ) {
  11948. var texture = event.target;
  11949. texture.removeEventListener( 'dispose', onTextureDispose );
  11950. deallocateTexture( texture );
  11951. _infoMemory.textures --;
  11952. }
  11953. function onRenderTargetDispose( event ) {
  11954. var renderTarget = event.target;
  11955. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  11956. deallocateRenderTarget( renderTarget );
  11957. _infoMemory.textures --;
  11958. }
  11959. function onMaterialDispose( event ) {
  11960. var material = event.target;
  11961. material.removeEventListener( 'dispose', onMaterialDispose );
  11962. deallocateMaterial( material );
  11963. }
  11964. // Buffer deallocation
  11965. function deallocateTexture( texture ) {
  11966. var textureProperties = properties.get( texture );
  11967. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  11968. // cube texture
  11969. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  11970. } else {
  11971. // 2D texture
  11972. if ( textureProperties.__webglInit === undefined ) return;
  11973. _gl.deleteTexture( textureProperties.__webglTexture );
  11974. }
  11975. // remove all webgl properties
  11976. properties.delete( texture );
  11977. }
  11978. function deallocateRenderTarget( renderTarget ) {
  11979. var renderTargetProperties = properties.get( renderTarget );
  11980. if ( ! renderTarget || renderTargetProperties.__webglTexture === undefined ) return;
  11981. _gl.deleteTexture( renderTargetProperties.__webglTexture );
  11982. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  11983. for ( var i = 0; i < 6; i ++ ) {
  11984. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  11985. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  11986. }
  11987. } else {
  11988. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  11989. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  11990. }
  11991. properties.delete( renderTarget );
  11992. }
  11993. function deallocateMaterial( material ) {
  11994. releaseMaterialProgramReference( material );
  11995. properties.delete( material );
  11996. }
  11997. function releaseMaterialProgramReference( material ) {
  11998. var program = properties.get( material ).program.program;
  11999. if ( program === undefined ) return;
  12000. material.program = undefined;
  12001. for ( var i = 0, n = _programs.length; i !== n; ++ i ) {
  12002. var programInfo = _programs[ i ];
  12003. if ( programInfo.program === program ) {
  12004. var newReferenceCount = -- programInfo.usedTimes;
  12005. if ( newReferenceCount === 0 ) {
  12006. // the last meterial that has been using the program let
  12007. // go of it, so remove it from the (unordered) _programs
  12008. // set and deallocate the GL resource
  12009. var newLength = n - 1;
  12010. _programs[ i ] = _programs[ newLength ];
  12011. _programs.pop();
  12012. _gl.deleteProgram( program );
  12013. _infoMemory.programs = newLength;
  12014. }
  12015. break;
  12016. }
  12017. }
  12018. }
  12019. // Buffer rendering
  12020. this.renderBufferImmediate = function ( object, program, material ) {
  12021. state.initAttributes();
  12022. var objectProperties = properties.get( object );
  12023. if ( object.hasPositions && ! objectProperties.__webglVertexBuffer ) objectProperties.__webglVertexBuffer = _gl.createBuffer();
  12024. if ( object.hasNormals && ! objectProperties.__webglNormalBuffer ) objectProperties.__webglNormalBuffer = _gl.createBuffer();
  12025. if ( object.hasUvs && ! objectProperties.__webglUvBuffer ) objectProperties.__webglUvBuffer = _gl.createBuffer();
  12026. if ( object.hasColors && ! objectProperties.__webglColorBuffer ) objectProperties.__webglColorBuffer = _gl.createBuffer();
  12027. var attributes = program.getAttributes();
  12028. if ( object.hasPositions ) {
  12029. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglVertexBuffer );
  12030. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  12031. state.enableAttribute( attributes.position );
  12032. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  12033. }
  12034. if ( object.hasNormals ) {
  12035. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglNormalBuffer );
  12036. if ( material instanceof THREE.MeshPhongMaterial === false && material.shading === THREE.FlatShading ) {
  12037. var nx, ny, nz,
  12038. nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
  12039. normalArray,
  12040. i, il = object.count * 3;
  12041. for ( i = 0; i < il; i += 9 ) {
  12042. normalArray = object.normalArray;
  12043. nax = normalArray[ i ];
  12044. nay = normalArray[ i + 1 ];
  12045. naz = normalArray[ i + 2 ];
  12046. nbx = normalArray[ i + 3 ];
  12047. nby = normalArray[ i + 4 ];
  12048. nbz = normalArray[ i + 5 ];
  12049. ncx = normalArray[ i + 6 ];
  12050. ncy = normalArray[ i + 7 ];
  12051. ncz = normalArray[ i + 8 ];
  12052. nx = ( nax + nbx + ncx ) / 3;
  12053. ny = ( nay + nby + ncy ) / 3;
  12054. nz = ( naz + nbz + ncz ) / 3;
  12055. normalArray[ i ] = nx;
  12056. normalArray[ i + 1 ] = ny;
  12057. normalArray[ i + 2 ] = nz;
  12058. normalArray[ i + 3 ] = nx;
  12059. normalArray[ i + 4 ] = ny;
  12060. normalArray[ i + 5 ] = nz;
  12061. normalArray[ i + 6 ] = nx;
  12062. normalArray[ i + 7 ] = ny;
  12063. normalArray[ i + 8 ] = nz;
  12064. }
  12065. }
  12066. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  12067. state.enableAttribute( attributes.normal );
  12068. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  12069. }
  12070. if ( object.hasUvs && material.map ) {
  12071. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglUvBuffer );
  12072. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  12073. state.enableAttribute( attributes.uv );
  12074. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  12075. }
  12076. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  12077. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglColorBuffer );
  12078. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  12079. state.enableAttribute( attributes.color );
  12080. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  12081. }
  12082. state.disableUnusedAttributes();
  12083. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  12084. object.count = 0;
  12085. };
  12086. this.renderBufferDirect = function ( camera, lights, fog, material, object ) {
  12087. if ( material instanceof THREE.MeshFaceMaterial ) {
  12088. var materials = material.materials;
  12089. for ( var i = 0, il = materials.length; i < il; i ++ ) {
  12090. _this.renderBufferDirect( camera, lights, fog, materials[ i ], object );
  12091. }
  12092. return;
  12093. }
  12094. if ( material.visible === false ) return;
  12095. setMaterial( material );
  12096. var geometry = objects.geometries.get( object );
  12097. var program = setProgram( camera, lights, fog, material, object );
  12098. var updateBuffers = false,
  12099. wireframeBit = material.wireframe ? 1 : 0,
  12100. geometryProgram = geometry.id + '_' + program.id + '_' + wireframeBit;
  12101. if ( geometryProgram !== _currentGeometryProgram ) {
  12102. _currentGeometryProgram = geometryProgram;
  12103. updateBuffers = true;
  12104. }
  12105. // morph targets
  12106. var morphTargetInfluences = object.morphTargetInfluences;
  12107. if ( morphTargetInfluences !== undefined ) {
  12108. var activeInfluences = [];
  12109. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  12110. var influence = morphTargetInfluences[ i ];
  12111. activeInfluences.push( [ influence, i ] );
  12112. }
  12113. activeInfluences.sort( numericalSort );
  12114. if ( activeInfluences.length > 8 ) {
  12115. activeInfluences.length = 8;
  12116. }
  12117. var morphAttributes = geometry.morphAttributes;
  12118. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  12119. var influence = activeInfluences[ i ];
  12120. morphInfluences[ i ] = influence[ 0 ];
  12121. if ( influence[ 0 ] !== 0 ) {
  12122. var index = influence[ 1 ];
  12123. if ( material.morphTargets === true ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  12124. if ( material.morphNormals === true ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  12125. } else {
  12126. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  12127. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  12128. }
  12129. }
  12130. var uniforms = program.getUniforms();
  12131. if ( uniforms.morphTargetInfluences !== null ) {
  12132. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  12133. }
  12134. updateBuffers = true;
  12135. }
  12136. if ( object instanceof THREE.Mesh ) {
  12137. renderMesh( material, geometry, object, program, updateBuffers );
  12138. } else if ( object instanceof THREE.Line ) {
  12139. renderLine( material, geometry, object, program, updateBuffers );
  12140. } else if ( object instanceof THREE.PointCloud ) {
  12141. renderPointCloud( material, geometry, object, program, updateBuffers );
  12142. }
  12143. };
  12144. function setupVertexAttributes( material, program, geometry, startIndex ) {
  12145. var extension;
  12146. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  12147. extension = extensions.get( 'ANGLE_instanced_arrays' );
  12148. if ( extension === null ) {
  12149. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12150. return;
  12151. }
  12152. }
  12153. state.initAttributes();
  12154. var geometryAttributes = geometry.attributes;
  12155. var programAttributes = program.getAttributes();
  12156. var materialDefaultAttributeValues = material.defaultAttributeValues;
  12157. for ( var name in programAttributes ) {
  12158. var programAttribute = programAttributes[ name ];
  12159. if ( programAttribute >= 0 ) {
  12160. var geometryAttribute = geometryAttributes[ name ];
  12161. if ( geometryAttribute !== undefined ) {
  12162. state.enableAttribute( programAttribute );
  12163. var size = geometryAttribute.itemSize;
  12164. var buffer = objects.getAttributeBuffer( geometryAttribute );
  12165. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  12166. var data = geometryAttribute.data;
  12167. var stride = data.stride;
  12168. var offset = geometryAttribute.offset;
  12169. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12170. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  12171. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  12172. if ( extension === null ) {
  12173. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  12174. return;
  12175. }
  12176. extension.vertexAttribDivisorANGLE( programAttribute, data.meshPerAttribute );
  12177. if ( geometry.maxInstancedCount === undefined ) {
  12178. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  12179. }
  12180. }
  12181. } else {
  12182. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12183. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  12184. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  12185. if ( extension === null ) {
  12186. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  12187. return;
  12188. }
  12189. extension.vertexAttribDivisorANGLE( programAttribute, geometryAttribute.meshPerAttribute );
  12190. if ( geometry.maxInstancedCount === undefined ) {
  12191. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  12192. }
  12193. }
  12194. }
  12195. } else if ( materialDefaultAttributeValues !== undefined ) {
  12196. var value = materialDefaultAttributeValues[ name ];
  12197. if ( value !== undefined ) {
  12198. switch ( value.length ) {
  12199. case 2:
  12200. _gl.vertexAttrib2fv( programAttribute, value );
  12201. break;
  12202. case 3:
  12203. _gl.vertexAttrib3fv( programAttribute, value );
  12204. break;
  12205. case 4:
  12206. _gl.vertexAttrib4fv( programAttribute, value );
  12207. break;
  12208. default:
  12209. _gl.vertexAttrib1fv( programAttribute, value );
  12210. }
  12211. }
  12212. }
  12213. }
  12214. }
  12215. state.disableUnusedAttributes();
  12216. }
  12217. function renderMesh( material, geometry, object, program, updateBuffers ) {
  12218. var mode = _gl.TRIANGLES;
  12219. if ( material.wireframe === true ) {
  12220. mode = _gl.LINES;
  12221. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  12222. }
  12223. var index = geometry.attributes.index;
  12224. if ( index ) {
  12225. // indexed triangles
  12226. var type, size;
  12227. var indexBuffer = objects.getAttributeBuffer( index );
  12228. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12229. type = _gl.UNSIGNED_INT;
  12230. size = 4;
  12231. } else {
  12232. type = _gl.UNSIGNED_SHORT;
  12233. size = 2;
  12234. }
  12235. var offsets = geometry.drawcalls;
  12236. if ( offsets.length === 0 ) {
  12237. if ( updateBuffers ) {
  12238. setupVertexAttributes( material, program, geometry, 0 );
  12239. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12240. }
  12241. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12242. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12243. if ( extension === null ) {
  12244. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12245. return;
  12246. }
  12247. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount ); // Draw the instanced meshes
  12248. } else {
  12249. _gl.drawElements( mode, index.array.length, type, 0 );
  12250. }
  12251. _infoRender.calls ++;
  12252. _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
  12253. _infoRender.faces += index.array.length / 3;
  12254. } else {
  12255. // if there is more than 1 chunk
  12256. // must set attribute pointers to use new offsets for each chunk
  12257. // even if geometry and materials didn't change
  12258. updateBuffers = true;
  12259. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12260. var startIndex = offsets[ i ].index;
  12261. if ( updateBuffers ) {
  12262. setupVertexAttributes( material, program, geometry, startIndex );
  12263. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12264. }
  12265. // render indexed triangles
  12266. if ( geometry instanceof THREE.InstancedBufferGeometry && offsets[ i ].instances > 0 ) {
  12267. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12268. if ( extension === null ) {
  12269. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12270. return;
  12271. }
  12272. extension.drawElementsInstancedANGLE( mode, offsets[ i ].count, type, offsets[ i ].start * size, offsets[ i ].count, type, offsets[ i ].instances ); // Draw the instanced meshes
  12273. } else {
  12274. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12275. }
  12276. _infoRender.calls ++;
  12277. _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12278. _infoRender.faces += offsets[ i ].count / 3;
  12279. }
  12280. }
  12281. } else {
  12282. // non-indexed triangles
  12283. var offsets = geometry.drawcalls;
  12284. if ( offsets.length === 0 ) {
  12285. if ( updateBuffers ) {
  12286. setupVertexAttributes( material, program, geometry, 0 );
  12287. }
  12288. var position = geometry.attributes.position;
  12289. // render non-indexed triangles
  12290. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12291. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12292. if ( extension === null ) {
  12293. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12294. return;
  12295. }
  12296. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12297. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount ); // Draw the instanced meshes
  12298. } else {
  12299. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount ); // Draw the instanced meshes
  12300. }
  12301. } else {
  12302. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12303. _gl.drawArrays( mode, 0, position.data.count );
  12304. } else {
  12305. _gl.drawArrays( mode, 0, position.count );
  12306. }
  12307. }
  12308. _infoRender.calls ++;
  12309. _infoRender.vertices += position.count;
  12310. _infoRender.faces += position.array.length / 3;
  12311. } else {
  12312. // if there is more than 1 chunk
  12313. // must set attribute pointers to use new offsets for each chunk
  12314. // even if geometry and materials didn't change
  12315. if ( updateBuffers ) {
  12316. setupVertexAttributes( material, program, geometry, 0 );
  12317. }
  12318. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12319. // render non-indexed triangles
  12320. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  12321. console.error( 'THREE.WebGLRenderer.renderMesh: cannot use drawCalls with THREE.InstancedBufferGeometry.' );
  12322. return;
  12323. } else {
  12324. _gl.drawArrays( mode, offsets[ i ].start, offsets[ i ].count );
  12325. }
  12326. _infoRender.calls ++;
  12327. _infoRender.vertices += offsets[ i ].count;
  12328. _infoRender.faces += ( offsets[ i ].count ) / 3;
  12329. }
  12330. }
  12331. }
  12332. }
  12333. function renderLine( material, geometry, object, program, updateBuffers ) {
  12334. var mode = object instanceof THREE.LineSegments ? _gl.LINES : _gl.LINE_STRIP;
  12335. // In case user is not using Line*Material by mistake
  12336. var lineWidth = material.linewidth !== undefined ? material.linewidth : 1;
  12337. state.setLineWidth( lineWidth * pixelRatio );
  12338. var index = geometry.attributes.index;
  12339. if ( index ) {
  12340. // indexed lines
  12341. var type, size;
  12342. var indexBuffer = objects.getAttributeBuffer( index );
  12343. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12344. type = _gl.UNSIGNED_INT;
  12345. size = 4;
  12346. } else {
  12347. type = _gl.UNSIGNED_SHORT;
  12348. size = 2;
  12349. }
  12350. var offsets = geometry.drawcalls;
  12351. if ( offsets.length === 0 ) {
  12352. if ( updateBuffers ) {
  12353. setupVertexAttributes( material, program, geometry, 0 );
  12354. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12355. }
  12356. _gl.drawElements( mode, index.array.length, type, 0 ); // 2 bytes per Uint16Array
  12357. _infoRender.calls ++;
  12358. _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
  12359. } else {
  12360. // if there is more than 1 chunk
  12361. // must set attribute pointers to use new offsets for each chunk
  12362. // even if geometry and materials didn't change
  12363. if ( offsets.length > 1 ) updateBuffers = true;
  12364. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12365. var startIndex = offsets[ i ].index;
  12366. if ( updateBuffers ) {
  12367. setupVertexAttributes( material, program, geometry, startIndex );
  12368. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12369. }
  12370. // render indexed lines
  12371. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size ); // 2 bytes per Uint16Array
  12372. _infoRender.calls ++;
  12373. _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12374. }
  12375. }
  12376. } else {
  12377. // non-indexed lines
  12378. if ( updateBuffers ) {
  12379. setupVertexAttributes( material, program, geometry, 0 );
  12380. }
  12381. var position = geometry.attributes.position;
  12382. var offsets = geometry.drawcalls;
  12383. if ( offsets.length === 0 ) {
  12384. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12385. _infoRender.calls ++;
  12386. _infoRender.vertices += position.array.length / 3;
  12387. } else {
  12388. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12389. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12390. _infoRender.calls ++;
  12391. _infoRender.vertices += offsets[ i ].count;
  12392. }
  12393. }
  12394. }
  12395. }
  12396. function renderPointCloud( material, geometry, object, program, updateBuffers ) {
  12397. var mode = _gl.POINTS;
  12398. var index = geometry.attributes.index;
  12399. if ( index ) {
  12400. // indexed points
  12401. var type, size;
  12402. var indexBuffer = objects.getAttributeBuffer( index );
  12403. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12404. type = _gl.UNSIGNED_INT;
  12405. size = 4;
  12406. } else {
  12407. type = _gl.UNSIGNED_SHORT;
  12408. size = 2;
  12409. }
  12410. var offsets = geometry.drawcalls;
  12411. if ( offsets.length === 0 ) {
  12412. if ( updateBuffers ) {
  12413. setupVertexAttributes( material, program, geometry, 0 );
  12414. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12415. }
  12416. _gl.drawElements( mode, index.array.length, type, 0 );
  12417. _infoRender.calls ++;
  12418. _infoRender.points += index.array.length;
  12419. } else {
  12420. // if there is more than 1 chunk
  12421. // must set attribute pointers to use new offsets for each chunk
  12422. // even if geometry and materials didn't change
  12423. if ( offsets.length > 1 ) updateBuffers = true;
  12424. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12425. var startIndex = offsets[ i ].index;
  12426. if ( updateBuffers ) {
  12427. setupVertexAttributes( material, program, geometry, startIndex );
  12428. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12429. }
  12430. // render indexed points
  12431. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12432. _infoRender.calls ++;
  12433. _infoRender.points += offsets[ i ].count;
  12434. }
  12435. }
  12436. } else {
  12437. // non-indexed points
  12438. if ( updateBuffers ) {
  12439. setupVertexAttributes( material, program, geometry, 0 );
  12440. }
  12441. var position = geometry.attributes.position;
  12442. var offsets = geometry.drawcalls;
  12443. if ( offsets.length === 0 ) {
  12444. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12445. _infoRender.calls ++;
  12446. _infoRender.points += position.array.length / 3;
  12447. } else {
  12448. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12449. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12450. _infoRender.calls ++;
  12451. _infoRender.points += offsets[ i ].count;
  12452. }
  12453. }
  12454. }
  12455. }
  12456. // Sorting
  12457. function numericalSort ( a, b ) {
  12458. return b[ 0 ] - a[ 0 ];
  12459. }
  12460. function painterSortStable ( a, b ) {
  12461. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12462. return a.object.renderOrder - b.object.renderOrder;
  12463. } else if ( a.object.material.id !== b.object.material.id ) {
  12464. return a.object.material.id - b.object.material.id;
  12465. } else if ( a.z !== b.z ) {
  12466. return a.z - b.z;
  12467. } else {
  12468. return a.id - b.id;
  12469. }
  12470. }
  12471. function reversePainterSortStable ( a, b ) {
  12472. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12473. return a.object.renderOrder - b.object.renderOrder;
  12474. } if ( a.z !== b.z ) {
  12475. return b.z - a.z;
  12476. } else {
  12477. return a.id - b.id;
  12478. }
  12479. }
  12480. // Rendering
  12481. this.render = function ( scene, camera, renderTarget, forceClear ) {
  12482. if ( camera instanceof THREE.Camera === false ) {
  12483. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  12484. return;
  12485. }
  12486. var fog = scene.fog;
  12487. // reset caching for this frame
  12488. _currentGeometryProgram = '';
  12489. _currentMaterialId = - 1;
  12490. _currentCamera = null;
  12491. _lightsNeedUpdate = true;
  12492. // update scene graph
  12493. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  12494. // update camera matrices and frustum
  12495. if ( camera.parent === undefined ) camera.updateMatrixWorld();
  12496. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12497. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  12498. _frustum.setFromMatrix( _projScreenMatrix );
  12499. lights.length = 0;
  12500. opaqueObjects.length = 0;
  12501. transparentObjects.length = 0;
  12502. opaqueImmediateObjects.length = 0;
  12503. transparentImmediateObjects.length = 0;
  12504. sprites.length = 0;
  12505. lensFlares.length = 0;
  12506. projectObject( scene );
  12507. if ( _this.sortObjects === true ) {
  12508. opaqueObjects.sort( painterSortStable );
  12509. transparentObjects.sort( reversePainterSortStable );
  12510. }
  12511. objects.update( opaqueObjects );
  12512. objects.update( transparentObjects );
  12513. //
  12514. shadowMap.render( scene, camera );
  12515. //
  12516. _infoRender.calls = 0;
  12517. _infoRender.vertices = 0;
  12518. _infoRender.faces = 0;
  12519. _infoRender.points = 0;
  12520. this.setRenderTarget( renderTarget );
  12521. if ( this.autoClear || forceClear ) {
  12522. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  12523. }
  12524. //
  12525. if ( scene.overrideMaterial ) {
  12526. var overrideMaterial = scene.overrideMaterial;
  12527. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  12528. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  12529. renderObjectsImmediate( opaqueImmediateObjects, camera, lights, fog, overrideMaterial );
  12530. renderObjectsImmediate( transparentImmediateObjects, camera, lights, fog, overrideMaterial );
  12531. } else {
  12532. // opaque pass (front-to-back order)
  12533. state.setBlending( THREE.NoBlending );
  12534. renderObjects( opaqueObjects, camera, lights, fog, null );
  12535. renderObjectsImmediate( opaqueImmediateObjects, camera, lights, fog, null );
  12536. // transparent pass (back-to-front order)
  12537. renderObjects( transparentObjects, camera, lights, fog, null );
  12538. renderObjectsImmediate( transparentImmediateObjects, camera, lights, fog, null );
  12539. }
  12540. // custom render plugins (post pass)
  12541. spritePlugin.render( scene, camera );
  12542. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  12543. // Generate mipmap if we're using any kind of mipmap filtering
  12544. if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
  12545. updateRenderTargetMipmap( renderTarget );
  12546. }
  12547. // Ensure depth buffer writing is enabled so it can be cleared on next render
  12548. state.setDepthTest( true );
  12549. state.setDepthWrite( true );
  12550. state.setColorWrite( true );
  12551. // _gl.finish();
  12552. };
  12553. function projectObject( object ) {
  12554. if ( object.visible === true ) {
  12555. if ( object instanceof THREE.Scene || object instanceof THREE.Group ) {
  12556. // skip
  12557. } else {
  12558. // update Skeleton objects
  12559. if ( object instanceof THREE.SkinnedMesh ) {
  12560. object.skeleton.update();
  12561. }
  12562. objects.init( object );
  12563. if ( object instanceof THREE.Light ) {
  12564. lights.push( object );
  12565. } else if ( object instanceof THREE.Sprite ) {
  12566. sprites.push( object );
  12567. } else if ( object instanceof THREE.LensFlare ) {
  12568. lensFlares.push( object );
  12569. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  12570. var material = object.material;
  12571. if ( material.transparent ) {
  12572. transparentImmediateObjects.push( object );
  12573. } else {
  12574. opaqueImmediateObjects.push( object );
  12575. }
  12576. } else {
  12577. var webglObject = objects.objects[ object.id ];
  12578. if ( webglObject && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  12579. var material = object.material;
  12580. if ( properties.get( material ) ) {
  12581. material.program = properties.get( material ).program;
  12582. }
  12583. if ( material.transparent ) {
  12584. transparentObjects.push( webglObject );
  12585. } else {
  12586. opaqueObjects.push( webglObject );
  12587. }
  12588. if ( _this.sortObjects === true ) {
  12589. _vector3.setFromMatrixPosition( object.matrixWorld );
  12590. _vector3.applyProjection( _projScreenMatrix );
  12591. webglObject.z = _vector3.z;
  12592. }
  12593. }
  12594. }
  12595. }
  12596. for ( var i = 0, l = object.children.length; i < l; i ++ ) {
  12597. projectObject( object.children[ i ] );
  12598. }
  12599. }
  12600. }
  12601. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  12602. var material = overrideMaterial;
  12603. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12604. var webglObject = renderList[ i ];
  12605. var object = webglObject.object;
  12606. setupMatrices( object, camera );
  12607. if ( overrideMaterial === null ) material = object.material;
  12608. _this.renderBufferDirect( camera, lights, fog, material, object );
  12609. }
  12610. }
  12611. function renderObjectsImmediate( renderList, camera, lights, fog, overrideMaterial ) {
  12612. var material = overrideMaterial;
  12613. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12614. var object = renderList[ i ];
  12615. setupMatrices( object, camera );
  12616. if ( object.visible === true ) {
  12617. if ( overrideMaterial === null ) material = object.material;
  12618. _this.renderImmediateObject( camera, lights, fog, material, object );
  12619. }
  12620. }
  12621. }
  12622. this.renderImmediateObject = function ( camera, lights, fog, material, object ) {
  12623. setMaterial( material );
  12624. var program = setProgram( camera, lights, fog, material, object );
  12625. _currentGeometryProgram = '';
  12626. object.render( function ( object ) {
  12627. _this.renderBufferImmediate( object, program, material );
  12628. } );
  12629. };
  12630. // Materials
  12631. var shaderIDs = {
  12632. MeshDepthMaterial: 'depth',
  12633. MeshNormalMaterial: 'normal',
  12634. MeshBasicMaterial: 'basic',
  12635. MeshLambertMaterial: 'lambert',
  12636. MeshPhongMaterial: 'phong',
  12637. LineBasicMaterial: 'basic',
  12638. LineDashedMaterial: 'dashed',
  12639. PointCloudMaterial: 'particle_basic'
  12640. };
  12641. function initMaterial( material, lights, fog, object ) {
  12642. var materialProperties = properties.get( material );
  12643. var shaderID = shaderIDs[ material.type ];
  12644. // heuristics to create shader parameters according to lights in the scene
  12645. // (not to blow over maxLights budget)
  12646. var maxLightCount = allocateLights( lights );
  12647. var maxShadows = allocateShadows( lights );
  12648. var maxBones = allocateBones( object );
  12649. var parameters = {
  12650. precision: _precision,
  12651. supportsVertexTextures: _supportsVertexTextures,
  12652. map: !! material.map,
  12653. envMap: !! material.envMap,
  12654. envMapMode: material.envMap && material.envMap.mapping,
  12655. lightMap: !! material.lightMap,
  12656. aoMap: !! material.aoMap,
  12657. emissiveMap: !! material.emissiveMap,
  12658. bumpMap: !! material.bumpMap,
  12659. normalMap: !! material.normalMap,
  12660. specularMap: !! material.specularMap,
  12661. alphaMap: !! material.alphaMap,
  12662. combine: material.combine,
  12663. vertexColors: material.vertexColors,
  12664. fog: fog,
  12665. useFog: material.fog,
  12666. fogExp: fog instanceof THREE.FogExp2,
  12667. flatShading: material.shading === THREE.FlatShading,
  12668. sizeAttenuation: material.sizeAttenuation,
  12669. logarithmicDepthBuffer: _logarithmicDepthBuffer,
  12670. skinning: material.skinning,
  12671. maxBones: maxBones,
  12672. useVertexTexture: _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  12673. morphTargets: material.morphTargets,
  12674. morphNormals: material.morphNormals,
  12675. maxMorphTargets: _this.maxMorphTargets,
  12676. maxMorphNormals: _this.maxMorphNormals,
  12677. maxDirLights: maxLightCount.directional,
  12678. maxPointLights: maxLightCount.point,
  12679. maxSpotLights: maxLightCount.spot,
  12680. maxHemiLights: maxLightCount.hemi,
  12681. maxShadows: maxShadows,
  12682. shadowMapEnabled: shadowMap.enabled && object.receiveShadow && maxShadows > 0,
  12683. shadowMapType: shadowMap.type,
  12684. shadowMapDebug: shadowMap.debug,
  12685. alphaTest: material.alphaTest,
  12686. metal: material.metal,
  12687. doubleSided: material.side === THREE.DoubleSide,
  12688. flipSided: material.side === THREE.BackSide
  12689. };
  12690. // Generate code
  12691. var chunks = [];
  12692. if ( shaderID ) {
  12693. chunks.push( shaderID );
  12694. } else {
  12695. chunks.push( material.fragmentShader );
  12696. chunks.push( material.vertexShader );
  12697. }
  12698. if ( material.defines !== undefined ) {
  12699. for ( var name in material.defines ) {
  12700. chunks.push( name );
  12701. chunks.push( material.defines[ name ] );
  12702. }
  12703. }
  12704. for ( var name in parameters ) {
  12705. chunks.push( name );
  12706. chunks.push( parameters[ name ] );
  12707. }
  12708. var code = chunks.join();
  12709. var programChange = true;
  12710. if ( ! materialProperties.program ) {
  12711. // new material
  12712. material.addEventListener( 'dispose', onMaterialDispose );
  12713. } else if ( materialProperties.program.code !== code ) {
  12714. // changed glsl or parameters
  12715. releaseMaterialProgramReference( material );
  12716. } else if ( shaderID !== undefined ) {
  12717. // same glsl and uniform list
  12718. return;
  12719. } else {
  12720. // only rebuild uniform list
  12721. programChange = false;
  12722. }
  12723. if ( shaderID ) {
  12724. var shader = THREE.ShaderLib[ shaderID ];
  12725. materialProperties.__webglShader = {
  12726. name: material.type,
  12727. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  12728. vertexShader: shader.vertexShader,
  12729. fragmentShader: shader.fragmentShader
  12730. };
  12731. } else {
  12732. materialProperties.__webglShader = {
  12733. name: material.type,
  12734. uniforms: material.uniforms,
  12735. vertexShader: material.vertexShader,
  12736. fragmentShader: material.fragmentShader
  12737. };
  12738. }
  12739. var program;
  12740. // Check if code has been already compiled
  12741. for ( var p = 0, pl = _programs.length; p < pl; p ++ ) {
  12742. var programInfo = _programs[ p ];
  12743. if ( programInfo.code === code ) {
  12744. program = programInfo;
  12745. if ( programChange ) {
  12746. program.usedTimes ++;
  12747. }
  12748. break;
  12749. }
  12750. }
  12751. if ( program === undefined ) {
  12752. material.__webglShader = materialProperties.__webglShader;
  12753. program = new THREE.WebGLProgram( _this, code, material, parameters );
  12754. _programs.push( program );
  12755. _infoMemory.programs = _programs.length;
  12756. }
  12757. materialProperties.program = program;
  12758. var attributes = program.getAttributes();
  12759. if ( material.morphTargets ) {
  12760. material.numSupportedMorphTargets = 0;
  12761. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  12762. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  12763. material.numSupportedMorphTargets ++;
  12764. }
  12765. }
  12766. }
  12767. if ( material.morphNormals ) {
  12768. material.numSupportedMorphNormals = 0;
  12769. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  12770. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  12771. material.numSupportedMorphNormals ++;
  12772. }
  12773. }
  12774. }
  12775. materialProperties.uniformsList = [];
  12776. var uniformLocations = materialProperties.program.getUniforms();
  12777. for ( var u in materialProperties.__webglShader.uniforms ) {
  12778. var location = uniformLocations[ u ];
  12779. if ( location ) {
  12780. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  12781. }
  12782. }
  12783. }
  12784. function setMaterial( material ) {
  12785. setMaterialFaces( material );
  12786. if ( material.transparent === true ) {
  12787. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  12788. } else {
  12789. state.setBlending( THREE.NoBlending );
  12790. }
  12791. state.setDepthFunc( material.depthFunc );
  12792. state.setDepthTest( material.depthTest );
  12793. state.setDepthWrite( material.depthWrite );
  12794. state.setColorWrite( material.colorWrite );
  12795. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12796. }
  12797. function setMaterialFaces( material ) {
  12798. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  12799. state.setFlipSided( material.side === THREE.BackSide );
  12800. }
  12801. function setProgram( camera, lights, fog, material, object ) {
  12802. _usedTextureUnits = 0;
  12803. var materialProperties = properties.get( material );
  12804. if ( material.needsUpdate || ! materialProperties.program ) {
  12805. initMaterial( material, lights, fog, object );
  12806. material.needsUpdate = false;
  12807. }
  12808. var refreshProgram = false;
  12809. var refreshMaterial = false;
  12810. var refreshLights = false;
  12811. var program = materialProperties.program,
  12812. p_uniforms = program.getUniforms(),
  12813. m_uniforms = materialProperties.__webglShader.uniforms;
  12814. if ( program.id !== _currentProgram ) {
  12815. _gl.useProgram( program.program );
  12816. _currentProgram = program.id;
  12817. refreshProgram = true;
  12818. refreshMaterial = true;
  12819. refreshLights = true;
  12820. }
  12821. if ( material.id !== _currentMaterialId ) {
  12822. if ( _currentMaterialId === - 1 ) refreshLights = true;
  12823. _currentMaterialId = material.id;
  12824. refreshMaterial = true;
  12825. }
  12826. if ( refreshProgram || camera !== _currentCamera ) {
  12827. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  12828. if ( _logarithmicDepthBuffer ) {
  12829. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  12830. }
  12831. if ( camera !== _currentCamera ) _currentCamera = camera;
  12832. // load material specific uniforms
  12833. // (shader material also gets them for the sake of genericity)
  12834. if ( material instanceof THREE.ShaderMaterial ||
  12835. material instanceof THREE.MeshPhongMaterial ||
  12836. material.envMap ) {
  12837. if ( p_uniforms.cameraPosition !== undefined ) {
  12838. _vector3.setFromMatrixPosition( camera.matrixWorld );
  12839. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  12840. }
  12841. }
  12842. if ( material instanceof THREE.MeshPhongMaterial ||
  12843. material instanceof THREE.MeshLambertMaterial ||
  12844. material instanceof THREE.MeshBasicMaterial ||
  12845. material instanceof THREE.ShaderMaterial ||
  12846. material.skinning ) {
  12847. if ( p_uniforms.viewMatrix !== undefined ) {
  12848. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  12849. }
  12850. }
  12851. }
  12852. // skinning uniforms must be set even if material didn't change
  12853. // auto-setting of texture unit for bone texture must go before other textures
  12854. // not sure why, but otherwise weird things happen
  12855. if ( material.skinning ) {
  12856. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  12857. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  12858. }
  12859. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  12860. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  12861. }
  12862. if ( _supportsBoneTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  12863. if ( p_uniforms.boneTexture !== undefined ) {
  12864. var textureUnit = getTextureUnit();
  12865. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  12866. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  12867. }
  12868. if ( p_uniforms.boneTextureWidth !== undefined ) {
  12869. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  12870. }
  12871. if ( p_uniforms.boneTextureHeight !== undefined ) {
  12872. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  12873. }
  12874. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  12875. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  12876. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  12877. }
  12878. }
  12879. }
  12880. if ( refreshMaterial ) {
  12881. // refresh uniforms common to several materials
  12882. if ( fog && material.fog ) {
  12883. refreshUniformsFog( m_uniforms, fog );
  12884. }
  12885. if ( material instanceof THREE.MeshPhongMaterial ||
  12886. material instanceof THREE.MeshLambertMaterial ||
  12887. material.lights ) {
  12888. if ( _lightsNeedUpdate ) {
  12889. refreshLights = true;
  12890. setupLights( lights );
  12891. _lightsNeedUpdate = false;
  12892. }
  12893. if ( refreshLights ) {
  12894. refreshUniformsLights( m_uniforms, _lights );
  12895. markUniformsLightsNeedsUpdate( m_uniforms, true );
  12896. } else {
  12897. markUniformsLightsNeedsUpdate( m_uniforms, false );
  12898. }
  12899. }
  12900. if ( material instanceof THREE.MeshBasicMaterial ||
  12901. material instanceof THREE.MeshLambertMaterial ||
  12902. material instanceof THREE.MeshPhongMaterial ) {
  12903. refreshUniformsCommon( m_uniforms, material );
  12904. }
  12905. // refresh single material specific uniforms
  12906. if ( material instanceof THREE.LineBasicMaterial ) {
  12907. refreshUniformsLine( m_uniforms, material );
  12908. } else if ( material instanceof THREE.LineDashedMaterial ) {
  12909. refreshUniformsLine( m_uniforms, material );
  12910. refreshUniformsDash( m_uniforms, material );
  12911. } else if ( material instanceof THREE.PointCloudMaterial ) {
  12912. refreshUniformsParticle( m_uniforms, material );
  12913. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  12914. refreshUniformsPhong( m_uniforms, material );
  12915. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  12916. refreshUniformsLambert( m_uniforms, material );
  12917. } else if ( material instanceof THREE.MeshBasicMaterial ) {
  12918. refreshUniformsBasic( m_uniforms, material );
  12919. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  12920. m_uniforms.mNear.value = camera.near;
  12921. m_uniforms.mFar.value = camera.far;
  12922. m_uniforms.opacity.value = material.opacity;
  12923. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  12924. m_uniforms.opacity.value = material.opacity;
  12925. }
  12926. if ( object.receiveShadow && ! material._shadowPass ) {
  12927. refreshUniformsShadow( m_uniforms, lights );
  12928. }
  12929. // load common uniforms
  12930. loadUniformsGeneric( materialProperties.uniformsList );
  12931. }
  12932. loadUniformsMatrices( p_uniforms, object );
  12933. if ( p_uniforms.modelMatrix !== undefined ) {
  12934. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  12935. }
  12936. return program;
  12937. }
  12938. // Uniforms (refresh uniforms objects)
  12939. function refreshUniformsCommon ( uniforms, material ) {
  12940. uniforms.opacity.value = material.opacity;
  12941. uniforms.diffuse.value = material.color;
  12942. uniforms.map.value = material.map;
  12943. uniforms.specularMap.value = material.specularMap;
  12944. uniforms.alphaMap.value = material.alphaMap;
  12945. if ( material.bumpMap ) {
  12946. uniforms.bumpMap.value = material.bumpMap;
  12947. uniforms.bumpScale.value = material.bumpScale;
  12948. }
  12949. if ( material.normalMap ) {
  12950. uniforms.normalMap.value = material.normalMap;
  12951. uniforms.normalScale.value.copy( material.normalScale );
  12952. }
  12953. // uv repeat and offset setting priorities
  12954. // 1. color map
  12955. // 2. specular map
  12956. // 3. normal map
  12957. // 4. bump map
  12958. // 5. alpha map
  12959. // 6. emissive map
  12960. var uvScaleMap;
  12961. if ( material.map ) {
  12962. uvScaleMap = material.map;
  12963. } else if ( material.specularMap ) {
  12964. uvScaleMap = material.specularMap;
  12965. } else if ( material.normalMap ) {
  12966. uvScaleMap = material.normalMap;
  12967. } else if ( material.bumpMap ) {
  12968. uvScaleMap = material.bumpMap;
  12969. } else if ( material.alphaMap ) {
  12970. uvScaleMap = material.alphaMap;
  12971. } else if ( material.emissiveMap ) {
  12972. uvScaleMap = material.emissiveMap;
  12973. }
  12974. if ( uvScaleMap !== undefined ) {
  12975. var offset = uvScaleMap.offset;
  12976. var repeat = uvScaleMap.repeat;
  12977. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  12978. }
  12979. uniforms.envMap.value = material.envMap;
  12980. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  12981. uniforms.reflectivity.value = material.reflectivity;
  12982. uniforms.refractionRatio.value = material.refractionRatio;
  12983. }
  12984. function refreshUniformsLine ( uniforms, material ) {
  12985. uniforms.diffuse.value = material.color;
  12986. uniforms.opacity.value = material.opacity;
  12987. }
  12988. function refreshUniformsDash ( uniforms, material ) {
  12989. uniforms.dashSize.value = material.dashSize;
  12990. uniforms.totalSize.value = material.dashSize + material.gapSize;
  12991. uniforms.scale.value = material.scale;
  12992. }
  12993. function refreshUniformsParticle ( uniforms, material ) {
  12994. uniforms.psColor.value = material.color;
  12995. uniforms.opacity.value = material.opacity;
  12996. uniforms.size.value = material.size;
  12997. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  12998. uniforms.map.value = material.map;
  12999. if ( material.map !== null ) {
  13000. var offset = material.map.offset;
  13001. var repeat = material.map.repeat;
  13002. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13003. }
  13004. }
  13005. function refreshUniformsFog ( uniforms, fog ) {
  13006. uniforms.fogColor.value = fog.color;
  13007. if ( fog instanceof THREE.Fog ) {
  13008. uniforms.fogNear.value = fog.near;
  13009. uniforms.fogFar.value = fog.far;
  13010. } else if ( fog instanceof THREE.FogExp2 ) {
  13011. uniforms.fogDensity.value = fog.density;
  13012. }
  13013. }
  13014. function refreshUniformsPhong ( uniforms, material ) {
  13015. uniforms.shininess.value = material.shininess;
  13016. uniforms.emissive.value = material.emissive;
  13017. uniforms.specular.value = material.specular;
  13018. uniforms.lightMap.value = material.lightMap;
  13019. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13020. uniforms.aoMap.value = material.aoMap;
  13021. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13022. uniforms.emissiveMap.value = material.emissiveMap;
  13023. }
  13024. function refreshUniformsLambert ( uniforms, material ) {
  13025. uniforms.emissive.value = material.emissive;
  13026. }
  13027. function refreshUniformsBasic ( uniforms, material ) {
  13028. uniforms.aoMap.value = material.aoMap;
  13029. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13030. }
  13031. function refreshUniformsLights ( uniforms, lights ) {
  13032. uniforms.ambientLightColor.value = lights.ambient;
  13033. uniforms.directionalLightColor.value = lights.directional.colors;
  13034. uniforms.directionalLightDirection.value = lights.directional.positions;
  13035. uniforms.pointLightColor.value = lights.point.colors;
  13036. uniforms.pointLightPosition.value = lights.point.positions;
  13037. uniforms.pointLightDistance.value = lights.point.distances;
  13038. uniforms.pointLightDecay.value = lights.point.decays;
  13039. uniforms.spotLightColor.value = lights.spot.colors;
  13040. uniforms.spotLightPosition.value = lights.spot.positions;
  13041. uniforms.spotLightDistance.value = lights.spot.distances;
  13042. uniforms.spotLightDirection.value = lights.spot.directions;
  13043. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  13044. uniforms.spotLightExponent.value = lights.spot.exponents;
  13045. uniforms.spotLightDecay.value = lights.spot.decays;
  13046. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  13047. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  13048. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  13049. }
  13050. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13051. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  13052. uniforms.ambientLightColor.needsUpdate = value;
  13053. uniforms.directionalLightColor.needsUpdate = value;
  13054. uniforms.directionalLightDirection.needsUpdate = value;
  13055. uniforms.pointLightColor.needsUpdate = value;
  13056. uniforms.pointLightPosition.needsUpdate = value;
  13057. uniforms.pointLightDistance.needsUpdate = value;
  13058. uniforms.pointLightDecay.needsUpdate = value;
  13059. uniforms.spotLightColor.needsUpdate = value;
  13060. uniforms.spotLightPosition.needsUpdate = value;
  13061. uniforms.spotLightDistance.needsUpdate = value;
  13062. uniforms.spotLightDirection.needsUpdate = value;
  13063. uniforms.spotLightAngleCos.needsUpdate = value;
  13064. uniforms.spotLightExponent.needsUpdate = value;
  13065. uniforms.spotLightDecay.needsUpdate = value;
  13066. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  13067. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  13068. uniforms.hemisphereLightDirection.needsUpdate = value;
  13069. }
  13070. function refreshUniformsShadow ( uniforms, lights ) {
  13071. if ( uniforms.shadowMatrix ) {
  13072. var j = 0;
  13073. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  13074. var light = lights[ i ];
  13075. if ( ! light.castShadow ) continue;
  13076. if ( light instanceof THREE.SpotLight || ( light instanceof THREE.DirectionalLight ) ) {
  13077. uniforms.shadowMap.value[ j ] = light.shadowMap;
  13078. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  13079. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  13080. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  13081. uniforms.shadowBias.value[ j ] = light.shadowBias;
  13082. j ++;
  13083. }
  13084. }
  13085. }
  13086. }
  13087. // Uniforms (load to GPU)
  13088. function loadUniformsMatrices ( uniforms, object ) {
  13089. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object._modelViewMatrix.elements );
  13090. if ( uniforms.normalMatrix ) {
  13091. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object._normalMatrix.elements );
  13092. }
  13093. }
  13094. function getTextureUnit() {
  13095. var textureUnit = _usedTextureUnits;
  13096. if ( textureUnit >= _maxTextures ) {
  13097. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + _maxTextures );
  13098. }
  13099. _usedTextureUnits += 1;
  13100. return textureUnit;
  13101. }
  13102. function loadUniformsGeneric ( uniforms ) {
  13103. var texture, textureUnit, offset;
  13104. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  13105. var uniform = uniforms[ j ][ 0 ];
  13106. // needsUpdate property is not added to all uniforms.
  13107. if ( uniform.needsUpdate === false ) continue;
  13108. var type = uniform.type;
  13109. var value = uniform.value;
  13110. var location = uniforms[ j ][ 1 ];
  13111. switch ( type ) {
  13112. case '1i':
  13113. _gl.uniform1i( location, value );
  13114. break;
  13115. case '1f':
  13116. _gl.uniform1f( location, value );
  13117. break;
  13118. case '2f':
  13119. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  13120. break;
  13121. case '3f':
  13122. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  13123. break;
  13124. case '4f':
  13125. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  13126. break;
  13127. case '1iv':
  13128. _gl.uniform1iv( location, value );
  13129. break;
  13130. case '3iv':
  13131. _gl.uniform3iv( location, value );
  13132. break;
  13133. case '1fv':
  13134. _gl.uniform1fv( location, value );
  13135. break;
  13136. case '2fv':
  13137. _gl.uniform2fv( location, value );
  13138. break;
  13139. case '3fv':
  13140. _gl.uniform3fv( location, value );
  13141. break;
  13142. case '4fv':
  13143. _gl.uniform4fv( location, value );
  13144. break;
  13145. case 'Matrix3fv':
  13146. _gl.uniformMatrix3fv( location, false, value );
  13147. break;
  13148. case 'Matrix4fv':
  13149. _gl.uniformMatrix4fv( location, false, value );
  13150. break;
  13151. //
  13152. case 'i':
  13153. // single integer
  13154. _gl.uniform1i( location, value );
  13155. break;
  13156. case 'f':
  13157. // single float
  13158. _gl.uniform1f( location, value );
  13159. break;
  13160. case 'v2':
  13161. // single THREE.Vector2
  13162. _gl.uniform2f( location, value.x, value.y );
  13163. break;
  13164. case 'v3':
  13165. // single THREE.Vector3
  13166. _gl.uniform3f( location, value.x, value.y, value.z );
  13167. break;
  13168. case 'v4':
  13169. // single THREE.Vector4
  13170. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  13171. break;
  13172. case 'c':
  13173. // single THREE.Color
  13174. _gl.uniform3f( location, value.r, value.g, value.b );
  13175. break;
  13176. case 'iv1':
  13177. // flat array of integers (JS or typed array)
  13178. _gl.uniform1iv( location, value );
  13179. break;
  13180. case 'iv':
  13181. // flat array of integers with 3 x N size (JS or typed array)
  13182. _gl.uniform3iv( location, value );
  13183. break;
  13184. case 'fv1':
  13185. // flat array of floats (JS or typed array)
  13186. _gl.uniform1fv( location, value );
  13187. break;
  13188. case 'fv':
  13189. // flat array of floats with 3 x N size (JS or typed array)
  13190. _gl.uniform3fv( location, value );
  13191. break;
  13192. case 'v2v':
  13193. // array of THREE.Vector2
  13194. if ( uniform._array === undefined ) {
  13195. uniform._array = new Float32Array( 2 * value.length );
  13196. }
  13197. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13198. offset = i * 2;
  13199. uniform._array[ offset + 0 ] = value[ i ].x;
  13200. uniform._array[ offset + 1 ] = value[ i ].y;
  13201. }
  13202. _gl.uniform2fv( location, uniform._array );
  13203. break;
  13204. case 'v3v':
  13205. // array of THREE.Vector3
  13206. if ( uniform._array === undefined ) {
  13207. uniform._array = new Float32Array( 3 * value.length );
  13208. }
  13209. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13210. offset = i * 3;
  13211. uniform._array[ offset + 0 ] = value[ i ].x;
  13212. uniform._array[ offset + 1 ] = value[ i ].y;
  13213. uniform._array[ offset + 2 ] = value[ i ].z;
  13214. }
  13215. _gl.uniform3fv( location, uniform._array );
  13216. break;
  13217. case 'v4v':
  13218. // array of THREE.Vector4
  13219. if ( uniform._array === undefined ) {
  13220. uniform._array = new Float32Array( 4 * value.length );
  13221. }
  13222. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13223. offset = i * 4;
  13224. uniform._array[ offset + 0 ] = value[ i ].x;
  13225. uniform._array[ offset + 1 ] = value[ i ].y;
  13226. uniform._array[ offset + 2 ] = value[ i ].z;
  13227. uniform._array[ offset + 3 ] = value[ i ].w;
  13228. }
  13229. _gl.uniform4fv( location, uniform._array );
  13230. break;
  13231. case 'm3':
  13232. // single THREE.Matrix3
  13233. _gl.uniformMatrix3fv( location, false, value.elements );
  13234. break;
  13235. case 'm3v':
  13236. // array of THREE.Matrix3
  13237. if ( uniform._array === undefined ) {
  13238. uniform._array = new Float32Array( 9 * value.length );
  13239. }
  13240. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13241. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  13242. }
  13243. _gl.uniformMatrix3fv( location, false, uniform._array );
  13244. break;
  13245. case 'm4':
  13246. // single THREE.Matrix4
  13247. _gl.uniformMatrix4fv( location, false, value.elements );
  13248. break;
  13249. case 'm4v':
  13250. // array of THREE.Matrix4
  13251. if ( uniform._array === undefined ) {
  13252. uniform._array = new Float32Array( 16 * value.length );
  13253. }
  13254. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13255. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  13256. }
  13257. _gl.uniformMatrix4fv( location, false, uniform._array );
  13258. break;
  13259. case 't':
  13260. // single THREE.Texture (2d or cube)
  13261. texture = value;
  13262. textureUnit = getTextureUnit();
  13263. _gl.uniform1i( location, textureUnit );
  13264. if ( ! texture ) continue;
  13265. if ( texture instanceof THREE.CubeTexture ||
  13266. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13267. // CompressedTexture can have Array in image :/
  13268. setCubeTexture( texture, textureUnit );
  13269. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  13270. setCubeTextureDynamic( texture, textureUnit );
  13271. } else {
  13272. _this.setTexture( texture, textureUnit );
  13273. }
  13274. break;
  13275. case 'tv':
  13276. // array of THREE.Texture (2d)
  13277. if ( uniform._array === undefined ) {
  13278. uniform._array = [];
  13279. }
  13280. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13281. uniform._array[ i ] = getTextureUnit();
  13282. }
  13283. _gl.uniform1iv( location, uniform._array );
  13284. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13285. texture = uniform.value[ i ];
  13286. textureUnit = uniform._array[ i ];
  13287. if ( ! texture ) continue;
  13288. _this.setTexture( texture, textureUnit );
  13289. }
  13290. break;
  13291. default:
  13292. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  13293. }
  13294. }
  13295. }
  13296. function setupMatrices( object, camera ) {
  13297. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13298. object._normalMatrix.getNormalMatrix( object._modelViewMatrix );
  13299. }
  13300. function setColorLinear( array, offset, color, intensity ) {
  13301. array[ offset + 0 ] = color.r * intensity;
  13302. array[ offset + 1 ] = color.g * intensity;
  13303. array[ offset + 2 ] = color.b * intensity;
  13304. }
  13305. function setupLights ( lights ) {
  13306. var l, ll, light,
  13307. r = 0, g = 0, b = 0,
  13308. color, skyColor, groundColor,
  13309. intensity,
  13310. distance,
  13311. zlights = _lights,
  13312. dirColors = zlights.directional.colors,
  13313. dirPositions = zlights.directional.positions,
  13314. pointColors = zlights.point.colors,
  13315. pointPositions = zlights.point.positions,
  13316. pointDistances = zlights.point.distances,
  13317. pointDecays = zlights.point.decays,
  13318. spotColors = zlights.spot.colors,
  13319. spotPositions = zlights.spot.positions,
  13320. spotDistances = zlights.spot.distances,
  13321. spotDirections = zlights.spot.directions,
  13322. spotAnglesCos = zlights.spot.anglesCos,
  13323. spotExponents = zlights.spot.exponents,
  13324. spotDecays = zlights.spot.decays,
  13325. hemiSkyColors = zlights.hemi.skyColors,
  13326. hemiGroundColors = zlights.hemi.groundColors,
  13327. hemiPositions = zlights.hemi.positions,
  13328. dirLength = 0,
  13329. pointLength = 0,
  13330. spotLength = 0,
  13331. hemiLength = 0,
  13332. dirCount = 0,
  13333. pointCount = 0,
  13334. spotCount = 0,
  13335. hemiCount = 0,
  13336. dirOffset = 0,
  13337. pointOffset = 0,
  13338. spotOffset = 0,
  13339. hemiOffset = 0;
  13340. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  13341. light = lights[ l ];
  13342. if ( light.onlyShadow ) continue;
  13343. color = light.color;
  13344. intensity = light.intensity;
  13345. distance = light.distance;
  13346. if ( light instanceof THREE.AmbientLight ) {
  13347. if ( ! light.visible ) continue;
  13348. r += color.r;
  13349. g += color.g;
  13350. b += color.b;
  13351. } else if ( light instanceof THREE.DirectionalLight ) {
  13352. dirCount += 1;
  13353. if ( ! light.visible ) continue;
  13354. _direction.setFromMatrixPosition( light.matrixWorld );
  13355. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13356. _direction.sub( _vector3 );
  13357. _direction.normalize();
  13358. dirOffset = dirLength * 3;
  13359. dirPositions[ dirOffset + 0 ] = _direction.x;
  13360. dirPositions[ dirOffset + 1 ] = _direction.y;
  13361. dirPositions[ dirOffset + 2 ] = _direction.z;
  13362. setColorLinear( dirColors, dirOffset, color, intensity );
  13363. dirLength += 1;
  13364. } else if ( light instanceof THREE.PointLight ) {
  13365. pointCount += 1;
  13366. if ( ! light.visible ) continue;
  13367. pointOffset = pointLength * 3;
  13368. setColorLinear( pointColors, pointOffset, color, intensity );
  13369. _vector3.setFromMatrixPosition( light.matrixWorld );
  13370. pointPositions[ pointOffset + 0 ] = _vector3.x;
  13371. pointPositions[ pointOffset + 1 ] = _vector3.y;
  13372. pointPositions[ pointOffset + 2 ] = _vector3.z;
  13373. // distance is 0 if decay is 0, because there is no attenuation at all.
  13374. pointDistances[ pointLength ] = distance;
  13375. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13376. pointLength += 1;
  13377. } else if ( light instanceof THREE.SpotLight ) {
  13378. spotCount += 1;
  13379. if ( ! light.visible ) continue;
  13380. spotOffset = spotLength * 3;
  13381. setColorLinear( spotColors, spotOffset, color, intensity );
  13382. _direction.setFromMatrixPosition( light.matrixWorld );
  13383. spotPositions[ spotOffset + 0 ] = _direction.x;
  13384. spotPositions[ spotOffset + 1 ] = _direction.y;
  13385. spotPositions[ spotOffset + 2 ] = _direction.z;
  13386. spotDistances[ spotLength ] = distance;
  13387. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13388. _direction.sub( _vector3 );
  13389. _direction.normalize();
  13390. spotDirections[ spotOffset + 0 ] = _direction.x;
  13391. spotDirections[ spotOffset + 1 ] = _direction.y;
  13392. spotDirections[ spotOffset + 2 ] = _direction.z;
  13393. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  13394. spotExponents[ spotLength ] = light.exponent;
  13395. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13396. spotLength += 1;
  13397. } else if ( light instanceof THREE.HemisphereLight ) {
  13398. hemiCount += 1;
  13399. if ( ! light.visible ) continue;
  13400. _direction.setFromMatrixPosition( light.matrixWorld );
  13401. _direction.normalize();
  13402. hemiOffset = hemiLength * 3;
  13403. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  13404. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  13405. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  13406. skyColor = light.color;
  13407. groundColor = light.groundColor;
  13408. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  13409. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  13410. hemiLength += 1;
  13411. }
  13412. }
  13413. // null eventual remains from removed lights
  13414. // (this is to avoid if in shader)
  13415. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  13416. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  13417. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  13418. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  13419. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  13420. zlights.directional.length = dirLength;
  13421. zlights.point.length = pointLength;
  13422. zlights.spot.length = spotLength;
  13423. zlights.hemi.length = hemiLength;
  13424. zlights.ambient[ 0 ] = r;
  13425. zlights.ambient[ 1 ] = g;
  13426. zlights.ambient[ 2 ] = b;
  13427. }
  13428. // GL state setting
  13429. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  13430. if ( cullFace === THREE.CullFaceNone ) {
  13431. state.disable( _gl.CULL_FACE );
  13432. } else {
  13433. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  13434. _gl.frontFace( _gl.CW );
  13435. } else {
  13436. _gl.frontFace( _gl.CCW );
  13437. }
  13438. if ( cullFace === THREE.CullFaceBack ) {
  13439. _gl.cullFace( _gl.BACK );
  13440. } else if ( cullFace === THREE.CullFaceFront ) {
  13441. _gl.cullFace( _gl.FRONT );
  13442. } else {
  13443. _gl.cullFace( _gl.FRONT_AND_BACK );
  13444. }
  13445. state.enable( _gl.CULL_FACE );
  13446. }
  13447. };
  13448. // Textures
  13449. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  13450. var extension;
  13451. if ( isImagePowerOfTwo ) {
  13452. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  13453. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  13454. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  13455. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  13456. } else {
  13457. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  13458. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  13459. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  13460. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. ( ' + texture.sourceFile + ' )' );
  13461. }
  13462. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  13463. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  13464. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  13465. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. ( ' + texture.sourceFile + ' )' );
  13466. }
  13467. }
  13468. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13469. if ( extension && texture.type !== THREE.FloatType && texture.type !== THREE.HalfFloatType ) {
  13470. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  13471. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  13472. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  13473. }
  13474. }
  13475. }
  13476. function uploadTexture( textureProperties, texture, slot ) {
  13477. if ( textureProperties.__webglInit === undefined ) {
  13478. textureProperties.__webglInit = true;
  13479. texture.__webglInit = true;
  13480. texture.addEventListener( 'dispose', onTextureDispose );
  13481. textureProperties.__webglTexture = _gl.createTexture();
  13482. _infoMemory.textures ++;
  13483. }
  13484. state.activeTexture( _gl.TEXTURE0 + slot );
  13485. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  13486. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13487. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  13488. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  13489. texture.image = clampToMaxSize( texture.image, _maxTextureSize );
  13490. var image = texture.image,
  13491. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13492. glFormat = paramThreeToGL( texture.format ),
  13493. glType = paramThreeToGL( texture.type );
  13494. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  13495. var mipmap, mipmaps = texture.mipmaps;
  13496. if ( texture instanceof THREE.DataTexture ) {
  13497. // use manually created mipmaps if available
  13498. // if there are no manual mipmaps
  13499. // set 0 level mipmap and then use GL to generate other mipmap levels
  13500. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13501. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13502. mipmap = mipmaps[ i ];
  13503. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13504. }
  13505. texture.generateMipmaps = false;
  13506. } else {
  13507. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13508. }
  13509. } else if ( texture instanceof THREE.CompressedTexture ) {
  13510. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13511. mipmap = mipmaps[ i ];
  13512. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13513. if ( getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  13514. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13515. } else {
  13516. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  13517. }
  13518. } else {
  13519. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13520. }
  13521. }
  13522. } else {
  13523. // regular Texture (image, video, canvas)
  13524. // use manually created mipmaps if available
  13525. // if there are no manual mipmaps
  13526. // set 0 level mipmap and then use GL to generate other mipmap levels
  13527. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13528. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13529. mipmap = mipmaps[ i ];
  13530. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  13531. }
  13532. texture.generateMipmaps = false;
  13533. } else {
  13534. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  13535. }
  13536. }
  13537. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13538. textureProperties.__version = texture.version;
  13539. if ( texture.onUpdate ) texture.onUpdate( texture );
  13540. }
  13541. this.setTexture = function ( texture, slot ) {
  13542. var textureProperties = properties.get( texture );
  13543. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13544. var image = texture.image;
  13545. if ( image === undefined ) {
  13546. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  13547. return;
  13548. }
  13549. if ( image.complete === false ) {
  13550. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  13551. return;
  13552. }
  13553. uploadTexture( textureProperties, texture, slot );
  13554. return;
  13555. }
  13556. state.activeTexture( _gl.TEXTURE0 + slot );
  13557. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  13558. };
  13559. function clampToMaxSize ( image, maxSize ) {
  13560. if ( image.width > maxSize || image.height > maxSize ) {
  13561. // Warning: Scaling through the canvas will only work with images that use
  13562. // premultiplied alpha.
  13563. var scale = maxSize / Math.max( image.width, image.height );
  13564. var canvas = document.createElement( 'canvas' );
  13565. canvas.width = Math.floor( image.width * scale );
  13566. canvas.height = Math.floor( image.height * scale );
  13567. var context = canvas.getContext( '2d' );
  13568. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  13569. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  13570. return canvas;
  13571. }
  13572. return image;
  13573. }
  13574. function setCubeTexture ( texture, slot ) {
  13575. var textureProperties = properties.get( texture );
  13576. if ( texture.image.length === 6 ) {
  13577. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13578. if ( ! textureProperties.__image__webglTextureCube ) {
  13579. texture.addEventListener( 'dispose', onTextureDispose );
  13580. textureProperties.__image__webglTextureCube = _gl.createTexture();
  13581. _infoMemory.textures ++;
  13582. }
  13583. state.activeTexture( _gl.TEXTURE0 + slot );
  13584. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13585. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13586. var isCompressed = texture instanceof THREE.CompressedTexture;
  13587. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  13588. var cubeImage = [];
  13589. for ( var i = 0; i < 6; i ++ ) {
  13590. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  13591. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], _maxCubemapSize );
  13592. } else {
  13593. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13594. }
  13595. }
  13596. var image = cubeImage[ 0 ],
  13597. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13598. glFormat = paramThreeToGL( texture.format ),
  13599. glType = paramThreeToGL( texture.type );
  13600. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  13601. for ( var i = 0; i < 6; i ++ ) {
  13602. if ( ! isCompressed ) {
  13603. if ( isDataTexture ) {
  13604. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  13605. } else {
  13606. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  13607. }
  13608. } else {
  13609. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  13610. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  13611. mipmap = mipmaps[ j ];
  13612. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13613. if ( getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  13614. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13615. } else {
  13616. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  13617. }
  13618. } else {
  13619. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13620. }
  13621. }
  13622. }
  13623. }
  13624. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  13625. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13626. }
  13627. textureProperties.__version = texture.version;
  13628. if ( texture.onUpdate ) texture.onUpdate( texture );
  13629. } else {
  13630. state.activeTexture( _gl.TEXTURE0 + slot );
  13631. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13632. }
  13633. }
  13634. }
  13635. function setCubeTextureDynamic ( texture, slot ) {
  13636. state.activeTexture( _gl.TEXTURE0 + slot );
  13637. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  13638. }
  13639. // Render targets
  13640. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  13641. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13642. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget ).__webglTexture, 0 );
  13643. }
  13644. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  13645. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  13646. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13647. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  13648. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13649. /* For some reason this is not working. Defaulting to RGBA4.
  13650. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13651. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  13652. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13653. */
  13654. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13655. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  13656. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13657. } else {
  13658. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  13659. }
  13660. }
  13661. this.setRenderTarget = function ( renderTarget ) {
  13662. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  13663. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  13664. var renderTargetProperties = properties.get( renderTarget );
  13665. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  13666. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  13667. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13668. renderTargetProperties.__webglTexture = _gl.createTexture();
  13669. _infoMemory.textures ++;
  13670. // Setup texture, create render and frame buffers
  13671. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
  13672. glFormat = paramThreeToGL( renderTarget.format ),
  13673. glType = paramThreeToGL( renderTarget.type );
  13674. if ( isCube ) {
  13675. renderTargetProperties.__webglFramebuffer = [];
  13676. renderTargetProperties.__webglRenderbuffer = [];
  13677. state.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTargetProperties.__webglTexture );
  13678. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
  13679. for ( var i = 0; i < 6; i ++ ) {
  13680. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13681. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  13682. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13683. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  13684. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  13685. }
  13686. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13687. } else {
  13688. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13689. if ( renderTarget.shareDepthFrom ) {
  13690. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  13691. } else {
  13692. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  13693. }
  13694. state.bindTexture( _gl.TEXTURE_2D, renderTargetProperties.__webglTexture );
  13695. setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
  13696. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13697. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  13698. if ( renderTarget.shareDepthFrom ) {
  13699. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13700. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13701. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13702. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13703. }
  13704. } else {
  13705. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  13706. }
  13707. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13708. }
  13709. // Release everything
  13710. if ( isCube ) {
  13711. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13712. } else {
  13713. state.bindTexture( _gl.TEXTURE_2D, null );
  13714. }
  13715. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  13716. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  13717. }
  13718. var framebuffer, width, height, vx, vy;
  13719. if ( renderTarget ) {
  13720. var renderTargetProperties = properties.get( renderTarget );
  13721. if ( isCube ) {
  13722. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  13723. } else {
  13724. framebuffer = renderTargetProperties.__webglFramebuffer;
  13725. }
  13726. width = renderTarget.width;
  13727. height = renderTarget.height;
  13728. vx = 0;
  13729. vy = 0;
  13730. } else {
  13731. framebuffer = null;
  13732. width = _viewportWidth;
  13733. height = _viewportHeight;
  13734. vx = _viewportX;
  13735. vy = _viewportY;
  13736. }
  13737. if ( framebuffer !== _currentFramebuffer ) {
  13738. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13739. _gl.viewport( vx, vy, width, height );
  13740. _currentFramebuffer = framebuffer;
  13741. }
  13742. _currentWidth = width;
  13743. _currentHeight = height;
  13744. };
  13745. this.readRenderTargetPixels = function( renderTarget, x, y, width, height, buffer ) {
  13746. if ( ! ( renderTarget instanceof THREE.WebGLRenderTarget ) ) {
  13747. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  13748. return;
  13749. }
  13750. if ( properties.get( renderTarget ).__webglFramebuffer ) {
  13751. if ( renderTarget.format !== THREE.RGBAFormat ) {
  13752. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA format. readPixels can read only RGBA format.' );
  13753. return;
  13754. }
  13755. var restore = false;
  13756. if ( properties.get( renderTarget ).__webglFramebuffer !== _currentFramebuffer ) {
  13757. _gl.bindFramebuffer( _gl.FRAMEBUFFER, properties.get( renderTarget ).__webglFramebuffer );
  13758. restore = true;
  13759. }
  13760. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  13761. _gl.readPixels( x, y, width, height, _gl.RGBA, _gl.UNSIGNED_BYTE, buffer );
  13762. } else {
  13763. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  13764. }
  13765. if ( restore ) {
  13766. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  13767. }
  13768. }
  13769. };
  13770. function updateRenderTargetMipmap ( renderTarget ) {
  13771. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  13772. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( renderTarget ).__webglTexture );
  13773. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13774. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13775. } else {
  13776. state.bindTexture( _gl.TEXTURE_2D, properties.get( renderTarget ).__webglTexture );
  13777. _gl.generateMipmap( _gl.TEXTURE_2D );
  13778. state.bindTexture( _gl.TEXTURE_2D, null );
  13779. }
  13780. }
  13781. // Fallback filters for non-power-of-2 textures
  13782. function filterFallback ( f ) {
  13783. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  13784. return _gl.NEAREST;
  13785. }
  13786. return _gl.LINEAR;
  13787. }
  13788. // Map three.js constants to WebGL constants
  13789. function paramThreeToGL ( p ) {
  13790. var extension;
  13791. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  13792. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  13793. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  13794. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  13795. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  13796. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  13797. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  13798. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  13799. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  13800. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  13801. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  13802. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  13803. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  13804. if ( p === THREE.ByteType ) return _gl.BYTE;
  13805. if ( p === THREE.ShortType ) return _gl.SHORT;
  13806. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  13807. if ( p === THREE.IntType ) return _gl.INT;
  13808. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  13809. if ( p === THREE.FloatType ) return _gl.FLOAT;
  13810. extension = extensions.get( 'OES_texture_half_float' );
  13811. if ( extension !== null ) {
  13812. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  13813. }
  13814. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  13815. if ( p === THREE.RGBFormat ) return _gl.RGB;
  13816. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  13817. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  13818. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  13819. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  13820. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  13821. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  13822. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  13823. if ( p === THREE.OneFactor ) return _gl.ONE;
  13824. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  13825. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  13826. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  13827. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  13828. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  13829. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  13830. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  13831. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  13832. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  13833. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13834. if ( extension !== null ) {
  13835. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13836. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13837. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13838. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13839. }
  13840. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13841. if ( extension !== null ) {
  13842. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13843. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13844. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13845. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13846. }
  13847. extension = extensions.get( 'EXT_blend_minmax' );
  13848. if ( extension !== null ) {
  13849. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  13850. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  13851. }
  13852. return 0;
  13853. }
  13854. // Allocations
  13855. function allocateBones ( object ) {
  13856. if ( _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  13857. return 1024;
  13858. } else {
  13859. // default for when object is not specified
  13860. // ( for example when prebuilding shader to be used with multiple objects )
  13861. //
  13862. // - leave some extra space for other uniforms
  13863. // - limit here is ANGLE's 254 max uniform vectors
  13864. // (up to 54 should be safe)
  13865. var nVertexUniforms = _gl.getParameter( _gl.MAX_VERTEX_UNIFORM_VECTORS );
  13866. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  13867. var maxBones = nVertexMatrices;
  13868. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  13869. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  13870. if ( maxBones < object.skeleton.bones.length ) {
  13871. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  13872. }
  13873. }
  13874. return maxBones;
  13875. }
  13876. }
  13877. function allocateLights( lights ) {
  13878. var dirLights = 0;
  13879. var pointLights = 0;
  13880. var spotLights = 0;
  13881. var hemiLights = 0;
  13882. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13883. var light = lights[ l ];
  13884. if ( light.onlyShadow || light.visible === false ) continue;
  13885. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  13886. if ( light instanceof THREE.PointLight ) pointLights ++;
  13887. if ( light instanceof THREE.SpotLight ) spotLights ++;
  13888. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  13889. }
  13890. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  13891. }
  13892. function allocateShadows( lights ) {
  13893. var maxShadows = 0;
  13894. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13895. var light = lights[ l ];
  13896. if ( ! light.castShadow ) continue;
  13897. if ( light instanceof THREE.SpotLight ) maxShadows ++;
  13898. if ( light instanceof THREE.DirectionalLight ) maxShadows ++;
  13899. }
  13900. return maxShadows;
  13901. }
  13902. // DEPRECATED
  13903. this.initMaterial = function () {
  13904. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  13905. };
  13906. this.addPrePlugin = function () {
  13907. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  13908. };
  13909. this.addPostPlugin = function () {
  13910. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  13911. };
  13912. this.updateShadowMap = function () {
  13913. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  13914. };
  13915. Object.defineProperties( this, {
  13916. shadowMapEnabled: {
  13917. get: function () {
  13918. return shadowMap.enabled;
  13919. },
  13920. set: function ( value ) {
  13921. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  13922. shadowMap.enabled = value;
  13923. }
  13924. },
  13925. shadowMapType: {
  13926. get: function () {
  13927. return shadowMap.type;
  13928. },
  13929. set: function ( value ) {
  13930. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  13931. shadowMap.type = value;
  13932. }
  13933. },
  13934. shadowMapCullFace: {
  13935. get: function () {
  13936. return shadowMap.cullFace;
  13937. },
  13938. set: function ( value ) {
  13939. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  13940. shadowMap.cullFace = value;
  13941. }
  13942. },
  13943. shadowMapDebug: {
  13944. get: function () {
  13945. return shadowMap.debug;
  13946. },
  13947. set: function ( value ) {
  13948. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  13949. shadowMap.debug = value;
  13950. }
  13951. }
  13952. } );
  13953. };
  13954. // File:src/renderers/WebGLRenderTarget.js
  13955. /**
  13956. * @author szimek / https://github.com/szimek/
  13957. * @author alteredq / http://alteredqualia.com/
  13958. */
  13959. THREE.WebGLRenderTarget = function ( width, height, options ) {
  13960. this.uuid = THREE.Math.generateUUID();
  13961. this.width = width;
  13962. this.height = height;
  13963. options = options || {};
  13964. this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
  13965. this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
  13966. this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
  13967. this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
  13968. this.anisotropy = options.anisotropy !== undefined ? options.anisotropy : 1;
  13969. this.offset = new THREE.Vector2( 0, 0 );
  13970. this.repeat = new THREE.Vector2( 1, 1 );
  13971. this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
  13972. this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
  13973. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  13974. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  13975. this.generateMipmaps = true;
  13976. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  13977. };
  13978. THREE.WebGLRenderTarget.prototype = {
  13979. constructor: THREE.WebGLRenderTarget,
  13980. setSize: function ( width, height ) {
  13981. if ( this.width !== width || this.height !== height ) {
  13982. this.width = width;
  13983. this.height = height;
  13984. this.dispose();
  13985. }
  13986. },
  13987. copy: function ( source ) {
  13988. this.width = source.width;
  13989. this.height = source.height;
  13990. this.wrapS = source.wrapS;
  13991. this.wrapT = source.wrapT;
  13992. this.magFilter = source.magFilter;
  13993. this.minFilter = source.minFilter;
  13994. this.anisotropy = source.anisotropy;
  13995. this.offset.copy( source.offset );
  13996. this.repeat.copy( source.repeat );
  13997. this.format = source.format;
  13998. this.type = source.type;
  13999. this.depthBuffer = source.depthBuffer;
  14000. this.stencilBuffer = source.stencilBuffer;
  14001. this.generateMipmaps = source.generateMipmaps;
  14002. this.shareDepthFrom = source.shareDepthFrom;
  14003. return this;
  14004. },
  14005. clone: function () {
  14006. return new THREE.WebGLRenderTarget().copy( this );
  14007. },
  14008. dispose: function () {
  14009. this.dispatchEvent( { type: 'dispose' } );
  14010. }
  14011. };
  14012. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  14013. // File:src/renderers/WebGLRenderTargetCube.js
  14014. /**
  14015. * @author alteredq / http://alteredqualia.com
  14016. */
  14017. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  14018. THREE.WebGLRenderTarget.call( this, width, height, options );
  14019. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  14020. };
  14021. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  14022. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  14023. // File:src/renderers/webgl/WebGLExtensions.js
  14024. /**
  14025. * @author mrdoob / http://mrdoob.com/
  14026. */
  14027. THREE.WebGLExtensions = function ( gl ) {
  14028. var extensions = {};
  14029. this.get = function ( name ) {
  14030. if ( extensions[ name ] !== undefined ) {
  14031. return extensions[ name ];
  14032. }
  14033. var extension;
  14034. switch ( name ) {
  14035. case 'EXT_texture_filter_anisotropic':
  14036. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  14037. break;
  14038. case 'WEBGL_compressed_texture_s3tc':
  14039. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  14040. break;
  14041. case 'WEBGL_compressed_texture_pvrtc':
  14042. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  14043. break;
  14044. default:
  14045. extension = gl.getExtension( name );
  14046. }
  14047. if ( extension === null ) {
  14048. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  14049. }
  14050. extensions[ name ] = extension;
  14051. return extension;
  14052. };
  14053. };
  14054. // File:src/renderers/webgl/WebGLGeometries.js
  14055. /**
  14056. * @author mrdoob / http://mrdoob.com/
  14057. */
  14058. THREE.WebGLGeometries = function ( gl, properties, info ) {
  14059. var geometries = {};
  14060. this.get = function ( object ) {
  14061. var geometry = object.geometry;
  14062. if ( geometries[ geometry.id ] !== undefined ) {
  14063. return geometries[ geometry.id ];
  14064. }
  14065. geometry.addEventListener( 'dispose', onGeometryDispose );
  14066. if ( geometry instanceof THREE.BufferGeometry ) {
  14067. geometries[ geometry.id ] = geometry;
  14068. } else if ( geometry instanceof THREE.Geometry ) {
  14069. if ( geometry._bufferGeometry === undefined ) {
  14070. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  14071. }
  14072. geometries[ geometry.id ] = geometry._bufferGeometry;
  14073. }
  14074. info.memory.geometries ++;
  14075. return geometries[ geometry.id ];
  14076. };
  14077. function onGeometryDispose( event ) {
  14078. var geometry = event.target;
  14079. var buffergeometry = geometries[ geometry.id ];
  14080. for ( var name in buffergeometry.attributes ) {
  14081. var attribute = buffergeometry.attributes[ name ];
  14082. var buffer = getAttributeBuffer( attribute );
  14083. if ( buffer !== undefined ) {
  14084. gl.deleteBuffer( buffer );
  14085. removeAttributeBuffer( attribute );
  14086. }
  14087. }
  14088. geometry.removeEventListener( 'dispose', onGeometryDispose );
  14089. delete geometries[ geometry.id ];
  14090. info.memory.geometries --;
  14091. }
  14092. function getAttributeBuffer( attribute ) {
  14093. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14094. return properties.get( attribute.data ).__webglBuffer;
  14095. }
  14096. return properties.get( attribute ).__webglBuffer;
  14097. }
  14098. function removeAttributeBuffer( attribute ) {
  14099. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14100. properties.delete( attribute.data );
  14101. } else {
  14102. properties.delete( attribute );
  14103. }
  14104. }
  14105. };
  14106. // File:src/renderers/webgl/WebGLObjects.js
  14107. /**
  14108. * @author mrdoob / http://mrdoob.com/
  14109. */
  14110. THREE.WebGLObjects = function ( gl, properties, info ) {
  14111. var objects = {};
  14112. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  14113. //
  14114. function onObjectRemoved( event ) {
  14115. var object = event.target;
  14116. object.traverse( function ( child ) {
  14117. child.removeEventListener( 'remove', onObjectRemoved );
  14118. removeObject( child );
  14119. } );
  14120. }
  14121. function removeObject( object ) {
  14122. if ( object instanceof THREE.Mesh ||
  14123. object instanceof THREE.PointCloud ||
  14124. object instanceof THREE.Line ) {
  14125. delete objects[ object.id ];
  14126. }
  14127. delete object._modelViewMatrix;
  14128. delete object._normalMatrix;
  14129. properties.delete( object );
  14130. }
  14131. //
  14132. this.objects = objects;
  14133. this.geometries = geometries;
  14134. this.init = function ( object ) {
  14135. var objectProperties = properties.get( object );
  14136. if ( objectProperties.__webglInit === undefined ) {
  14137. objectProperties.__webglInit = true;
  14138. object._modelViewMatrix = new THREE.Matrix4();
  14139. object._normalMatrix = new THREE.Matrix3();
  14140. object.addEventListener( 'removed', onObjectRemoved );
  14141. }
  14142. if ( objectProperties.__webglActive === undefined ) {
  14143. objectProperties.__webglActive = true;
  14144. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.PointCloud ) {
  14145. objects[ object.id ] = {
  14146. id: object.id,
  14147. object: object,
  14148. z: 0
  14149. };
  14150. }
  14151. }
  14152. };
  14153. function updateObject( object ) {
  14154. var geometry = geometries.get( object );
  14155. if ( object.geometry instanceof THREE.Geometry ) {
  14156. geometry.updateFromObject( object );
  14157. }
  14158. var attributes = geometry.attributes;
  14159. for ( var name in attributes ) {
  14160. updateAttribute( attributes[ name ], name );
  14161. }
  14162. // morph targets
  14163. var morphAttributes = geometry.morphAttributes;
  14164. for ( var name in morphAttributes ) {
  14165. var array = morphAttributes[ name ];
  14166. for ( var i = 0, l = array.length; i < l; i ++ ) {
  14167. updateAttribute( array[ i ], i );
  14168. }
  14169. }
  14170. }
  14171. function updateAttribute( attribute, name ) {
  14172. var bufferType = ( name === 'index' ) ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
  14173. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  14174. var attributeProperties = properties.get( data );
  14175. if ( attributeProperties.__webglBuffer === undefined ) {
  14176. createBuffer( attributeProperties, data, bufferType );
  14177. } else if ( attributeProperties.version !== data.version ) {
  14178. updateBuffer( attributeProperties, data, bufferType );
  14179. }
  14180. }
  14181. function createBuffer( attributeProperties, data, bufferType ) {
  14182. attributeProperties.__webglBuffer = gl.createBuffer();
  14183. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  14184. var usage = gl.STATIC_DRAW;
  14185. if ( data instanceof THREE.DynamicBufferAttribute
  14186. || ( data instanceof THREE.InstancedBufferAttribute && data.dynamic === true )
  14187. || ( data instanceof THREE.InterleavedBuffer && data.dynamic === true ) ) {
  14188. usage = gl.DYNAMIC_DRAW;
  14189. }
  14190. gl.bufferData( bufferType, data.array, usage );
  14191. attributeProperties.version = data.version;
  14192. }
  14193. function updateBuffer( attributeProperties, data, bufferType ) {
  14194. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  14195. if ( data.updateRange === undefined || data.updateRange.count === - 1 ) {
  14196. // Not using update ranges
  14197. gl.bufferSubData( bufferType, 0, data.array );
  14198. } else if ( data.updateRange.count === 0 ) {
  14199. 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.' );
  14200. } else {
  14201. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  14202. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  14203. data.updateRange.count = 0; // reset range
  14204. }
  14205. attributeProperties.version = data.version;
  14206. }
  14207. // returns the webgl buffer for a specified attribute
  14208. this.getAttributeBuffer = function ( attribute ) {
  14209. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14210. return properties.get( attribute.data ).__webglBuffer;
  14211. }
  14212. return properties.get( attribute ).__webglBuffer;
  14213. };
  14214. this.update = function ( renderList ) {
  14215. for ( var i = 0, ul = renderList.length; i < ul; i ++ ) {
  14216. var object = renderList[ i ].object;
  14217. if ( object.material.visible !== false ) {
  14218. updateObject( object );
  14219. }
  14220. }
  14221. };
  14222. this.clear = function () {
  14223. objects = {};
  14224. };
  14225. };
  14226. // File:src/renderers/webgl/WebGLProgram.js
  14227. THREE.WebGLProgram = ( function () {
  14228. var programIdCount = 0;
  14229. function generateDefines( defines ) {
  14230. var chunks = [];
  14231. for ( var name in defines ) {
  14232. var value = defines[ name ];
  14233. if ( value === false ) continue;
  14234. chunks.push( '#define ' + name + ' ' + value );
  14235. }
  14236. return chunks.join( '\n' );
  14237. }
  14238. function fetchUniformLocations( gl, program, identifiers ) {
  14239. var uniforms = {};
  14240. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  14241. for ( var i = 0; i < n; i ++ ) {
  14242. var info = gl.getActiveUniform( program, i );
  14243. var name = info.name;
  14244. var location = gl.getUniformLocation( program, name );
  14245. // console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  14246. var suffixPos = name.lastIndexOf( '[0]' );
  14247. if ( suffixPos !== - 1 && suffixPos === name.length - 3 ) {
  14248. uniforms[ name.substr( 0, suffixPos ) ] = location;
  14249. }
  14250. uniforms[ name ] = location;
  14251. }
  14252. return uniforms;
  14253. }
  14254. function fetchAttributeLocations( gl, program, identifiers ) {
  14255. var attributes = {};
  14256. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  14257. for ( var i = 0; i < n; i ++ ) {
  14258. var info = gl.getActiveAttrib( program, i );
  14259. var name = info.name;
  14260. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  14261. attributes[ name ] = gl.getAttribLocation( program, name );
  14262. }
  14263. return attributes;
  14264. }
  14265. function filterEmptyLine( string ) {
  14266. return string !== '';
  14267. }
  14268. return function WebGLProgram( renderer, code, material, parameters ) {
  14269. var gl = renderer.context;
  14270. var defines = material.defines;
  14271. var vertexShader = material.__webglShader.vertexShader;
  14272. var fragmentShader = material.__webglShader.fragmentShader;
  14273. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  14274. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  14275. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  14276. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  14277. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  14278. }
  14279. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14280. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  14281. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14282. if ( parameters.envMap ) {
  14283. switch ( material.envMap.mapping ) {
  14284. case THREE.CubeReflectionMapping:
  14285. case THREE.CubeRefractionMapping:
  14286. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14287. break;
  14288. case THREE.EquirectangularReflectionMapping:
  14289. case THREE.EquirectangularRefractionMapping:
  14290. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  14291. break;
  14292. case THREE.SphericalReflectionMapping:
  14293. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  14294. break;
  14295. }
  14296. switch ( material.envMap.mapping ) {
  14297. case THREE.CubeRefractionMapping:
  14298. case THREE.EquirectangularRefractionMapping:
  14299. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  14300. break;
  14301. }
  14302. switch ( material.combine ) {
  14303. case THREE.MultiplyOperation:
  14304. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14305. break;
  14306. case THREE.MixOperation:
  14307. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  14308. break;
  14309. case THREE.AddOperation:
  14310. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  14311. break;
  14312. }
  14313. }
  14314. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  14315. // console.log( 'building new program ' );
  14316. //
  14317. var customDefines = generateDefines( defines );
  14318. //
  14319. var program = gl.createProgram();
  14320. var prefixVertex, prefixFragment;
  14321. if ( material instanceof THREE.RawShaderMaterial ) {
  14322. prefixVertex = '';
  14323. prefixFragment = '';
  14324. } else {
  14325. prefixVertex = [
  14326. 'precision ' + parameters.precision + ' float;',
  14327. 'precision ' + parameters.precision + ' int;',
  14328. '#define SHADER_NAME ' + material.__webglShader.name,
  14329. customDefines,
  14330. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  14331. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14332. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14333. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14334. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14335. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14336. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14337. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14338. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14339. '#define MAX_BONES ' + parameters.maxBones,
  14340. parameters.map ? '#define USE_MAP' : '',
  14341. parameters.envMap ? '#define USE_ENVMAP' : '',
  14342. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14343. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14344. parameters.aoMap ? '#define USE_AOMAP' : '',
  14345. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14346. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14347. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14348. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14349. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14350. parameters.vertexColors ? '#define USE_COLOR' : '',
  14351. parameters.flatShading ? '#define FLAT_SHADED' : '',
  14352. parameters.skinning ? '#define USE_SKINNING' : '',
  14353. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  14354. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  14355. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  14356. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14357. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14358. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14359. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14360. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14361. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  14362. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14363. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14364. 'uniform mat4 modelMatrix;',
  14365. 'uniform mat4 modelViewMatrix;',
  14366. 'uniform mat4 projectionMatrix;',
  14367. 'uniform mat4 viewMatrix;',
  14368. 'uniform mat3 normalMatrix;',
  14369. 'uniform vec3 cameraPosition;',
  14370. 'attribute vec3 position;',
  14371. 'attribute vec3 normal;',
  14372. 'attribute vec2 uv;',
  14373. '#ifdef USE_COLOR',
  14374. ' attribute vec3 color;',
  14375. '#endif',
  14376. '#ifdef USE_MORPHTARGETS',
  14377. ' attribute vec3 morphTarget0;',
  14378. ' attribute vec3 morphTarget1;',
  14379. ' attribute vec3 morphTarget2;',
  14380. ' attribute vec3 morphTarget3;',
  14381. ' #ifdef USE_MORPHNORMALS',
  14382. ' attribute vec3 morphNormal0;',
  14383. ' attribute vec3 morphNormal1;',
  14384. ' attribute vec3 morphNormal2;',
  14385. ' attribute vec3 morphNormal3;',
  14386. ' #else',
  14387. ' attribute vec3 morphTarget4;',
  14388. ' attribute vec3 morphTarget5;',
  14389. ' attribute vec3 morphTarget6;',
  14390. ' attribute vec3 morphTarget7;',
  14391. ' #endif',
  14392. '#endif',
  14393. '#ifdef USE_SKINNING',
  14394. ' attribute vec4 skinIndex;',
  14395. ' attribute vec4 skinWeight;',
  14396. '#endif',
  14397. '\n'
  14398. ].filter( filterEmptyLine ).join( '\n' );
  14399. prefixFragment = [
  14400. ( parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  14401. 'precision ' + parameters.precision + ' float;',
  14402. 'precision ' + parameters.precision + ' int;',
  14403. '#define SHADER_NAME ' + material.__webglShader.name,
  14404. customDefines,
  14405. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14406. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14407. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14408. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14409. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14410. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  14411. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14412. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14413. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14414. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  14415. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  14416. parameters.map ? '#define USE_MAP' : '',
  14417. parameters.envMap ? '#define USE_ENVMAP' : '',
  14418. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  14419. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14420. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  14421. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14422. parameters.aoMap ? '#define USE_AOMAP' : '',
  14423. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14424. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14425. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14426. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14427. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14428. parameters.vertexColors ? '#define USE_COLOR' : '',
  14429. parameters.flatShading ? '#define FLAT_SHADED' : '',
  14430. parameters.metal ? '#define METAL' : '',
  14431. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14432. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14433. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14434. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14435. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14436. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14437. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14438. 'uniform mat4 viewMatrix;',
  14439. 'uniform vec3 cameraPosition;',
  14440. '\n'
  14441. ].filter( filterEmptyLine ).join( '\n' );
  14442. }
  14443. var vertexGlsl = prefixVertex + vertexShader;
  14444. var fragmentGlsl = prefixFragment + fragmentShader;
  14445. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  14446. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  14447. gl.attachShader( program, glVertexShader );
  14448. gl.attachShader( program, glFragmentShader );
  14449. // Force a particular attribute to index 0.
  14450. if ( material.index0AttributeName !== undefined ) {
  14451. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  14452. } else if ( parameters.morphTargets === true ) {
  14453. // programs with morphTargets displace position out of attribute 0
  14454. gl.bindAttribLocation( program, 0, 'position' );
  14455. }
  14456. gl.linkProgram( program );
  14457. var programLog = gl.getProgramInfoLog( program );
  14458. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  14459. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  14460. var runnable = true;
  14461. var haveDiagnostics = true;
  14462. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  14463. runnable = false;
  14464. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  14465. } else if ( programLog !== '' ) {
  14466. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  14467. } else if ( vertexLog === '' || fragmentLog === '' ) {
  14468. haveDiagnostics = false;
  14469. }
  14470. if ( haveDiagnostics ) {
  14471. this.diagnostics = {
  14472. runnable: runnable,
  14473. material: material,
  14474. programLog: programLog,
  14475. vertexShader: {
  14476. log: vertexLog,
  14477. prefix: prefixVertex
  14478. },
  14479. fragmentShader: {
  14480. log: fragmentLog,
  14481. prefix: prefixFragment
  14482. }
  14483. };
  14484. }
  14485. // clean up
  14486. gl.deleteShader( glVertexShader );
  14487. gl.deleteShader( glFragmentShader );
  14488. // set up caching for uniform locations
  14489. var cachedUniforms;
  14490. this.getUniforms = function() {
  14491. if ( cachedUniforms === undefined ) {
  14492. cachedUniforms = fetchUniformLocations( gl, program );
  14493. }
  14494. return cachedUniforms;
  14495. };
  14496. // set up caching for attribute locations
  14497. var cachedAttributes;
  14498. this.getAttributes = function() {
  14499. if ( cachedAttributes === undefined ) {
  14500. cachedAttributes = fetchAttributeLocations( gl, program );
  14501. }
  14502. return cachedAttributes;
  14503. };
  14504. // DEPRECATED
  14505. Object.defineProperties( this, {
  14506. uniforms: {
  14507. get: function() {
  14508. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  14509. return this.getUniforms();
  14510. }
  14511. },
  14512. attributes: {
  14513. get: function() {
  14514. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  14515. return this.getAttributes();
  14516. }
  14517. }
  14518. } );
  14519. //
  14520. this.id = programIdCount ++;
  14521. this.code = code;
  14522. this.usedTimes = 1;
  14523. this.program = program;
  14524. this.vertexShader = glVertexShader;
  14525. this.fragmentShader = glFragmentShader;
  14526. return this;
  14527. };
  14528. } )();
  14529. // File:src/renderers/webgl/WebGLProperties.js
  14530. /**
  14531. * @author fordacious / fordacious.github.io
  14532. */
  14533. THREE.WebGLProperties = function () {
  14534. var properties = {};
  14535. this.get = function ( object ) {
  14536. var uuid = object.uuid;
  14537. var map = properties[ uuid ];
  14538. if ( map === undefined ) {
  14539. map = {};
  14540. properties[ uuid ] = map;
  14541. }
  14542. return map;
  14543. };
  14544. this.delete = function ( object ) {
  14545. delete properties[ object.uuid ];
  14546. };
  14547. this.clear = function () {
  14548. properties = {};
  14549. };
  14550. };
  14551. // File:src/renderers/webgl/WebGLShader.js
  14552. THREE.WebGLShader = ( function () {
  14553. var addLineNumbers = function ( string ) {
  14554. var lines = string.split( '\n' );
  14555. for ( var i = 0; i < lines.length; i ++ ) {
  14556. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  14557. }
  14558. return lines.join( '\n' );
  14559. };
  14560. return function WebGLShader( gl, type, string ) {
  14561. var shader = gl.createShader( type );
  14562. gl.shaderSource( shader, string );
  14563. gl.compileShader( shader );
  14564. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  14565. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  14566. }
  14567. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  14568. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  14569. }
  14570. // --enable-privileged-webgl-extension
  14571. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  14572. return shader;
  14573. };
  14574. } )();
  14575. // File:src/renderers/webgl/WebGLShadowMap.js
  14576. /**
  14577. * @author alteredq / http://alteredqualia.com/
  14578. * @author mrdoob / http://mrdoob.com/
  14579. */
  14580. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  14581. var _gl = _renderer.context,
  14582. _state = _renderer.state,
  14583. _frustum = new THREE.Frustum(),
  14584. _projScreenMatrix = new THREE.Matrix4(),
  14585. _min = new THREE.Vector3(),
  14586. _max = new THREE.Vector3(),
  14587. _matrixPosition = new THREE.Vector3(),
  14588. _renderList = [];
  14589. // init
  14590. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  14591. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  14592. var _depthMaterial = new THREE.ShaderMaterial( {
  14593. uniforms: depthUniforms,
  14594. vertexShader: depthShader.vertexShader,
  14595. fragmentShader: depthShader.fragmentShader
  14596. } );
  14597. var _depthMaterialMorph = new THREE.ShaderMaterial( {
  14598. uniforms: depthUniforms,
  14599. vertexShader: depthShader.vertexShader,
  14600. fragmentShader: depthShader.fragmentShader,
  14601. morphTargets: true
  14602. } );
  14603. var _depthMaterialSkin = new THREE.ShaderMaterial( {
  14604. uniforms: depthUniforms,
  14605. vertexShader: depthShader.vertexShader,
  14606. fragmentShader: depthShader.fragmentShader,
  14607. skinning: true
  14608. } );
  14609. var _depthMaterialMorphSkin = new THREE.ShaderMaterial( {
  14610. uniforms: depthUniforms,
  14611. vertexShader: depthShader.vertexShader,
  14612. fragmentShader: depthShader.fragmentShader,
  14613. morphTargets: true,
  14614. skinning: true
  14615. } );
  14616. _depthMaterial._shadowPass = true;
  14617. _depthMaterialMorph._shadowPass = true;
  14618. _depthMaterialSkin._shadowPass = true;
  14619. _depthMaterialMorphSkin._shadowPass = true;
  14620. //
  14621. var scope = this;
  14622. this.enabled = false;
  14623. this.autoUpdate = true;
  14624. this.needsUpdate = false;
  14625. this.type = THREE.PCFShadowMap;
  14626. this.cullFace = THREE.CullFaceFront;
  14627. this.render = function ( scene, camera ) {
  14628. if ( scope.enabled === false ) return;
  14629. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  14630. // set GL state for depth map
  14631. _gl.clearColor( 1, 1, 1, 1 );
  14632. _state.disable( _gl.BLEND );
  14633. _state.enable( _gl.CULL_FACE );
  14634. _gl.frontFace( _gl.CCW );
  14635. if ( scope.cullFace === THREE.CullFaceFront ) {
  14636. _gl.cullFace( _gl.FRONT );
  14637. } else {
  14638. _gl.cullFace( _gl.BACK );
  14639. }
  14640. _state.setDepthTest( true );
  14641. // render depth map
  14642. for ( var i = 0, il = _lights.length; i < il; i ++ ) {
  14643. var light = _lights[ i ];
  14644. if ( ! light.castShadow ) continue;
  14645. if ( ! light.shadowMap ) {
  14646. var shadowFilter = THREE.LinearFilter;
  14647. if ( scope.type === THREE.PCFSoftShadowMap ) {
  14648. shadowFilter = THREE.NearestFilter;
  14649. }
  14650. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  14651. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  14652. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  14653. light.shadowMatrix = new THREE.Matrix4();
  14654. }
  14655. if ( ! light.shadowCamera ) {
  14656. if ( light instanceof THREE.SpotLight ) {
  14657. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  14658. } else if ( light instanceof THREE.DirectionalLight ) {
  14659. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  14660. } else {
  14661. console.error( "THREE.ShadowMapPlugin: Unsupported light type for shadow", light );
  14662. continue;
  14663. }
  14664. scene.add( light.shadowCamera );
  14665. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14666. }
  14667. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  14668. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  14669. scene.add( light.cameraHelper );
  14670. }
  14671. var shadowMap = light.shadowMap;
  14672. var shadowMatrix = light.shadowMatrix;
  14673. var shadowCamera = light.shadowCamera;
  14674. //
  14675. shadowCamera.position.setFromMatrixPosition( light.matrixWorld );
  14676. _matrixPosition.setFromMatrixPosition( light.target.matrixWorld );
  14677. shadowCamera.lookAt( _matrixPosition );
  14678. shadowCamera.updateMatrixWorld();
  14679. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  14680. //
  14681. if ( light.cameraHelper ) light.cameraHelper.visible = light.shadowCameraVisible;
  14682. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  14683. // compute shadow matrix
  14684. shadowMatrix.set(
  14685. 0.5, 0.0, 0.0, 0.5,
  14686. 0.0, 0.5, 0.0, 0.5,
  14687. 0.0, 0.0, 0.5, 0.5,
  14688. 0.0, 0.0, 0.0, 1.0
  14689. );
  14690. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  14691. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  14692. // update camera matrices and frustum
  14693. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  14694. _frustum.setFromMatrix( _projScreenMatrix );
  14695. // render shadow map
  14696. _renderer.setRenderTarget( shadowMap );
  14697. _renderer.clear();
  14698. // set object matrices & frustum culling
  14699. _renderList.length = 0;
  14700. projectObject( scene, shadowCamera );
  14701. // render regular objects
  14702. var webglObject, object, material;
  14703. var objectMaterial, useMorphing, useSkinning;
  14704. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  14705. webglObject = _renderList[ j ];
  14706. object = webglObject.object;
  14707. // culling is overridden globally for all objects
  14708. // while rendering depth map
  14709. // need to deal with MeshFaceMaterial somehow
  14710. // in that case just use the first of material.materials for now
  14711. // (proper solution would require to break objects by materials
  14712. // similarly to regular rendering and then set corresponding
  14713. // depth materials per each chunk instead of just once per object)
  14714. objectMaterial = getObjectMaterial( object );
  14715. useMorphing = object.geometry.morphTargets !== undefined && object.geometry.morphTargets.length > 0 && objectMaterial.morphTargets;
  14716. useSkinning = object instanceof THREE.SkinnedMesh && objectMaterial.skinning;
  14717. if ( object.customDepthMaterial ) {
  14718. material = object.customDepthMaterial;
  14719. } else if ( useSkinning ) {
  14720. material = useMorphing ? _depthMaterialMorphSkin : _depthMaterialSkin;
  14721. } else if ( useMorphing ) {
  14722. material = _depthMaterialMorph;
  14723. } else {
  14724. material = _depthMaterial;
  14725. }
  14726. _renderer.renderBufferDirect( shadowCamera, _lights, null, material, object );
  14727. }
  14728. }
  14729. // restore GL state
  14730. var clearColor = _renderer.getClearColor(),
  14731. clearAlpha = _renderer.getClearAlpha();
  14732. _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
  14733. _state.enable( _gl.BLEND );
  14734. if ( scope.cullFace === THREE.CullFaceFront ) {
  14735. _gl.cullFace( _gl.BACK );
  14736. }
  14737. _renderer.resetGLState();
  14738. scope.needsUpdate = false;
  14739. };
  14740. function projectObject( object, camera ) {
  14741. if ( object.visible === true ) {
  14742. var webglObject = _objects.objects[ object.id ];
  14743. if ( webglObject && object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  14744. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14745. _renderList.push( webglObject );
  14746. }
  14747. for ( var i = 0, l = object.children.length; i < l; i ++ ) {
  14748. projectObject( object.children[ i ], camera );
  14749. }
  14750. }
  14751. }
  14752. // For the moment just ignore objects that have multiple materials with different animation methods
  14753. // Only the first material will be taken into account for deciding which depth material to use for shadow maps
  14754. function getObjectMaterial( object ) {
  14755. return object.material instanceof THREE.MeshFaceMaterial
  14756. ? object.material.materials[ 0 ]
  14757. : object.material;
  14758. }
  14759. };
  14760. // File:src/renderers/webgl/WebGLState.js
  14761. /**
  14762. * @author mrdoob / http://mrdoob.com/
  14763. */
  14764. THREE.WebGLState = function ( gl, paramThreeToGL ) {
  14765. var _this = this;
  14766. var newAttributes = new Uint8Array( 16 );
  14767. var enabledAttributes = new Uint8Array( 16 );
  14768. var capabilities = {};
  14769. var currentBlending = null;
  14770. var currentBlendEquation = null;
  14771. var currentBlendSrc = null;
  14772. var currentBlendDst = null;
  14773. var currentBlendEquationAlpha = null;
  14774. var currentBlendSrcAlpha = null;
  14775. var currentBlendDstAlpha = null;
  14776. var currentDepthFunc = null;
  14777. var currentDepthWrite = null;
  14778. var currentColorWrite = null;
  14779. var currentFlipSided = null;
  14780. var currentLineWidth = null;
  14781. var currentPolygonOffsetFactor = null;
  14782. var currentPolygonOffsetUnits = null;
  14783. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14784. var currentTextureSlot = undefined;
  14785. var currentBoundTextures = {};
  14786. this.init = function () {
  14787. gl.clearColor( 0, 0, 0, 1 );
  14788. gl.clearDepth( 1 );
  14789. gl.clearStencil( 0 );
  14790. this.enable( gl.DEPTH_TEST );
  14791. gl.depthFunc( gl.LEQUAL );
  14792. gl.frontFace( gl.CCW );
  14793. gl.cullFace( gl.BACK );
  14794. this.enable( gl.CULL_FACE );
  14795. this.enable( gl.BLEND );
  14796. gl.blendEquation( gl.FUNC_ADD );
  14797. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  14798. };
  14799. this.initAttributes = function () {
  14800. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  14801. newAttributes[ i ] = 0;
  14802. }
  14803. };
  14804. this.enableAttribute = function ( attribute ) {
  14805. newAttributes[ attribute ] = 1;
  14806. if ( enabledAttributes[ attribute ] === 0 ) {
  14807. gl.enableVertexAttribArray( attribute );
  14808. enabledAttributes[ attribute ] = 1;
  14809. }
  14810. };
  14811. this.disableUnusedAttributes = function () {
  14812. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  14813. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  14814. gl.disableVertexAttribArray( i );
  14815. enabledAttributes[ i ] = 0;
  14816. }
  14817. }
  14818. };
  14819. this.enable = function ( id ) {
  14820. if ( capabilities[ id ] !== true ) {
  14821. gl.enable( id );
  14822. capabilities[ id ] = true;
  14823. }
  14824. };
  14825. this.disable = function ( id ) {
  14826. if ( capabilities[ id ] !== false ) {
  14827. gl.disable( id );
  14828. capabilities[ id ] = false;
  14829. }
  14830. };
  14831. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  14832. if ( blending !== currentBlending ) {
  14833. if ( blending === THREE.NoBlending ) {
  14834. this.disable( gl.BLEND );
  14835. } else if ( blending === THREE.AdditiveBlending ) {
  14836. this.enable( gl.BLEND );
  14837. gl.blendEquation( gl.FUNC_ADD );
  14838. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  14839. } else if ( blending === THREE.SubtractiveBlending ) {
  14840. // TODO: Find blendFuncSeparate() combination
  14841. this.enable( gl.BLEND );
  14842. gl.blendEquation( gl.FUNC_ADD );
  14843. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  14844. } else if ( blending === THREE.MultiplyBlending ) {
  14845. // TODO: Find blendFuncSeparate() combination
  14846. this.enable( gl.BLEND );
  14847. gl.blendEquation( gl.FUNC_ADD );
  14848. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  14849. } else if ( blending === THREE.CustomBlending ) {
  14850. this.enable( gl.BLEND );
  14851. } else {
  14852. this.enable( gl.BLEND );
  14853. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  14854. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  14855. }
  14856. currentBlending = blending;
  14857. }
  14858. if ( blending === THREE.CustomBlending ) {
  14859. blendEquationAlpha = blendEquationAlpha || blendEquation;
  14860. blendSrcAlpha = blendSrcAlpha || blendSrc;
  14861. blendDstAlpha = blendDstAlpha || blendDst;
  14862. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  14863. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  14864. currentBlendEquation = blendEquation;
  14865. currentBlendEquationAlpha = blendEquationAlpha;
  14866. }
  14867. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  14868. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  14869. currentBlendSrc = blendSrc;
  14870. currentBlendDst = blendDst;
  14871. currentBlendSrcAlpha = blendSrcAlpha;
  14872. currentBlendDstAlpha = blendDstAlpha;
  14873. }
  14874. } else {
  14875. currentBlendEquation = null;
  14876. currentBlendSrc = null;
  14877. currentBlendDst = null;
  14878. currentBlendEquationAlpha = null;
  14879. currentBlendSrcAlpha = null;
  14880. currentBlendDstAlpha = null;
  14881. }
  14882. };
  14883. this.setDepthFunc = function ( depthFunc ) {
  14884. if ( currentDepthFunc !== depthFunc ) {
  14885. if ( depthFunc ) {
  14886. switch ( depthFunc ) {
  14887. case THREE.NeverDepth:
  14888. gl.depthFunc( gl.NEVER );
  14889. break;
  14890. case THREE.AlwaysDepth:
  14891. gl.depthFunc( gl.ALWAYS );
  14892. break;
  14893. case THREE.LessDepth:
  14894. gl.depthFunc( gl.LESS );
  14895. break;
  14896. case THREE.LessEqualDepth:
  14897. gl.depthFunc( gl.LEQUAL );
  14898. break;
  14899. case THREE.EqualDepth:
  14900. gl.depthFunc( gl.EQUAL );
  14901. break;
  14902. case THREE.GreaterEqualDepth:
  14903. gl.depthFunc( gl.GEQUAL );
  14904. break;
  14905. case THREE.GreaterDepth:
  14906. gl.depthFunc( gl.GREATER );
  14907. break;
  14908. case THREE.NotEqualDepth:
  14909. gl.depthFunc( gl.NOTEQUAL );
  14910. break;
  14911. default:
  14912. gl.depthFunc( gl.LEQUAL );
  14913. }
  14914. } else {
  14915. gl.depthFunc( gl.LEQUAL );
  14916. }
  14917. currentDepthFunc = depthFunc;
  14918. }
  14919. };
  14920. this.setDepthTest = function ( depthTest ) {
  14921. if ( depthTest ) {
  14922. this.enable( gl.DEPTH_TEST );
  14923. } else {
  14924. this.disable( gl.DEPTH_TEST );
  14925. }
  14926. };
  14927. this.setDepthWrite = function ( depthWrite ) {
  14928. if ( currentDepthWrite !== depthWrite ) {
  14929. gl.depthMask( depthWrite );
  14930. currentDepthWrite = depthWrite;
  14931. }
  14932. };
  14933. this.setColorWrite = function ( colorWrite ) {
  14934. if ( currentColorWrite !== colorWrite ) {
  14935. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  14936. currentColorWrite = colorWrite;
  14937. }
  14938. };
  14939. this.setFlipSided = function ( flipSided ) {
  14940. if ( currentFlipSided !== flipSided ) {
  14941. if ( flipSided ) {
  14942. gl.frontFace( gl.CW );
  14943. } else {
  14944. gl.frontFace( gl.CCW );
  14945. }
  14946. currentFlipSided = flipSided;
  14947. }
  14948. };
  14949. this.setLineWidth = function ( width ) {
  14950. if ( width !== currentLineWidth ) {
  14951. gl.lineWidth( width );
  14952. currentLineWidth = width;
  14953. }
  14954. };
  14955. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  14956. if ( polygonOffset ) {
  14957. this.enable( gl.POLYGON_OFFSET_FILL );
  14958. } else {
  14959. this.disable( gl.POLYGON_OFFSET_FILL );
  14960. }
  14961. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  14962. gl.polygonOffset( factor, units );
  14963. currentPolygonOffsetFactor = factor;
  14964. currentPolygonOffsetUnits = units;
  14965. }
  14966. };
  14967. this.setScissorTest = function ( scissorTest ) {
  14968. if ( scissorTest ) {
  14969. this.enable( gl.SCISSOR_TEST );
  14970. } else {
  14971. this.disable( gl.SCISSOR_TEST );
  14972. }
  14973. };
  14974. // texture
  14975. this.activeTexture = function ( webglSlot ) {
  14976. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  14977. if ( currentTextureSlot !== webglSlot ) {
  14978. gl.activeTexture( webglSlot );
  14979. currentTextureSlot = webglSlot;
  14980. }
  14981. }
  14982. this.bindTexture = function ( webglType, webglTexture ) {
  14983. if ( currentTextureSlot === undefined ) {
  14984. _this.activeTexture();
  14985. }
  14986. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  14987. if ( boundTexture === undefined ) {
  14988. boundTexture = { type: undefined, texture: undefined };
  14989. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  14990. }
  14991. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  14992. gl.bindTexture( webglType, webglTexture );
  14993. boundTexture.type = webglType;
  14994. boundTexture.texture = webglTexture;
  14995. }
  14996. };
  14997. this.compressedTexImage2D = function () {
  14998. try {
  14999. gl.compressedTexImage2D.apply( gl, arguments );
  15000. } catch ( error ) {
  15001. console.error( error );
  15002. }
  15003. };
  15004. this.texImage2D = function () {
  15005. try {
  15006. gl.texImage2D.apply( gl, arguments );
  15007. } catch ( error ) {
  15008. console.error( error );
  15009. }
  15010. };
  15011. //
  15012. this.reset = function () {
  15013. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  15014. if ( enabledAttributes[ i ] === 1 ) {
  15015. gl.disableVertexAttribArray( i );
  15016. enabledAttributes[ i ] = 0;
  15017. }
  15018. }
  15019. capabilities = {};
  15020. currentBlending = null;
  15021. currentDepthWrite = null;
  15022. currentColorWrite = null;
  15023. currentFlipSided = null;
  15024. };
  15025. };
  15026. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  15027. /**
  15028. * @author mikael emtinger / http://gomo.se/
  15029. * @author alteredq / http://alteredqualia.com/
  15030. */
  15031. THREE.LensFlarePlugin = function ( renderer, flares ) {
  15032. var gl = renderer.context;
  15033. var state = renderer.state;
  15034. var vertexBuffer, elementBuffer;
  15035. var program, attributes, uniforms;
  15036. var hasVertexTexture;
  15037. var tempTexture, occlusionTexture;
  15038. var init = function () {
  15039. var vertices = new Float32Array( [
  15040. - 1, - 1, 0, 0,
  15041. 1, - 1, 1, 0,
  15042. 1, 1, 1, 1,
  15043. - 1, 1, 0, 1
  15044. ] );
  15045. var faces = new Uint16Array( [
  15046. 0, 1, 2,
  15047. 0, 2, 3
  15048. ] );
  15049. // buffers
  15050. vertexBuffer = gl.createBuffer();
  15051. elementBuffer = gl.createBuffer();
  15052. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15053. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15054. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15055. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15056. // textures
  15057. tempTexture = gl.createTexture();
  15058. occlusionTexture = gl.createTexture();
  15059. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15060. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  15061. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15062. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15063. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15064. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15065. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15066. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  15067. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15068. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15069. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15070. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15071. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  15072. var shader;
  15073. if ( hasVertexTexture ) {
  15074. shader = {
  15075. vertexShader: [
  15076. "uniform lowp int renderType;",
  15077. "uniform vec3 screenPosition;",
  15078. "uniform vec2 scale;",
  15079. "uniform float rotation;",
  15080. "uniform sampler2D occlusionMap;",
  15081. "attribute vec2 position;",
  15082. "attribute vec2 uv;",
  15083. "varying vec2 vUV;",
  15084. "varying float vVisibility;",
  15085. "void main() {",
  15086. "vUV = uv;",
  15087. "vec2 pos = position;",
  15088. "if( renderType == 2 ) {",
  15089. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  15090. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  15091. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  15092. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  15093. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  15094. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  15095. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  15096. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  15097. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  15098. "vVisibility = visibility.r / 9.0;",
  15099. "vVisibility *= 1.0 - visibility.g / 9.0;",
  15100. "vVisibility *= visibility.b / 9.0;",
  15101. "vVisibility *= 1.0 - visibility.a / 9.0;",
  15102. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15103. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15104. "}",
  15105. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15106. "}"
  15107. ].join( "\n" ),
  15108. fragmentShader: [
  15109. "uniform lowp int renderType;",
  15110. "uniform sampler2D map;",
  15111. "uniform float opacity;",
  15112. "uniform vec3 color;",
  15113. "varying vec2 vUV;",
  15114. "varying float vVisibility;",
  15115. "void main() {",
  15116. // pink square
  15117. "if( renderType == 0 ) {",
  15118. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  15119. // restore
  15120. "} else if( renderType == 1 ) {",
  15121. "gl_FragColor = texture2D( map, vUV );",
  15122. // flare
  15123. "} else {",
  15124. "vec4 texture = texture2D( map, vUV );",
  15125. "texture.a *= opacity * vVisibility;",
  15126. "gl_FragColor = texture;",
  15127. "gl_FragColor.rgb *= color;",
  15128. "}",
  15129. "}"
  15130. ].join( "\n" )
  15131. };
  15132. } else {
  15133. shader = {
  15134. vertexShader: [
  15135. "uniform lowp int renderType;",
  15136. "uniform vec3 screenPosition;",
  15137. "uniform vec2 scale;",
  15138. "uniform float rotation;",
  15139. "attribute vec2 position;",
  15140. "attribute vec2 uv;",
  15141. "varying vec2 vUV;",
  15142. "void main() {",
  15143. "vUV = uv;",
  15144. "vec2 pos = position;",
  15145. "if( renderType == 2 ) {",
  15146. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15147. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15148. "}",
  15149. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15150. "}"
  15151. ].join( "\n" ),
  15152. fragmentShader: [
  15153. "precision mediump float;",
  15154. "uniform lowp int renderType;",
  15155. "uniform sampler2D map;",
  15156. "uniform sampler2D occlusionMap;",
  15157. "uniform float opacity;",
  15158. "uniform vec3 color;",
  15159. "varying vec2 vUV;",
  15160. "void main() {",
  15161. // pink square
  15162. "if( renderType == 0 ) {",
  15163. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  15164. // restore
  15165. "} else if( renderType == 1 ) {",
  15166. "gl_FragColor = texture2D( map, vUV );",
  15167. // flare
  15168. "} else {",
  15169. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  15170. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  15171. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  15172. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  15173. "visibility = ( 1.0 - visibility / 4.0 );",
  15174. "vec4 texture = texture2D( map, vUV );",
  15175. "texture.a *= opacity * visibility;",
  15176. "gl_FragColor = texture;",
  15177. "gl_FragColor.rgb *= color;",
  15178. "}",
  15179. "}"
  15180. ].join( "\n" )
  15181. };
  15182. }
  15183. program = createProgram( shader );
  15184. attributes = {
  15185. vertex: gl.getAttribLocation ( program, "position" ),
  15186. uv: gl.getAttribLocation ( program, "uv" )
  15187. };
  15188. uniforms = {
  15189. renderType: gl.getUniformLocation( program, "renderType" ),
  15190. map: gl.getUniformLocation( program, "map" ),
  15191. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  15192. opacity: gl.getUniformLocation( program, "opacity" ),
  15193. color: gl.getUniformLocation( program, "color" ),
  15194. scale: gl.getUniformLocation( program, "scale" ),
  15195. rotation: gl.getUniformLocation( program, "rotation" ),
  15196. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  15197. };
  15198. };
  15199. /*
  15200. * Render lens flares
  15201. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  15202. * reads these back and calculates occlusion.
  15203. */
  15204. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  15205. if ( flares.length === 0 ) return;
  15206. var tempPosition = new THREE.Vector3();
  15207. var invAspect = viewportHeight / viewportWidth,
  15208. halfViewportWidth = viewportWidth * 0.5,
  15209. halfViewportHeight = viewportHeight * 0.5;
  15210. var size = 16 / viewportHeight,
  15211. scale = new THREE.Vector2( size * invAspect, size );
  15212. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  15213. screenPositionPixels = new THREE.Vector2( 1, 1 );
  15214. if ( program === undefined ) {
  15215. init();
  15216. }
  15217. gl.useProgram( program );
  15218. state.initAttributes();
  15219. state.enableAttribute( attributes.vertex );
  15220. state.enableAttribute( attributes.uv );
  15221. state.disableUnusedAttributes();
  15222. // loop through all lens flares to update their occlusion and positions
  15223. // setup gl and common used attribs/uniforms
  15224. gl.uniform1i( uniforms.occlusionMap, 0 );
  15225. gl.uniform1i( uniforms.map, 1 );
  15226. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15227. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  15228. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15229. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15230. state.disable( gl.CULL_FACE );
  15231. gl.depthMask( false );
  15232. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  15233. size = 16 / viewportHeight;
  15234. scale.set( size * invAspect, size );
  15235. // calc object screen position
  15236. var flare = flares[ i ];
  15237. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  15238. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  15239. tempPosition.applyProjection( camera.projectionMatrix );
  15240. // setup arrays for gl programs
  15241. screenPosition.copy( tempPosition );
  15242. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  15243. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  15244. // screen cull
  15245. if ( hasVertexTexture || (
  15246. screenPositionPixels.x > 0 &&
  15247. screenPositionPixels.x < viewportWidth &&
  15248. screenPositionPixels.y > 0 &&
  15249. screenPositionPixels.y < viewportHeight ) ) {
  15250. // save current RGB to temp texture
  15251. state.activeTexture( gl.TEXTURE0 );
  15252. state.bindTexture( gl.TEXTURE_2D, null );
  15253. state.activeTexture( gl.TEXTURE1 );
  15254. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15255. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15256. // render pink quad
  15257. gl.uniform1i( uniforms.renderType, 0 );
  15258. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15259. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15260. state.disable( gl.BLEND );
  15261. state.enable( gl.DEPTH_TEST );
  15262. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15263. // copy result to occlusionMap
  15264. state.activeTexture( gl.TEXTURE0 );
  15265. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15266. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15267. // restore graphics
  15268. gl.uniform1i( uniforms.renderType, 1 );
  15269. state.disable( gl.DEPTH_TEST );
  15270. state.activeTexture( gl.TEXTURE1 );
  15271. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15272. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15273. // update object positions
  15274. flare.positionScreen.copy( screenPosition );
  15275. if ( flare.customUpdateCallback ) {
  15276. flare.customUpdateCallback( flare );
  15277. } else {
  15278. flare.updateLensFlares();
  15279. }
  15280. // render flares
  15281. gl.uniform1i( uniforms.renderType, 2 );
  15282. state.enable( gl.BLEND );
  15283. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  15284. var sprite = flare.lensFlares[ j ];
  15285. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  15286. screenPosition.x = sprite.x;
  15287. screenPosition.y = sprite.y;
  15288. screenPosition.z = sprite.z;
  15289. size = sprite.size * sprite.scale / viewportHeight;
  15290. scale.x = size * invAspect;
  15291. scale.y = size;
  15292. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15293. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15294. gl.uniform1f( uniforms.rotation, sprite.rotation );
  15295. gl.uniform1f( uniforms.opacity, sprite.opacity );
  15296. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  15297. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  15298. renderer.setTexture( sprite.texture, 1 );
  15299. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15300. }
  15301. }
  15302. }
  15303. }
  15304. // restore gl
  15305. state.enable( gl.CULL_FACE );
  15306. state.enable( gl.DEPTH_TEST );
  15307. gl.depthMask( true );
  15308. renderer.resetGLState();
  15309. };
  15310. function createProgram ( shader ) {
  15311. var program = gl.createProgram();
  15312. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15313. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15314. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  15315. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  15316. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  15317. gl.compileShader( fragmentShader );
  15318. gl.compileShader( vertexShader );
  15319. gl.attachShader( program, fragmentShader );
  15320. gl.attachShader( program, vertexShader );
  15321. gl.linkProgram( program );
  15322. return program;
  15323. }
  15324. };
  15325. // File:src/renderers/webgl/plugins/SpritePlugin.js
  15326. /**
  15327. * @author mikael emtinger / http://gomo.se/
  15328. * @author alteredq / http://alteredqualia.com/
  15329. */
  15330. THREE.SpritePlugin = function ( renderer, sprites ) {
  15331. var gl = renderer.context;
  15332. var state = renderer.state;
  15333. var vertexBuffer, elementBuffer;
  15334. var program, attributes, uniforms;
  15335. var texture;
  15336. // decompose matrixWorld
  15337. var spritePosition = new THREE.Vector3();
  15338. var spriteRotation = new THREE.Quaternion();
  15339. var spriteScale = new THREE.Vector3();
  15340. var init = function () {
  15341. var vertices = new Float32Array( [
  15342. - 0.5, - 0.5, 0, 0,
  15343. 0.5, - 0.5, 1, 0,
  15344. 0.5, 0.5, 1, 1,
  15345. - 0.5, 0.5, 0, 1
  15346. ] );
  15347. var faces = new Uint16Array( [
  15348. 0, 1, 2,
  15349. 0, 2, 3
  15350. ] );
  15351. vertexBuffer = gl.createBuffer();
  15352. elementBuffer = gl.createBuffer();
  15353. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15354. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15355. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15356. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15357. program = createProgram();
  15358. attributes = {
  15359. position: gl.getAttribLocation ( program, 'position' ),
  15360. uv: gl.getAttribLocation ( program, 'uv' )
  15361. };
  15362. uniforms = {
  15363. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  15364. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  15365. rotation: gl.getUniformLocation( program, 'rotation' ),
  15366. scale: gl.getUniformLocation( program, 'scale' ),
  15367. color: gl.getUniformLocation( program, 'color' ),
  15368. map: gl.getUniformLocation( program, 'map' ),
  15369. opacity: gl.getUniformLocation( program, 'opacity' ),
  15370. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  15371. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  15372. fogType: gl.getUniformLocation( program, 'fogType' ),
  15373. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  15374. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  15375. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  15376. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  15377. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  15378. };
  15379. var canvas = document.createElement( 'canvas' );
  15380. canvas.width = 8;
  15381. canvas.height = 8;
  15382. var context = canvas.getContext( '2d' );
  15383. context.fillStyle = 'white';
  15384. context.fillRect( 0, 0, 8, 8 );
  15385. texture = new THREE.Texture( canvas );
  15386. texture.needsUpdate = true;
  15387. };
  15388. this.render = function ( scene, camera ) {
  15389. if ( sprites.length === 0 ) return;
  15390. // setup gl
  15391. if ( program === undefined ) {
  15392. init();
  15393. }
  15394. gl.useProgram( program );
  15395. state.initAttributes();
  15396. state.enableAttribute( attributes.position );
  15397. state.enableAttribute( attributes.uv );
  15398. state.disableUnusedAttributes();
  15399. state.disable( gl.CULL_FACE );
  15400. state.enable( gl.BLEND );
  15401. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15402. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  15403. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15404. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15405. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15406. state.activeTexture( gl.TEXTURE0 );
  15407. gl.uniform1i( uniforms.map, 0 );
  15408. var oldFogType = 0;
  15409. var sceneFogType = 0;
  15410. var fog = scene.fog;
  15411. if ( fog ) {
  15412. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  15413. if ( fog instanceof THREE.Fog ) {
  15414. gl.uniform1f( uniforms.fogNear, fog.near );
  15415. gl.uniform1f( uniforms.fogFar, fog.far );
  15416. gl.uniform1i( uniforms.fogType, 1 );
  15417. oldFogType = 1;
  15418. sceneFogType = 1;
  15419. } else if ( fog instanceof THREE.FogExp2 ) {
  15420. gl.uniform1f( uniforms.fogDensity, fog.density );
  15421. gl.uniform1i( uniforms.fogType, 2 );
  15422. oldFogType = 2;
  15423. sceneFogType = 2;
  15424. }
  15425. } else {
  15426. gl.uniform1i( uniforms.fogType, 0 );
  15427. oldFogType = 0;
  15428. sceneFogType = 0;
  15429. }
  15430. // update positions and sort
  15431. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15432. var sprite = sprites[ i ];
  15433. sprite._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  15434. sprite.z = - sprite._modelViewMatrix.elements[ 14 ];
  15435. }
  15436. sprites.sort( painterSortStable );
  15437. // render all sprites
  15438. var scale = [];
  15439. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15440. var sprite = sprites[ i ];
  15441. var material = sprite.material;
  15442. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  15443. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements );
  15444. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  15445. scale[ 0 ] = spriteScale.x;
  15446. scale[ 1 ] = spriteScale.y;
  15447. var fogType = 0;
  15448. if ( scene.fog && material.fog ) {
  15449. fogType = sceneFogType;
  15450. }
  15451. if ( oldFogType !== fogType ) {
  15452. gl.uniform1i( uniforms.fogType, fogType );
  15453. oldFogType = fogType;
  15454. }
  15455. if ( material.map !== null ) {
  15456. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  15457. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  15458. } else {
  15459. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  15460. gl.uniform2f( uniforms.uvScale, 1, 1 );
  15461. }
  15462. gl.uniform1f( uniforms.opacity, material.opacity );
  15463. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  15464. gl.uniform1f( uniforms.rotation, material.rotation );
  15465. gl.uniform2fv( uniforms.scale, scale );
  15466. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  15467. state.setDepthTest( material.depthTest );
  15468. state.setDepthWrite( material.depthWrite );
  15469. if ( material.map && material.map.image && material.map.image.width ) {
  15470. renderer.setTexture( material.map, 0 );
  15471. } else {
  15472. renderer.setTexture( texture, 0 );
  15473. }
  15474. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15475. }
  15476. // restore gl
  15477. state.enable( gl.CULL_FACE );
  15478. renderer.resetGLState();
  15479. };
  15480. function createProgram () {
  15481. var program = gl.createProgram();
  15482. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15483. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15484. gl.shaderSource( vertexShader, [
  15485. 'precision ' + renderer.getPrecision() + ' float;',
  15486. 'uniform mat4 modelViewMatrix;',
  15487. 'uniform mat4 projectionMatrix;',
  15488. 'uniform float rotation;',
  15489. 'uniform vec2 scale;',
  15490. 'uniform vec2 uvOffset;',
  15491. 'uniform vec2 uvScale;',
  15492. 'attribute vec2 position;',
  15493. 'attribute vec2 uv;',
  15494. 'varying vec2 vUV;',
  15495. 'void main() {',
  15496. 'vUV = uvOffset + uv * uvScale;',
  15497. 'vec2 alignedPosition = position * scale;',
  15498. 'vec2 rotatedPosition;',
  15499. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  15500. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  15501. 'vec4 finalPosition;',
  15502. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  15503. 'finalPosition.xy += rotatedPosition;',
  15504. 'finalPosition = projectionMatrix * finalPosition;',
  15505. 'gl_Position = finalPosition;',
  15506. '}'
  15507. ].join( '\n' ) );
  15508. gl.shaderSource( fragmentShader, [
  15509. 'precision ' + renderer.getPrecision() + ' float;',
  15510. 'uniform vec3 color;',
  15511. 'uniform sampler2D map;',
  15512. 'uniform float opacity;',
  15513. 'uniform int fogType;',
  15514. 'uniform vec3 fogColor;',
  15515. 'uniform float fogDensity;',
  15516. 'uniform float fogNear;',
  15517. 'uniform float fogFar;',
  15518. 'uniform float alphaTest;',
  15519. 'varying vec2 vUV;',
  15520. 'void main() {',
  15521. 'vec4 texture = texture2D( map, vUV );',
  15522. 'if ( texture.a < alphaTest ) discard;',
  15523. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  15524. 'if ( fogType > 0 ) {',
  15525. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  15526. 'float fogFactor = 0.0;',
  15527. 'if ( fogType == 1 ) {',
  15528. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  15529. '} else {',
  15530. 'const float LOG2 = 1.442695;',
  15531. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  15532. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  15533. '}',
  15534. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  15535. '}',
  15536. '}'
  15537. ].join( '\n' ) );
  15538. gl.compileShader( vertexShader );
  15539. gl.compileShader( fragmentShader );
  15540. gl.attachShader( program, vertexShader );
  15541. gl.attachShader( program, fragmentShader );
  15542. gl.linkProgram( program );
  15543. return program;
  15544. }
  15545. function painterSortStable ( a, b ) {
  15546. if ( a.z !== b.z ) {
  15547. return b.z - a.z;
  15548. } else {
  15549. return b.id - a.id;
  15550. }
  15551. }
  15552. };
  15553. // File:src/extras/GeometryUtils.js
  15554. /**
  15555. * @author mrdoob / http://mrdoob.com/
  15556. */
  15557. THREE.GeometryUtils = {
  15558. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  15559. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  15560. var matrix;
  15561. if ( geometry2 instanceof THREE.Mesh ) {
  15562. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  15563. matrix = geometry2.matrix;
  15564. geometry2 = geometry2.geometry;
  15565. }
  15566. geometry1.merge( geometry2, matrix, materialIndexOffset );
  15567. },
  15568. center: function ( geometry ) {
  15569. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  15570. return geometry.center();
  15571. }
  15572. };
  15573. // File:src/extras/ImageUtils.js
  15574. /**
  15575. * @author alteredq / http://alteredqualia.com/
  15576. * @author mrdoob / http://mrdoob.com/
  15577. * @author Daosheng Mu / https://github.com/DaoshengMu/
  15578. */
  15579. THREE.ImageUtils = {
  15580. crossOrigin: undefined,
  15581. loadTexture: function ( url, mapping, onLoad, onError ) {
  15582. var loader = new THREE.ImageLoader();
  15583. loader.crossOrigin = this.crossOrigin;
  15584. var texture = new THREE.Texture( undefined, mapping );
  15585. loader.load( url, function ( image ) {
  15586. texture.image = image;
  15587. texture.needsUpdate = true;
  15588. if ( onLoad ) onLoad( texture );
  15589. }, undefined, function ( event ) {
  15590. if ( onError ) onError( event );
  15591. } );
  15592. texture.sourceFile = url;
  15593. return texture;
  15594. },
  15595. loadTextureCube: function ( array, mapping, onLoad, onError ) {
  15596. var images = [];
  15597. var loader = new THREE.ImageLoader();
  15598. loader.crossOrigin = this.crossOrigin;
  15599. var texture = new THREE.CubeTexture( images, mapping );
  15600. var loaded = 0;
  15601. var loadTexture = function ( i ) {
  15602. loader.load( array[ i ], function ( image ) {
  15603. texture.images[ i ] = image;
  15604. loaded += 1;
  15605. if ( loaded === 6 ) {
  15606. texture.needsUpdate = true;
  15607. if ( onLoad ) onLoad( texture );
  15608. }
  15609. }, undefined, onError );
  15610. };
  15611. for ( var i = 0, il = array.length; i < il; ++ i ) {
  15612. loadTexture( i );
  15613. }
  15614. return texture;
  15615. },
  15616. loadCompressedTexture: function () {
  15617. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  15618. },
  15619. loadCompressedTextureCube: function () {
  15620. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  15621. },
  15622. getNormalMap: function ( image, depth ) {
  15623. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  15624. var cross = function ( a, b ) {
  15625. 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 ] ];
  15626. };
  15627. var subtract = function ( a, b ) {
  15628. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  15629. };
  15630. var normalize = function ( a ) {
  15631. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  15632. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  15633. };
  15634. depth = depth | 1;
  15635. var width = image.width;
  15636. var height = image.height;
  15637. var canvas = document.createElement( 'canvas' );
  15638. canvas.width = width;
  15639. canvas.height = height;
  15640. var context = canvas.getContext( '2d' );
  15641. context.drawImage( image, 0, 0 );
  15642. var data = context.getImageData( 0, 0, width, height ).data;
  15643. var imageData = context.createImageData( width, height );
  15644. var output = imageData.data;
  15645. for ( var x = 0; x < width; x ++ ) {
  15646. for ( var y = 0; y < height; y ++ ) {
  15647. var ly = y - 1 < 0 ? 0 : y - 1;
  15648. var uy = y + 1 > height - 1 ? height - 1 : y + 1;
  15649. var lx = x - 1 < 0 ? 0 : x - 1;
  15650. var ux = x + 1 > width - 1 ? width - 1 : x + 1;
  15651. var points = [];
  15652. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  15653. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  15654. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  15655. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  15656. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  15657. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  15658. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  15659. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  15660. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  15661. var normals = [];
  15662. var num_points = points.length;
  15663. for ( var i = 0; i < num_points; i ++ ) {
  15664. var v1 = points[ i ];
  15665. var v2 = points[ ( i + 1 ) % num_points ];
  15666. v1 = subtract( v1, origin );
  15667. v2 = subtract( v2, origin );
  15668. normals.push( normalize( cross( v1, v2 ) ) );
  15669. }
  15670. var normal = [ 0, 0, 0 ];
  15671. for ( var i = 0; i < normals.length; i ++ ) {
  15672. normal[ 0 ] += normals[ i ][ 0 ];
  15673. normal[ 1 ] += normals[ i ][ 1 ];
  15674. normal[ 2 ] += normals[ i ][ 2 ];
  15675. }
  15676. normal[ 0 ] /= normals.length;
  15677. normal[ 1 ] /= normals.length;
  15678. normal[ 2 ] /= normals.length;
  15679. var idx = ( y * width + x ) * 4;
  15680. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15681. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15682. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  15683. output[ idx + 3 ] = 255;
  15684. }
  15685. }
  15686. context.putImageData( imageData, 0, 0 );
  15687. return canvas;
  15688. },
  15689. generateDataTexture: function ( width, height, color ) {
  15690. var size = width * height;
  15691. var data = new Uint8Array( 3 * size );
  15692. var r = Math.floor( color.r * 255 );
  15693. var g = Math.floor( color.g * 255 );
  15694. var b = Math.floor( color.b * 255 );
  15695. for ( var i = 0; i < size; i ++ ) {
  15696. data[ i * 3 ] = r;
  15697. data[ i * 3 + 1 ] = g;
  15698. data[ i * 3 + 2 ] = b;
  15699. }
  15700. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  15701. texture.needsUpdate = true;
  15702. return texture;
  15703. }
  15704. };
  15705. // File:src/extras/SceneUtils.js
  15706. /**
  15707. * @author alteredq / http://alteredqualia.com/
  15708. */
  15709. THREE.SceneUtils = {
  15710. createMultiMaterialObject: function ( geometry, materials ) {
  15711. var group = new THREE.Object3D();
  15712. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  15713. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  15714. }
  15715. return group;
  15716. },
  15717. detach: function ( child, parent, scene ) {
  15718. child.applyMatrix( parent.matrixWorld );
  15719. parent.remove( child );
  15720. scene.add( child );
  15721. },
  15722. attach: function ( child, scene, parent ) {
  15723. var matrixWorldInverse = new THREE.Matrix4();
  15724. matrixWorldInverse.getInverse( parent.matrixWorld );
  15725. child.applyMatrix( matrixWorldInverse );
  15726. scene.remove( child );
  15727. parent.add( child );
  15728. }
  15729. };
  15730. // File:src/extras/FontUtils.js
  15731. /**
  15732. * @author zz85 / http://www.lab4games.net/zz85/blog
  15733. * @author alteredq / http://alteredqualia.com/
  15734. *
  15735. * For Text operations in three.js (See TextGeometry)
  15736. *
  15737. * It uses techniques used in:
  15738. *
  15739. * Triangulation ported from AS3
  15740. * Simple Polygon Triangulation
  15741. * http://actionsnippet.com/?p=1462
  15742. *
  15743. * A Method to triangulate shapes with holes
  15744. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  15745. *
  15746. */
  15747. THREE.FontUtils = {
  15748. faces: {},
  15749. // Just for now. face[weight][style]
  15750. face: 'helvetiker',
  15751. weight: 'normal',
  15752. style: 'normal',
  15753. size: 150,
  15754. divisions: 10,
  15755. getFace: function () {
  15756. try {
  15757. return this.faces[ this.face.toLowerCase() ][ this.weight ][ this.style ];
  15758. } catch ( e ) {
  15759. throw "The font " + this.face + " with " + this.weight + " weight and " + this.style + " style is missing."
  15760. }
  15761. },
  15762. loadFace: function ( data ) {
  15763. var family = data.familyName.toLowerCase();
  15764. var ThreeFont = this;
  15765. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  15766. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  15767. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15768. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15769. return data;
  15770. },
  15771. drawText: function ( text ) {
  15772. // RenderText
  15773. var i,
  15774. face = this.getFace(),
  15775. scale = this.size / face.resolution,
  15776. offset = 0,
  15777. chars = String( text ).split( '' ),
  15778. length = chars.length;
  15779. var fontPaths = [];
  15780. for ( i = 0; i < length; i ++ ) {
  15781. var path = new THREE.Path();
  15782. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  15783. offset += ret.offset;
  15784. fontPaths.push( ret.path );
  15785. }
  15786. // get the width
  15787. var width = offset / 2;
  15788. //
  15789. // for ( p = 0; p < allPts.length; p++ ) {
  15790. //
  15791. // allPts[ p ].x -= width;
  15792. //
  15793. // }
  15794. //var extract = this.extractPoints( allPts, characterPts );
  15795. //extract.contour = allPts;
  15796. //extract.paths = fontPaths;
  15797. //extract.offset = width;
  15798. return { paths: fontPaths, offset: width };
  15799. },
  15800. extractGlyphPoints: function ( c, face, scale, offset, path ) {
  15801. var pts = [];
  15802. var i, i2, divisions,
  15803. outline, action, length,
  15804. scaleX, scaleY,
  15805. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  15806. laste,
  15807. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  15808. if ( ! glyph ) return;
  15809. if ( glyph.o ) {
  15810. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  15811. length = outline.length;
  15812. scaleX = scale;
  15813. scaleY = scale;
  15814. for ( i = 0; i < length; ) {
  15815. action = outline[ i ++ ];
  15816. //console.log( action );
  15817. switch ( action ) {
  15818. case 'm':
  15819. // Move To
  15820. x = outline[ i ++ ] * scaleX + offset;
  15821. y = outline[ i ++ ] * scaleY;
  15822. path.moveTo( x, y );
  15823. break;
  15824. case 'l':
  15825. // Line To
  15826. x = outline[ i ++ ] * scaleX + offset;
  15827. y = outline[ i ++ ] * scaleY;
  15828. path.lineTo( x, y );
  15829. break;
  15830. case 'q':
  15831. // QuadraticCurveTo
  15832. cpx = outline[ i ++ ] * scaleX + offset;
  15833. cpy = outline[ i ++ ] * scaleY;
  15834. cpx1 = outline[ i ++ ] * scaleX + offset;
  15835. cpy1 = outline[ i ++ ] * scaleY;
  15836. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  15837. laste = pts[ pts.length - 1 ];
  15838. if ( laste ) {
  15839. cpx0 = laste.x;
  15840. cpy0 = laste.y;
  15841. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15842. var t = i2 / divisions;
  15843. THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  15844. THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  15845. }
  15846. }
  15847. break;
  15848. case 'b':
  15849. // Cubic Bezier Curve
  15850. cpx = outline[ i ++ ] * scaleX + offset;
  15851. cpy = outline[ i ++ ] * scaleY;
  15852. cpx1 = outline[ i ++ ] * scaleX + offset;
  15853. cpy1 = outline[ i ++ ] * scaleY;
  15854. cpx2 = outline[ i ++ ] * scaleX + offset;
  15855. cpy2 = outline[ i ++ ] * scaleY;
  15856. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  15857. laste = pts[ pts.length - 1 ];
  15858. if ( laste ) {
  15859. cpx0 = laste.x;
  15860. cpy0 = laste.y;
  15861. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15862. var t = i2 / divisions;
  15863. THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  15864. THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  15865. }
  15866. }
  15867. break;
  15868. }
  15869. }
  15870. }
  15871. return { offset: glyph.ha * scale, path: path };
  15872. }
  15873. };
  15874. THREE.FontUtils.generateShapes = function ( text, parameters ) {
  15875. // Parameters
  15876. parameters = parameters || {};
  15877. var size = parameters.size !== undefined ? parameters.size : 100;
  15878. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments : 4;
  15879. var font = parameters.font !== undefined ? parameters.font : 'helvetiker';
  15880. var weight = parameters.weight !== undefined ? parameters.weight : 'normal';
  15881. var style = parameters.style !== undefined ? parameters.style : 'normal';
  15882. THREE.FontUtils.size = size;
  15883. THREE.FontUtils.divisions = curveSegments;
  15884. THREE.FontUtils.face = font;
  15885. THREE.FontUtils.weight = weight;
  15886. THREE.FontUtils.style = style;
  15887. // Get a Font data json object
  15888. var data = THREE.FontUtils.drawText( text );
  15889. var paths = data.paths;
  15890. var shapes = [];
  15891. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  15892. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  15893. }
  15894. return shapes;
  15895. };
  15896. /**
  15897. * This code is a quick port of code written in C++ which was submitted to
  15898. * flipcode.com by John W. Ratcliff // July 22, 2000
  15899. * See original code and more information here:
  15900. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  15901. *
  15902. * ported to actionscript by Zevan Rosser
  15903. * www.actionsnippet.com
  15904. *
  15905. * ported to javascript by Joshua Koo
  15906. * http://www.lab4games.net/zz85/blog
  15907. *
  15908. */
  15909. ( function ( namespace ) {
  15910. var EPSILON = 0.0000000001;
  15911. // takes in an contour array and returns
  15912. var process = function ( contour, indices ) {
  15913. var n = contour.length;
  15914. if ( n < 3 ) return null;
  15915. var result = [],
  15916. verts = [],
  15917. vertIndices = [];
  15918. /* we want a counter-clockwise polygon in verts */
  15919. var u, v, w;
  15920. if ( area( contour ) > 0.0 ) {
  15921. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  15922. } else {
  15923. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  15924. }
  15925. var nv = n;
  15926. /* remove nv - 2 vertices, creating 1 triangle every time */
  15927. var count = 2 * nv; /* error detection */
  15928. for ( v = nv - 1; nv > 2; ) {
  15929. /* if we loop, it is probably a non-simple polygon */
  15930. if ( ( count -- ) <= 0 ) {
  15931. //** Triangulate: ERROR - probable bad polygon!
  15932. //throw ( "Warning, unable to triangulate polygon!" );
  15933. //return null;
  15934. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  15935. console.warn( 'THREE.FontUtils: Warning, unable to triangulate polygon! in Triangulate.process()' );
  15936. if ( indices ) return vertIndices;
  15937. return result;
  15938. }
  15939. /* three consecutive vertices in current polygon, <u,v,w> */
  15940. u = v; if ( nv <= u ) u = 0; /* previous */
  15941. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  15942. w = v + 1; if ( nv <= w ) w = 0; /* next */
  15943. if ( snip( contour, u, v, w, nv, verts ) ) {
  15944. var a, b, c, s, t;
  15945. /* true names of the vertices */
  15946. a = verts[ u ];
  15947. b = verts[ v ];
  15948. c = verts[ w ];
  15949. /* output Triangle */
  15950. result.push( [ contour[ a ],
  15951. contour[ b ],
  15952. contour[ c ] ] );
  15953. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  15954. /* remove v from the remaining polygon */
  15955. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  15956. verts[ s ] = verts[ t ];
  15957. }
  15958. nv --;
  15959. /* reset error detection counter */
  15960. count = 2 * nv;
  15961. }
  15962. }
  15963. if ( indices ) return vertIndices;
  15964. return result;
  15965. };
  15966. // calculate area of the contour polygon
  15967. var area = function ( contour ) {
  15968. var n = contour.length;
  15969. var a = 0.0;
  15970. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  15971. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  15972. }
  15973. return a * 0.5;
  15974. };
  15975. var snip = function ( contour, u, v, w, n, verts ) {
  15976. var p;
  15977. var ax, ay, bx, by;
  15978. var cx, cy, px, py;
  15979. ax = contour[ verts[ u ] ].x;
  15980. ay = contour[ verts[ u ] ].y;
  15981. bx = contour[ verts[ v ] ].x;
  15982. by = contour[ verts[ v ] ].y;
  15983. cx = contour[ verts[ w ] ].x;
  15984. cy = contour[ verts[ w ] ].y;
  15985. if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  15986. var aX, aY, bX, bY, cX, cY;
  15987. var apx, apy, bpx, bpy, cpx, cpy;
  15988. var cCROSSap, bCROSScp, aCROSSbp;
  15989. aX = cx - bx; aY = cy - by;
  15990. bX = ax - cx; bY = ay - cy;
  15991. cX = bx - ax; cY = by - ay;
  15992. for ( p = 0; p < n; p ++ ) {
  15993. px = contour[ verts[ p ] ].x;
  15994. py = contour[ verts[ p ] ].y;
  15995. if ( ( ( px === ax ) && ( py === ay ) ) ||
  15996. ( ( px === bx ) && ( py === by ) ) ||
  15997. ( ( px === cx ) && ( py === cy ) ) ) continue;
  15998. apx = px - ax; apy = py - ay;
  15999. bpx = px - bx; bpy = py - by;
  16000. cpx = px - cx; cpy = py - cy;
  16001. // see if p is inside triangle abc
  16002. aCROSSbp = aX * bpy - aY * bpx;
  16003. cCROSSap = cX * apy - cY * apx;
  16004. bCROSScp = bX * cpy - bY * cpx;
  16005. if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
  16006. }
  16007. return true;
  16008. };
  16009. namespace.Triangulate = process;
  16010. namespace.Triangulate.area = area;
  16011. return namespace;
  16012. } )( THREE.FontUtils );
  16013. // To use the typeface.js face files, hook up the API
  16014. THREE.typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  16015. if ( typeof self !== 'undefined' ) self._typeface_js = THREE.typeface_js;
  16016. // File:src/extras/audio/Audio.js
  16017. /**
  16018. * @author mrdoob / http://mrdoob.com/
  16019. */
  16020. THREE.Audio = function ( listener ) {
  16021. THREE.Object3D.call( this );
  16022. this.type = 'Audio';
  16023. this.context = listener.context;
  16024. this.source = this.context.createBufferSource();
  16025. this.source.onended = this.onEnded.bind( this );
  16026. this.gain = this.context.createGain();
  16027. this.gain.connect( this.context.destination );
  16028. this.panner = this.context.createPanner();
  16029. this.panner.connect( this.gain );
  16030. this.autoplay = false;
  16031. this.startTime = 0;
  16032. this.playbackRate = 1;
  16033. this.isPlaying = false;
  16034. };
  16035. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  16036. THREE.Audio.prototype.constructor = THREE.Audio;
  16037. THREE.Audio.prototype.load = function ( file ) {
  16038. var scope = this;
  16039. var request = new XMLHttpRequest();
  16040. request.open( 'GET', file, true );
  16041. request.responseType = 'arraybuffer';
  16042. request.onload = function ( e ) {
  16043. scope.context.decodeAudioData( this.response, function ( buffer ) {
  16044. scope.source.buffer = buffer;
  16045. if ( scope.autoplay ) scope.play();
  16046. } );
  16047. };
  16048. request.send();
  16049. return this;
  16050. };
  16051. THREE.Audio.prototype.play = function () {
  16052. if ( this.isPlaying === true ) {
  16053. console.warn( 'THREE.Audio: Audio is already playing.' );
  16054. return;
  16055. }
  16056. var source = this.context.createBufferSource();
  16057. source.buffer = this.source.buffer;
  16058. source.loop = this.source.loop;
  16059. source.onended = this.source.onended;
  16060. source.start( 0, this.startTime );
  16061. source.playbackRate.value = this.playbackRate;
  16062. this.isPlaying = true;
  16063. this.source = source;
  16064. this.connect();
  16065. };
  16066. THREE.Audio.prototype.pause = function () {
  16067. this.source.stop();
  16068. this.startTime = this.context.currentTime;
  16069. };
  16070. THREE.Audio.prototype.stop = function () {
  16071. this.source.stop();
  16072. this.startTime = 0;
  16073. };
  16074. THREE.Audio.prototype.connect = function () {
  16075. if ( this.filter !== undefined ) {
  16076. this.source.connect( this.filter );
  16077. this.filter.connect( this.panner );
  16078. } else {
  16079. this.source.connect( this.panner );
  16080. }
  16081. };
  16082. THREE.Audio.prototype.disconnect = function () {
  16083. if ( this.filter !== undefined ) {
  16084. this.source.disconnect( this.filter );
  16085. this.filter.disconnect( this.panner );
  16086. } else {
  16087. this.source.disconnect( this.panner );
  16088. }
  16089. };
  16090. THREE.Audio.prototype.setFilter = function ( value ) {
  16091. if ( this.isPlaying === true ) {
  16092. this.disconnect();
  16093. this.filter = value;
  16094. this.connect();
  16095. } else {
  16096. this.filter = value;
  16097. }
  16098. };
  16099. THREE.Audio.prototype.getFilter = function () {
  16100. return this.filter;
  16101. };
  16102. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  16103. this.playbackRate = value;
  16104. if ( this.isPlaying === true ) {
  16105. this.source.playbackRate.value = this.playbackRate;
  16106. }
  16107. };
  16108. THREE.Audio.prototype.getPlaybackRate = function () {
  16109. return this.playbackRate;
  16110. };
  16111. THREE.Audio.prototype.onEnded = function() {
  16112. this.isPlaying = false;
  16113. };
  16114. THREE.Audio.prototype.setLoop = function ( value ) {
  16115. this.source.loop = value;
  16116. };
  16117. THREE.Audio.prototype.getLoop = function () {
  16118. return this.source.loop;
  16119. };
  16120. THREE.Audio.prototype.setRefDistance = function ( value ) {
  16121. this.panner.refDistance = value;
  16122. };
  16123. THREE.Audio.prototype.getRefDistance = function () {
  16124. return this.panner.refDistance;
  16125. };
  16126. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  16127. this.panner.rolloffFactor = value;
  16128. };
  16129. THREE.Audio.prototype.getRolloffFactor = function () {
  16130. return this.panner.rolloffFactor;
  16131. };
  16132. THREE.Audio.prototype.setVolume = function ( value ) {
  16133. this.gain.gain.value = value;
  16134. };
  16135. THREE.Audio.prototype.getVolume = function () {
  16136. return this.gain.gain.value;
  16137. };
  16138. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  16139. var position = new THREE.Vector3();
  16140. return function updateMatrixWorld( force ) {
  16141. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16142. position.setFromMatrixPosition( this.matrixWorld );
  16143. this.panner.setPosition( position.x, position.y, position.z );
  16144. };
  16145. } )();
  16146. // File:src/extras/audio/AudioListener.js
  16147. /**
  16148. * @author mrdoob / http://mrdoob.com/
  16149. */
  16150. THREE.AudioListener = function () {
  16151. THREE.Object3D.call( this );
  16152. this.type = 'AudioListener';
  16153. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  16154. };
  16155. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  16156. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  16157. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  16158. var position = new THREE.Vector3();
  16159. var quaternion = new THREE.Quaternion();
  16160. var scale = new THREE.Vector3();
  16161. var orientation = new THREE.Vector3();
  16162. return function updateMatrixWorld( force ) {
  16163. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16164. var listener = this.context.listener;
  16165. var up = this.up;
  16166. this.matrixWorld.decompose( position, quaternion, scale );
  16167. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  16168. listener.setPosition( position.x, position.y, position.z );
  16169. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  16170. };
  16171. } )();
  16172. // File:src/extras/core/Curve.js
  16173. /**
  16174. * @author zz85 / http://www.lab4games.net/zz85/blog
  16175. * Extensible curve object
  16176. *
  16177. * Some common of Curve methods
  16178. * .getPoint(t), getTangent(t)
  16179. * .getPointAt(u), getTagentAt(u)
  16180. * .getPoints(), .getSpacedPoints()
  16181. * .getLength()
  16182. * .updateArcLengths()
  16183. *
  16184. * This following classes subclasses THREE.Curve:
  16185. *
  16186. * -- 2d classes --
  16187. * THREE.LineCurve
  16188. * THREE.QuadraticBezierCurve
  16189. * THREE.CubicBezierCurve
  16190. * THREE.SplineCurve
  16191. * THREE.ArcCurve
  16192. * THREE.EllipseCurve
  16193. *
  16194. * -- 3d classes --
  16195. * THREE.LineCurve3
  16196. * THREE.QuadraticBezierCurve3
  16197. * THREE.CubicBezierCurve3
  16198. * THREE.SplineCurve3
  16199. * THREE.ClosedSplineCurve3
  16200. *
  16201. * A series of curves can be represented as a THREE.CurvePath
  16202. *
  16203. **/
  16204. /**************************************************************
  16205. * Abstract Curve base class
  16206. **************************************************************/
  16207. THREE.Curve = function () {
  16208. };
  16209. // Virtual base class method to overwrite and implement in subclasses
  16210. // - t [0 .. 1]
  16211. THREE.Curve.prototype.getPoint = function ( t ) {
  16212. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  16213. return null;
  16214. };
  16215. // Get point at relative position in curve according to arc length
  16216. // - u [0 .. 1]
  16217. THREE.Curve.prototype.getPointAt = function ( u ) {
  16218. var t = this.getUtoTmapping( u );
  16219. return this.getPoint( t );
  16220. };
  16221. // Get sequence of points using getPoint( t )
  16222. THREE.Curve.prototype.getPoints = function ( divisions ) {
  16223. if ( ! divisions ) divisions = 5;
  16224. var d, pts = [];
  16225. for ( d = 0; d <= divisions; d ++ ) {
  16226. pts.push( this.getPoint( d / divisions ) );
  16227. }
  16228. return pts;
  16229. };
  16230. // Get sequence of points using getPointAt( u )
  16231. THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
  16232. if ( ! divisions ) divisions = 5;
  16233. var d, pts = [];
  16234. for ( d = 0; d <= divisions; d ++ ) {
  16235. pts.push( this.getPointAt( d / divisions ) );
  16236. }
  16237. return pts;
  16238. };
  16239. // Get total curve arc length
  16240. THREE.Curve.prototype.getLength = function () {
  16241. var lengths = this.getLengths();
  16242. return lengths[ lengths.length - 1 ];
  16243. };
  16244. // Get list of cumulative segment lengths
  16245. THREE.Curve.prototype.getLengths = function ( divisions ) {
  16246. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  16247. if ( this.cacheArcLengths
  16248. && ( this.cacheArcLengths.length === divisions + 1 )
  16249. && ! this.needsUpdate ) {
  16250. //console.log( "cached", this.cacheArcLengths );
  16251. return this.cacheArcLengths;
  16252. }
  16253. this.needsUpdate = false;
  16254. var cache = [];
  16255. var current, last = this.getPoint( 0 );
  16256. var p, sum = 0;
  16257. cache.push( 0 );
  16258. for ( p = 1; p <= divisions; p ++ ) {
  16259. current = this.getPoint ( p / divisions );
  16260. sum += current.distanceTo( last );
  16261. cache.push( sum );
  16262. last = current;
  16263. }
  16264. this.cacheArcLengths = cache;
  16265. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  16266. };
  16267. THREE.Curve.prototype.updateArcLengths = function() {
  16268. this.needsUpdate = true;
  16269. this.getLengths();
  16270. };
  16271. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  16272. THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
  16273. var arcLengths = this.getLengths();
  16274. var i = 0, il = arcLengths.length;
  16275. var targetArcLength; // The targeted u distance value to get
  16276. if ( distance ) {
  16277. targetArcLength = distance;
  16278. } else {
  16279. targetArcLength = u * arcLengths[ il - 1 ];
  16280. }
  16281. //var time = Date.now();
  16282. // binary search for the index with largest value smaller than target u distance
  16283. var low = 0, high = il - 1, comparison;
  16284. while ( low <= high ) {
  16285. 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
  16286. comparison = arcLengths[ i ] - targetArcLength;
  16287. if ( comparison < 0 ) {
  16288. low = i + 1;
  16289. } else if ( comparison > 0 ) {
  16290. high = i - 1;
  16291. } else {
  16292. high = i;
  16293. break;
  16294. // DONE
  16295. }
  16296. }
  16297. i = high;
  16298. //console.log('b' , i, low, high, Date.now()- time);
  16299. if ( arcLengths[ i ] === targetArcLength ) {
  16300. var t = i / ( il - 1 );
  16301. return t;
  16302. }
  16303. // we could get finer grain at lengths, or use simple interpolation between two points
  16304. var lengthBefore = arcLengths[ i ];
  16305. var lengthAfter = arcLengths[ i + 1 ];
  16306. var segmentLength = lengthAfter - lengthBefore;
  16307. // determine where we are between the 'before' and 'after' points
  16308. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  16309. // add that fractional amount to t
  16310. var t = ( i + segmentFraction ) / ( il - 1 );
  16311. return t;
  16312. };
  16313. // Returns a unit vector tangent at t
  16314. // In case any sub curve does not implement its tangent derivation,
  16315. // 2 points a small delta apart will be used to find its gradient
  16316. // which seems to give a reasonable approximation
  16317. THREE.Curve.prototype.getTangent = function( t ) {
  16318. var delta = 0.0001;
  16319. var t1 = t - delta;
  16320. var t2 = t + delta;
  16321. // Capping in case of danger
  16322. if ( t1 < 0 ) t1 = 0;
  16323. if ( t2 > 1 ) t2 = 1;
  16324. var pt1 = this.getPoint( t1 );
  16325. var pt2 = this.getPoint( t2 );
  16326. var vec = pt2.clone().sub( pt1 );
  16327. return vec.normalize();
  16328. };
  16329. THREE.Curve.prototype.getTangentAt = function ( u ) {
  16330. var t = this.getUtoTmapping( u );
  16331. return this.getTangent( t );
  16332. };
  16333. /**************************************************************
  16334. * Utils
  16335. **************************************************************/
  16336. THREE.Curve.Utils = {
  16337. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  16338. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  16339. },
  16340. // Puay Bing, thanks for helping with this derivative!
  16341. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  16342. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  16343. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  16344. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  16345. 3 * t * t * p3;
  16346. },
  16347. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  16348. // To check if my formulas are correct
  16349. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  16350. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  16351. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  16352. var h11 = 3 * t * t - 2 * t; // t3 − t2
  16353. return h00 + h10 + h01 + h11;
  16354. },
  16355. // Catmull-Rom
  16356. interpolate: function( p0, p1, p2, p3, t ) {
  16357. var v0 = ( p2 - p0 ) * 0.5;
  16358. var v1 = ( p3 - p1 ) * 0.5;
  16359. var t2 = t * t;
  16360. var t3 = t * t2;
  16361. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  16362. }
  16363. };
  16364. // TODO: Transformation for Curves?
  16365. /**************************************************************
  16366. * 3D Curves
  16367. **************************************************************/
  16368. // A Factory method for creating new curve subclasses
  16369. THREE.Curve.create = function ( constructor, getPointFunc ) {
  16370. constructor.prototype = Object.create( THREE.Curve.prototype );
  16371. constructor.prototype.constructor = constructor;
  16372. constructor.prototype.getPoint = getPointFunc;
  16373. return constructor;
  16374. };
  16375. // File:src/extras/core/CurvePath.js
  16376. /**
  16377. * @author zz85 / http://www.lab4games.net/zz85/blog
  16378. *
  16379. **/
  16380. /**************************************************************
  16381. * Curved Path - a curve path is simply a array of connected
  16382. * curves, but retains the api of a curve
  16383. **************************************************************/
  16384. THREE.CurvePath = function () {
  16385. this.curves = [];
  16386. this.bends = [];
  16387. this.autoClose = false; // Automatically closes the path
  16388. };
  16389. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  16390. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  16391. THREE.CurvePath.prototype.add = function ( curve ) {
  16392. this.curves.push( curve );
  16393. };
  16394. THREE.CurvePath.prototype.checkConnection = function() {
  16395. // TODO
  16396. // If the ending of curve is not connected to the starting
  16397. // or the next curve, then, this is not a real path
  16398. };
  16399. THREE.CurvePath.prototype.closePath = function() {
  16400. // TODO Test
  16401. // and verify for vector3 (needs to implement equals)
  16402. // Add a line curve if start and end of lines are not connected
  16403. var startPoint = this.curves[ 0 ].getPoint( 0 );
  16404. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  16405. if ( ! startPoint.equals( endPoint ) ) {
  16406. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  16407. }
  16408. };
  16409. // To get accurate point with reference to
  16410. // entire path distance at time t,
  16411. // following has to be done:
  16412. // 1. Length of each sub path have to be known
  16413. // 2. Locate and identify type of curve
  16414. // 3. Get t for the curve
  16415. // 4. Return curve.getPointAt(t')
  16416. THREE.CurvePath.prototype.getPoint = function( t ) {
  16417. var d = t * this.getLength();
  16418. var curveLengths = this.getCurveLengths();
  16419. var i = 0, diff, curve;
  16420. // To think about boundaries points.
  16421. while ( i < curveLengths.length ) {
  16422. if ( curveLengths[ i ] >= d ) {
  16423. diff = curveLengths[ i ] - d;
  16424. curve = this.curves[ i ];
  16425. var u = 1 - diff / curve.getLength();
  16426. return curve.getPointAt( u );
  16427. }
  16428. i ++;
  16429. }
  16430. return null;
  16431. // loop where sum != 0, sum > d , sum+1 <d
  16432. };
  16433. /*
  16434. THREE.CurvePath.prototype.getTangent = function( t ) {
  16435. };*/
  16436. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  16437. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  16438. // getPoint() depends on getLength
  16439. THREE.CurvePath.prototype.getLength = function() {
  16440. var lens = this.getCurveLengths();
  16441. return lens[ lens.length - 1 ];
  16442. };
  16443. // Compute lengths and cache them
  16444. // We cannot overwrite getLengths() because UtoT mapping uses it.
  16445. THREE.CurvePath.prototype.getCurveLengths = function() {
  16446. // We use cache values if curves and cache array are same length
  16447. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  16448. return this.cacheLengths;
  16449. }
  16450. // Get length of sub-curve
  16451. // Push sums into cached array
  16452. var lengths = [], sums = 0;
  16453. var i, il = this.curves.length;
  16454. for ( i = 0; i < il; i ++ ) {
  16455. sums += this.curves[ i ].getLength();
  16456. lengths.push( sums );
  16457. }
  16458. this.cacheLengths = lengths;
  16459. return lengths;
  16460. };
  16461. // Returns min and max coordinates
  16462. THREE.CurvePath.prototype.getBoundingBox = function () {
  16463. var points = this.getPoints();
  16464. var maxX, maxY, maxZ;
  16465. var minX, minY, minZ;
  16466. maxX = maxY = Number.NEGATIVE_INFINITY;
  16467. minX = minY = Number.POSITIVE_INFINITY;
  16468. var p, i, il, sum;
  16469. var v3 = points[ 0 ] instanceof THREE.Vector3;
  16470. sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
  16471. for ( i = 0, il = points.length; i < il; i ++ ) {
  16472. p = points[ i ];
  16473. if ( p.x > maxX ) maxX = p.x;
  16474. else if ( p.x < minX ) minX = p.x;
  16475. if ( p.y > maxY ) maxY = p.y;
  16476. else if ( p.y < minY ) minY = p.y;
  16477. if ( v3 ) {
  16478. if ( p.z > maxZ ) maxZ = p.z;
  16479. else if ( p.z < minZ ) minZ = p.z;
  16480. }
  16481. sum.add( p );
  16482. }
  16483. var ret = {
  16484. minX: minX,
  16485. minY: minY,
  16486. maxX: maxX,
  16487. maxY: maxY
  16488. };
  16489. if ( v3 ) {
  16490. ret.maxZ = maxZ;
  16491. ret.minZ = minZ;
  16492. }
  16493. return ret;
  16494. };
  16495. /**************************************************************
  16496. * Create Geometries Helpers
  16497. **************************************************************/
  16498. /// Generate geometry from path points (for Line or Points objects)
  16499. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  16500. var pts = this.getPoints( divisions, true );
  16501. return this.createGeometry( pts );
  16502. };
  16503. // Generate geometry from equidistant sampling along the path
  16504. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  16505. var pts = this.getSpacedPoints( divisions, true );
  16506. return this.createGeometry( pts );
  16507. };
  16508. THREE.CurvePath.prototype.createGeometry = function( points ) {
  16509. var geometry = new THREE.Geometry();
  16510. for ( var i = 0; i < points.length; i ++ ) {
  16511. geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, points[ i ].z || 0 ) );
  16512. }
  16513. return geometry;
  16514. };
  16515. /**************************************************************
  16516. * Bend / Wrap Helper Methods
  16517. **************************************************************/
  16518. // Wrap path / Bend modifiers?
  16519. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  16520. this.bends.push( bendpath );
  16521. };
  16522. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  16523. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  16524. var i, il;
  16525. if ( ! bends ) {
  16526. bends = this.bends;
  16527. }
  16528. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16529. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16530. }
  16531. return oldPts;
  16532. };
  16533. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  16534. var oldPts = this.getSpacedPoints( segments );
  16535. var i, il;
  16536. if ( ! bends ) {
  16537. bends = this.bends;
  16538. }
  16539. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16540. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16541. }
  16542. return oldPts;
  16543. };
  16544. // This returns getPoints() bend/wrapped around the contour of a path.
  16545. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  16546. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  16547. var bounds = this.getBoundingBox();
  16548. var i, il, p, oldX, oldY, xNorm;
  16549. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  16550. p = oldPts[ i ];
  16551. oldX = p.x;
  16552. oldY = p.y;
  16553. xNorm = oldX / bounds.maxX;
  16554. // If using actual distance, for length > path, requires line extrusions
  16555. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  16556. xNorm = path.getUtoTmapping( xNorm, oldX );
  16557. // check for out of bounds?
  16558. var pathPt = path.getPoint( xNorm );
  16559. var normal = path.getTangent( xNorm );
  16560. normal.set( - normal.y, normal.x ).multiplyScalar( oldY );
  16561. p.x = pathPt.x + normal.x;
  16562. p.y = pathPt.y + normal.y;
  16563. }
  16564. return oldPts;
  16565. };
  16566. // File:src/extras/core/Gyroscope.js
  16567. /**
  16568. * @author alteredq / http://alteredqualia.com/
  16569. */
  16570. THREE.Gyroscope = function () {
  16571. THREE.Object3D.call( this );
  16572. };
  16573. THREE.Gyroscope.prototype = Object.create( THREE.Object3D.prototype );
  16574. THREE.Gyroscope.prototype.constructor = THREE.Gyroscope;
  16575. THREE.Gyroscope.prototype.updateMatrixWorld = ( function () {
  16576. var translationObject = new THREE.Vector3();
  16577. var quaternionObject = new THREE.Quaternion();
  16578. var scaleObject = new THREE.Vector3();
  16579. var translationWorld = new THREE.Vector3();
  16580. var quaternionWorld = new THREE.Quaternion();
  16581. var scaleWorld = new THREE.Vector3();
  16582. return function updateMatrixWorld( force ) {
  16583. this.matrixAutoUpdate && this.updateMatrix();
  16584. // update matrixWorld
  16585. if ( this.matrixWorldNeedsUpdate || force ) {
  16586. if ( this.parent ) {
  16587. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  16588. this.matrixWorld.decompose( translationWorld, quaternionWorld, scaleWorld );
  16589. this.matrix.decompose( translationObject, quaternionObject, scaleObject );
  16590. this.matrixWorld.compose( translationWorld, quaternionObject, scaleWorld );
  16591. } else {
  16592. this.matrixWorld.copy( this.matrix );
  16593. }
  16594. this.matrixWorldNeedsUpdate = false;
  16595. force = true;
  16596. }
  16597. // update children
  16598. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  16599. this.children[ i ].updateMatrixWorld( force );
  16600. }
  16601. };
  16602. }() );
  16603. // File:src/extras/core/Path.js
  16604. /**
  16605. * @author zz85 / http://www.lab4games.net/zz85/blog
  16606. * Creates free form 2d path using series of points, lines or curves.
  16607. *
  16608. **/
  16609. THREE.Path = function ( points ) {
  16610. THREE.CurvePath.call( this );
  16611. this.actions = [];
  16612. if ( points ) {
  16613. this.fromPoints( points );
  16614. }
  16615. };
  16616. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  16617. THREE.Path.prototype.constructor = THREE.Path;
  16618. THREE.PathActions = {
  16619. MOVE_TO: 'moveTo',
  16620. LINE_TO: 'lineTo',
  16621. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  16622. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  16623. CSPLINE_THRU: 'splineThru', // Catmull-Rom spline
  16624. ARC: 'arc', // Circle
  16625. ELLIPSE: 'ellipse'
  16626. };
  16627. // TODO Clean up PATH API
  16628. // Create path using straight lines to connect all points
  16629. // - vectors: array of Vector2
  16630. THREE.Path.prototype.fromPoints = function ( vectors ) {
  16631. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  16632. for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
  16633. this.lineTo( vectors[ v ].x, vectors[ v ].y );
  16634. }
  16635. };
  16636. // startPath() endPath()?
  16637. THREE.Path.prototype.moveTo = function ( x, y ) {
  16638. var args = Array.prototype.slice.call( arguments );
  16639. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  16640. };
  16641. THREE.Path.prototype.lineTo = function ( x, y ) {
  16642. var args = Array.prototype.slice.call( arguments );
  16643. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16644. var x0 = lastargs[ lastargs.length - 2 ];
  16645. var y0 = lastargs[ lastargs.length - 1 ];
  16646. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  16647. this.curves.push( curve );
  16648. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  16649. };
  16650. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  16651. var args = Array.prototype.slice.call( arguments );
  16652. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16653. var x0 = lastargs[ lastargs.length - 2 ];
  16654. var y0 = lastargs[ lastargs.length - 1 ];
  16655. var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
  16656. new THREE.Vector2( aCPx, aCPy ),
  16657. new THREE.Vector2( aX, aY ) );
  16658. this.curves.push( curve );
  16659. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  16660. };
  16661. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
  16662. aCP2x, aCP2y,
  16663. aX, aY ) {
  16664. var args = Array.prototype.slice.call( arguments );
  16665. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16666. var x0 = lastargs[ lastargs.length - 2 ];
  16667. var y0 = lastargs[ lastargs.length - 1 ];
  16668. var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
  16669. new THREE.Vector2( aCP1x, aCP1y ),
  16670. new THREE.Vector2( aCP2x, aCP2y ),
  16671. new THREE.Vector2( aX, aY ) );
  16672. this.curves.push( curve );
  16673. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  16674. };
  16675. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  16676. var args = Array.prototype.slice.call( arguments );
  16677. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16678. var x0 = lastargs[ lastargs.length - 2 ];
  16679. var y0 = lastargs[ lastargs.length - 1 ];
  16680. //---
  16681. var npts = [ new THREE.Vector2( x0, y0 ) ];
  16682. Array.prototype.push.apply( npts, pts );
  16683. var curve = new THREE.SplineCurve( npts );
  16684. this.curves.push( curve );
  16685. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  16686. };
  16687. // FUTURE: Change the API or follow canvas API?
  16688. THREE.Path.prototype.arc = function ( aX, aY, aRadius,
  16689. aStartAngle, aEndAngle, aClockwise ) {
  16690. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16691. var x0 = lastargs[ lastargs.length - 2 ];
  16692. var y0 = lastargs[ lastargs.length - 1 ];
  16693. this.absarc( aX + x0, aY + y0, aRadius,
  16694. aStartAngle, aEndAngle, aClockwise );
  16695. };
  16696. THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
  16697. aStartAngle, aEndAngle, aClockwise ) {
  16698. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  16699. };
  16700. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
  16701. aStartAngle, aEndAngle, aClockwise ) {
  16702. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16703. var x0 = lastargs[ lastargs.length - 2 ];
  16704. var y0 = lastargs[ lastargs.length - 1 ];
  16705. this.absellipse( aX + x0, aY + y0, xRadius, yRadius,
  16706. aStartAngle, aEndAngle, aClockwise );
  16707. };
  16708. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
  16709. aStartAngle, aEndAngle, aClockwise ) {
  16710. var args = Array.prototype.slice.call( arguments );
  16711. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
  16712. aStartAngle, aEndAngle, aClockwise );
  16713. this.curves.push( curve );
  16714. var lastPoint = curve.getPoint( 1 );
  16715. args.push( lastPoint.x );
  16716. args.push( lastPoint.y );
  16717. this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
  16718. };
  16719. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  16720. if ( ! divisions ) divisions = 40;
  16721. var points = [];
  16722. for ( var i = 0; i < divisions; i ++ ) {
  16723. points.push( this.getPoint( i / divisions ) );
  16724. //if( !this.getPoint( i / divisions ) ) throw "DIE";
  16725. }
  16726. // if ( closedPath ) {
  16727. //
  16728. // points.push( points[ 0 ] );
  16729. //
  16730. // }
  16731. return points;
  16732. };
  16733. /* Return an array of vectors based on contour of the path */
  16734. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  16735. if ( this.useSpacedPoints ) {
  16736. return this.getSpacedPoints( divisions, closedPath );
  16737. }
  16738. divisions = divisions || 12;
  16739. var points = [];
  16740. var i, il, item, action, args;
  16741. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  16742. laste, j,
  16743. t, tx, ty;
  16744. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  16745. item = this.actions[ i ];
  16746. action = item.action;
  16747. args = item.args;
  16748. switch ( action ) {
  16749. case THREE.PathActions.MOVE_TO:
  16750. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16751. break;
  16752. case THREE.PathActions.LINE_TO:
  16753. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16754. break;
  16755. case THREE.PathActions.QUADRATIC_CURVE_TO:
  16756. cpx = args[ 2 ];
  16757. cpy = args[ 3 ];
  16758. cpx1 = args[ 0 ];
  16759. cpy1 = args[ 1 ];
  16760. if ( points.length > 0 ) {
  16761. laste = points[ points.length - 1 ];
  16762. cpx0 = laste.x;
  16763. cpy0 = laste.y;
  16764. } else {
  16765. laste = this.actions[ i - 1 ].args;
  16766. cpx0 = laste[ laste.length - 2 ];
  16767. cpy0 = laste[ laste.length - 1 ];
  16768. }
  16769. for ( j = 1; j <= divisions; j ++ ) {
  16770. t = j / divisions;
  16771. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  16772. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  16773. points.push( new THREE.Vector2( tx, ty ) );
  16774. }
  16775. break;
  16776. case THREE.PathActions.BEZIER_CURVE_TO:
  16777. cpx = args[ 4 ];
  16778. cpy = args[ 5 ];
  16779. cpx1 = args[ 0 ];
  16780. cpy1 = args[ 1 ];
  16781. cpx2 = args[ 2 ];
  16782. cpy2 = args[ 3 ];
  16783. if ( points.length > 0 ) {
  16784. laste = points[ points.length - 1 ];
  16785. cpx0 = laste.x;
  16786. cpy0 = laste.y;
  16787. } else {
  16788. laste = this.actions[ i - 1 ].args;
  16789. cpx0 = laste[ laste.length - 2 ];
  16790. cpy0 = laste[ laste.length - 1 ];
  16791. }
  16792. for ( j = 1; j <= divisions; j ++ ) {
  16793. t = j / divisions;
  16794. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  16795. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  16796. points.push( new THREE.Vector2( tx, ty ) );
  16797. }
  16798. break;
  16799. case THREE.PathActions.CSPLINE_THRU:
  16800. laste = this.actions[ i - 1 ].args;
  16801. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  16802. var spts = [ last ];
  16803. var n = divisions * args[ 0 ].length;
  16804. spts = spts.concat( args[ 0 ] );
  16805. var spline = new THREE.SplineCurve( spts );
  16806. for ( j = 1; j <= n; j ++ ) {
  16807. points.push( spline.getPointAt( j / n ) );
  16808. }
  16809. break;
  16810. case THREE.PathActions.ARC:
  16811. var aX = args[ 0 ], aY = args[ 1 ],
  16812. aRadius = args[ 2 ],
  16813. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  16814. aClockwise = !! args[ 5 ];
  16815. var deltaAngle = aEndAngle - aStartAngle;
  16816. var angle;
  16817. var tdivisions = divisions * 2;
  16818. for ( j = 1; j <= tdivisions; j ++ ) {
  16819. t = j / tdivisions;
  16820. if ( ! aClockwise ) {
  16821. t = 1 - t;
  16822. }
  16823. angle = aStartAngle + t * deltaAngle;
  16824. tx = aX + aRadius * Math.cos( angle );
  16825. ty = aY + aRadius * Math.sin( angle );
  16826. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16827. points.push( new THREE.Vector2( tx, ty ) );
  16828. }
  16829. //console.log(points);
  16830. break;
  16831. case THREE.PathActions.ELLIPSE:
  16832. var aX = args[ 0 ], aY = args[ 1 ],
  16833. xRadius = args[ 2 ],
  16834. yRadius = args[ 3 ],
  16835. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  16836. aClockwise = !! args[ 6 ];
  16837. var deltaAngle = aEndAngle - aStartAngle;
  16838. var angle;
  16839. var tdivisions = divisions * 2;
  16840. for ( j = 1; j <= tdivisions; j ++ ) {
  16841. t = j / tdivisions;
  16842. if ( ! aClockwise ) {
  16843. t = 1 - t;
  16844. }
  16845. angle = aStartAngle + t * deltaAngle;
  16846. tx = aX + xRadius * Math.cos( angle );
  16847. ty = aY + yRadius * Math.sin( angle );
  16848. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16849. points.push( new THREE.Vector2( tx, ty ) );
  16850. }
  16851. //console.log(points);
  16852. break;
  16853. } // end switch
  16854. }
  16855. // Normalize to remove the closing point by default.
  16856. var lastPoint = points[ points.length - 1 ];
  16857. var EPSILON = 0.0000000001;
  16858. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < EPSILON &&
  16859. Math.abs( lastPoint.y - points[ 0 ].y ) < EPSILON )
  16860. points.splice( points.length - 1, 1 );
  16861. if ( closedPath ) {
  16862. points.push( points[ 0 ] );
  16863. }
  16864. return points;
  16865. };
  16866. //
  16867. // Breaks path into shapes
  16868. //
  16869. // Assumptions (if parameter isCCW==true the opposite holds):
  16870. // - solid shapes are defined clockwise (CW)
  16871. // - holes are defined counterclockwise (CCW)
  16872. //
  16873. // If parameter noHoles==true:
  16874. // - all subPaths are regarded as solid shapes
  16875. // - definition order CW/CCW has no relevance
  16876. //
  16877. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  16878. function extractSubpaths( inActions ) {
  16879. var i, il, item, action, args;
  16880. var subPaths = [], lastPath = new THREE.Path();
  16881. for ( i = 0, il = inActions.length; i < il; i ++ ) {
  16882. item = inActions[ i ];
  16883. args = item.args;
  16884. action = item.action;
  16885. if ( action === THREE.PathActions.MOVE_TO ) {
  16886. if ( lastPath.actions.length !== 0 ) {
  16887. subPaths.push( lastPath );
  16888. lastPath = new THREE.Path();
  16889. }
  16890. }
  16891. lastPath[ action ].apply( lastPath, args );
  16892. }
  16893. if ( lastPath.actions.length !== 0 ) {
  16894. subPaths.push( lastPath );
  16895. }
  16896. // console.log(subPaths);
  16897. return subPaths;
  16898. }
  16899. function toShapesNoHoles( inSubpaths ) {
  16900. var shapes = [];
  16901. for ( var i = 0, il = inSubpaths.length; i < il; i ++ ) {
  16902. var tmpPath = inSubpaths[ i ];
  16903. var tmpShape = new THREE.Shape();
  16904. tmpShape.actions = tmpPath.actions;
  16905. tmpShape.curves = tmpPath.curves;
  16906. shapes.push( tmpShape );
  16907. }
  16908. //console.log("shape", shapes);
  16909. return shapes;
  16910. }
  16911. function isPointInsidePolygon( inPt, inPolygon ) {
  16912. var EPSILON = 0.0000000001;
  16913. var polyLen = inPolygon.length;
  16914. // inPt on polygon contour => immediate success or
  16915. // toggling of inside/outside at every single! intersection point of an edge
  16916. // with the horizontal line through inPt, left of inPt
  16917. // not counting lowerY endpoints of edges and whole edges on that line
  16918. var inside = false;
  16919. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  16920. var edgeLowPt = inPolygon[ p ];
  16921. var edgeHighPt = inPolygon[ q ];
  16922. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  16923. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  16924. if ( Math.abs( edgeDy ) > EPSILON ) {
  16925. // not parallel
  16926. if ( edgeDy < 0 ) {
  16927. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  16928. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  16929. }
  16930. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  16931. if ( inPt.y === edgeLowPt.y ) {
  16932. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  16933. // continue; // no intersection or edgeLowPt => doesn't count !!!
  16934. } else {
  16935. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  16936. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  16937. if ( perpEdge < 0 ) continue;
  16938. inside = ! inside; // true intersection left of inPt
  16939. }
  16940. } else {
  16941. // parallel or collinear
  16942. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  16943. // edge lies on the same horizontal line as inPt
  16944. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  16945. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  16946. // continue;
  16947. }
  16948. }
  16949. return inside;
  16950. }
  16951. var subPaths = extractSubpaths( this.actions );
  16952. if ( subPaths.length === 0 ) return [];
  16953. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  16954. var solid, tmpPath, tmpShape, shapes = [];
  16955. if ( subPaths.length === 1 ) {
  16956. tmpPath = subPaths[ 0 ];
  16957. tmpShape = new THREE.Shape();
  16958. tmpShape.actions = tmpPath.actions;
  16959. tmpShape.curves = tmpPath.curves;
  16960. shapes.push( tmpShape );
  16961. return shapes;
  16962. }
  16963. var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  16964. holesFirst = isCCW ? ! holesFirst : holesFirst;
  16965. // console.log("Holes first", holesFirst);
  16966. var betterShapeHoles = [];
  16967. var newShapes = [];
  16968. var newShapeHoles = [];
  16969. var mainIdx = 0;
  16970. var tmpPoints;
  16971. newShapes[ mainIdx ] = undefined;
  16972. newShapeHoles[ mainIdx ] = [];
  16973. var i, il;
  16974. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  16975. tmpPath = subPaths[ i ];
  16976. tmpPoints = tmpPath.getPoints();
  16977. solid = THREE.Shape.Utils.isClockWise( tmpPoints );
  16978. solid = isCCW ? ! solid : solid;
  16979. if ( solid ) {
  16980. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  16981. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  16982. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  16983. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  16984. if ( holesFirst ) mainIdx ++;
  16985. newShapeHoles[ mainIdx ] = [];
  16986. //console.log('cw', i);
  16987. } else {
  16988. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  16989. //console.log('ccw', i);
  16990. }
  16991. }
  16992. // only Holes? -> probably all Shapes with wrong orientation
  16993. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  16994. if ( newShapes.length > 1 ) {
  16995. var ambiguous = false;
  16996. var toChange = [];
  16997. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  16998. betterShapeHoles[ sIdx ] = [];
  16999. }
  17000. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  17001. var sho = newShapeHoles[ sIdx ];
  17002. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  17003. var ho = sho[ hIdx ];
  17004. var hole_unassigned = true;
  17005. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  17006. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  17007. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  17008. if ( hole_unassigned ) {
  17009. hole_unassigned = false;
  17010. betterShapeHoles[ s2Idx ].push( ho );
  17011. } else {
  17012. ambiguous = true;
  17013. }
  17014. }
  17015. }
  17016. if ( hole_unassigned ) {
  17017. betterShapeHoles[ sIdx ].push( ho );
  17018. }
  17019. }
  17020. }
  17021. // console.log("ambiguous: ", ambiguous);
  17022. if ( toChange.length > 0 ) {
  17023. // console.log("to change: ", toChange);
  17024. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  17025. }
  17026. }
  17027. var tmpHoles, j, jl;
  17028. for ( i = 0, il = newShapes.length; i < il; i ++ ) {
  17029. tmpShape = newShapes[ i ].s;
  17030. shapes.push( tmpShape );
  17031. tmpHoles = newShapeHoles[ i ];
  17032. for ( j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  17033. tmpShape.holes.push( tmpHoles[ j ].h );
  17034. }
  17035. }
  17036. //console.log("shape", shapes);
  17037. return shapes;
  17038. };
  17039. // File:src/extras/core/Shape.js
  17040. /**
  17041. * @author zz85 / http://www.lab4games.net/zz85/blog
  17042. * Defines a 2d shape plane using paths.
  17043. **/
  17044. // STEP 1 Create a path.
  17045. // STEP 2 Turn path into shape.
  17046. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  17047. // STEP 3a - Extract points from each shape, turn to vertices
  17048. // STEP 3b - Triangulate each shape, add faces.
  17049. THREE.Shape = function () {
  17050. THREE.Path.apply( this, arguments );
  17051. this.holes = [];
  17052. };
  17053. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  17054. THREE.Shape.prototype.constructor = THREE.Shape;
  17055. // Convenience method to return ExtrudeGeometry
  17056. THREE.Shape.prototype.extrude = function ( options ) {
  17057. var extruded = new THREE.ExtrudeGeometry( this, options );
  17058. return extruded;
  17059. };
  17060. // Convenience method to return ShapeGeometry
  17061. THREE.Shape.prototype.makeGeometry = function ( options ) {
  17062. var geometry = new THREE.ShapeGeometry( this, options );
  17063. return geometry;
  17064. };
  17065. // Get points of holes
  17066. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  17067. var i, il = this.holes.length, holesPts = [];
  17068. for ( i = 0; i < il; i ++ ) {
  17069. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  17070. }
  17071. return holesPts;
  17072. };
  17073. // Get points of holes (spaced by regular distance)
  17074. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  17075. var i, il = this.holes.length, holesPts = [];
  17076. for ( i = 0; i < il; i ++ ) {
  17077. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  17078. }
  17079. return holesPts;
  17080. };
  17081. // Get points of shape and holes (keypoints based on segments parameter)
  17082. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  17083. return {
  17084. shape: this.getTransformedPoints( divisions ),
  17085. holes: this.getPointsHoles( divisions )
  17086. };
  17087. };
  17088. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  17089. if ( this.useSpacedPoints ) {
  17090. return this.extractAllSpacedPoints( divisions );
  17091. }
  17092. return this.extractAllPoints( divisions );
  17093. };
  17094. //
  17095. // THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  17096. //
  17097. // return {
  17098. //
  17099. // shape: this.transform( bend, divisions ),
  17100. // holes: this.getPointsHoles( divisions, bend )
  17101. //
  17102. // };
  17103. //
  17104. // };
  17105. // Get points of shape and holes (spaced by regular distance)
  17106. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  17107. return {
  17108. shape: this.getTransformedSpacedPoints( divisions ),
  17109. holes: this.getSpacedPointsHoles( divisions )
  17110. };
  17111. };
  17112. /**************************************************************
  17113. * Utils
  17114. **************************************************************/
  17115. THREE.Shape.Utils = {
  17116. triangulateShape: function ( contour, holes ) {
  17117. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  17118. // inOtherPt needs to be collinear to the inSegment
  17119. if ( inSegPt1.x !== inSegPt2.x ) {
  17120. if ( inSegPt1.x < inSegPt2.x ) {
  17121. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  17122. } else {
  17123. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  17124. }
  17125. } else {
  17126. if ( inSegPt1.y < inSegPt2.y ) {
  17127. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  17128. } else {
  17129. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  17130. }
  17131. }
  17132. }
  17133. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  17134. var EPSILON = 0.0000000001;
  17135. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  17136. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  17137. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  17138. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  17139. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  17140. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  17141. if ( Math.abs( limit ) > EPSILON ) {
  17142. // not parallel
  17143. var perpSeg2;
  17144. if ( limit > 0 ) {
  17145. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  17146. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17147. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  17148. } else {
  17149. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  17150. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17151. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  17152. }
  17153. // i.e. to reduce rounding errors
  17154. // intersection at endpoint of segment#1?
  17155. if ( perpSeg2 === 0 ) {
  17156. if ( ( inExcludeAdjacentSegs ) &&
  17157. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17158. return [ inSeg1Pt1 ];
  17159. }
  17160. if ( perpSeg2 === limit ) {
  17161. if ( ( inExcludeAdjacentSegs ) &&
  17162. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17163. return [ inSeg1Pt2 ];
  17164. }
  17165. // intersection at endpoint of segment#2?
  17166. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  17167. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  17168. // return real intersection point
  17169. var factorSeg1 = perpSeg2 / limit;
  17170. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  17171. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  17172. } else {
  17173. // parallel or collinear
  17174. if ( ( perpSeg1 !== 0 ) ||
  17175. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  17176. // they are collinear or degenerate
  17177. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  17178. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  17179. // both segments are points
  17180. if ( seg1Pt && seg2Pt ) {
  17181. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  17182. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  17183. return [ inSeg1Pt1 ]; // they are the same point
  17184. }
  17185. // segment#1 is a single point
  17186. if ( seg1Pt ) {
  17187. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  17188. return [ inSeg1Pt1 ];
  17189. }
  17190. // segment#2 is a single point
  17191. if ( seg2Pt ) {
  17192. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  17193. return [ inSeg2Pt1 ];
  17194. }
  17195. // they are collinear segments, which might overlap
  17196. var seg1min, seg1max, seg1minVal, seg1maxVal;
  17197. var seg2min, seg2max, seg2minVal, seg2maxVal;
  17198. if ( seg1dx !== 0 ) {
  17199. // the segments are NOT on a vertical line
  17200. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  17201. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  17202. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  17203. } else {
  17204. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  17205. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  17206. }
  17207. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  17208. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  17209. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  17210. } else {
  17211. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  17212. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  17213. }
  17214. } else {
  17215. // the segments are on a vertical line
  17216. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  17217. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  17218. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  17219. } else {
  17220. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  17221. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  17222. }
  17223. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  17224. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  17225. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  17226. } else {
  17227. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  17228. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  17229. }
  17230. }
  17231. if ( seg1minVal <= seg2minVal ) {
  17232. if ( seg1maxVal < seg2minVal ) return [];
  17233. if ( seg1maxVal === seg2minVal ) {
  17234. if ( inExcludeAdjacentSegs ) return [];
  17235. return [ seg2min ];
  17236. }
  17237. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  17238. return [ seg2min, seg2max ];
  17239. } else {
  17240. if ( seg1minVal > seg2maxVal ) return [];
  17241. if ( seg1minVal === seg2maxVal ) {
  17242. if ( inExcludeAdjacentSegs ) return [];
  17243. return [ seg1min ];
  17244. }
  17245. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  17246. return [ seg1min, seg2max ];
  17247. }
  17248. }
  17249. }
  17250. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  17251. // The order of legs is important
  17252. var EPSILON = 0.0000000001;
  17253. // translation of all points, so that Vertex is at (0,0)
  17254. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  17255. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  17256. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  17257. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  17258. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  17259. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  17260. if ( Math.abs( from2toAngle ) > EPSILON ) {
  17261. // angle != 180 deg.
  17262. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  17263. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  17264. if ( from2toAngle > 0 ) {
  17265. // main angle < 180 deg.
  17266. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  17267. } else {
  17268. // main angle > 180 deg.
  17269. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  17270. }
  17271. } else {
  17272. // angle == 180 deg.
  17273. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  17274. return ( from2otherAngle > 0 );
  17275. }
  17276. }
  17277. function removeHoles( contour, holes ) {
  17278. var shape = contour.concat(); // work on this shape
  17279. var hole;
  17280. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  17281. // Check if hole point lies within angle around shape point
  17282. var lastShapeIdx = shape.length - 1;
  17283. var prevShapeIdx = inShapeIdx - 1;
  17284. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  17285. var nextShapeIdx = inShapeIdx + 1;
  17286. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  17287. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  17288. if ( ! insideAngle ) {
  17289. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  17290. return false;
  17291. }
  17292. // Check if shape point lies within angle around hole point
  17293. var lastHoleIdx = hole.length - 1;
  17294. var prevHoleIdx = inHoleIdx - 1;
  17295. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  17296. var nextHoleIdx = inHoleIdx + 1;
  17297. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  17298. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  17299. if ( ! insideAngle ) {
  17300. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  17301. return false;
  17302. }
  17303. return true;
  17304. }
  17305. function intersectsShapeEdge( inShapePt, inHolePt ) {
  17306. // checks for intersections with shape edges
  17307. var sIdx, nextIdx, intersection;
  17308. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  17309. nextIdx = sIdx + 1; nextIdx %= shape.length;
  17310. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  17311. if ( intersection.length > 0 ) return true;
  17312. }
  17313. return false;
  17314. }
  17315. var indepHoles = [];
  17316. function intersectsHoleEdge( inShapePt, inHolePt ) {
  17317. // checks for intersections with hole edges
  17318. var ihIdx, chkHole,
  17319. hIdx, nextIdx, intersection;
  17320. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  17321. chkHole = holes[ indepHoles[ ihIdx ]];
  17322. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  17323. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  17324. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  17325. if ( intersection.length > 0 ) return true;
  17326. }
  17327. }
  17328. return false;
  17329. }
  17330. var holeIndex, shapeIndex,
  17331. shapePt, holePt,
  17332. holeIdx, cutKey, failedCuts = [],
  17333. tmpShape1, tmpShape2,
  17334. tmpHole1, tmpHole2;
  17335. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17336. indepHoles.push( h );
  17337. }
  17338. var minShapeIndex = 0;
  17339. var counter = indepHoles.length * 2;
  17340. while ( indepHoles.length > 0 ) {
  17341. counter --;
  17342. if ( counter < 0 ) {
  17343. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  17344. break;
  17345. }
  17346. // search for shape-vertex and hole-vertex,
  17347. // which can be connected without intersections
  17348. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  17349. shapePt = shape[ shapeIndex ];
  17350. holeIndex = - 1;
  17351. // search for hole which can be reached without intersections
  17352. for ( var h = 0; h < indepHoles.length; h ++ ) {
  17353. holeIdx = indepHoles[ h ];
  17354. // prevent multiple checks
  17355. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  17356. if ( failedCuts[ cutKey ] !== undefined ) continue;
  17357. hole = holes[ holeIdx ];
  17358. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  17359. holePt = hole[ h2 ];
  17360. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  17361. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  17362. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  17363. holeIndex = h2;
  17364. indepHoles.splice( h, 1 );
  17365. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  17366. tmpShape2 = shape.slice( shapeIndex );
  17367. tmpHole1 = hole.slice( holeIndex );
  17368. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  17369. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  17370. minShapeIndex = shapeIndex;
  17371. // Debug only, to show the selected cuts
  17372. // glob_CutLines.push( [ shapePt, holePt ] );
  17373. break;
  17374. }
  17375. if ( holeIndex >= 0 ) break; // hole-vertex found
  17376. failedCuts[ cutKey ] = true; // remember failure
  17377. }
  17378. if ( holeIndex >= 0 ) break; // hole-vertex found
  17379. }
  17380. }
  17381. return shape; /* shape with no holes */
  17382. }
  17383. var i, il, f, face,
  17384. key, index,
  17385. allPointsMap = {};
  17386. // 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.
  17387. var allpoints = contour.concat();
  17388. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17389. Array.prototype.push.apply( allpoints, holes[ h ] );
  17390. }
  17391. //console.log( "allpoints",allpoints, allpoints.length );
  17392. // prepare all points map
  17393. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  17394. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  17395. if ( allPointsMap[ key ] !== undefined ) {
  17396. console.warn( "THREE.Shape: Duplicate point", key );
  17397. }
  17398. allPointsMap[ key ] = i;
  17399. }
  17400. // remove holes by cutting paths to holes and adding them to the shape
  17401. var shapeWithoutHoles = removeHoles( contour, holes );
  17402. var triangles = THREE.FontUtils.Triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  17403. //console.log( "triangles",triangles, triangles.length );
  17404. // check all face vertices against all points map
  17405. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  17406. face = triangles[ i ];
  17407. for ( f = 0; f < 3; f ++ ) {
  17408. key = face[ f ].x + ":" + face[ f ].y;
  17409. index = allPointsMap[ key ];
  17410. if ( index !== undefined ) {
  17411. face[ f ] = index;
  17412. }
  17413. }
  17414. }
  17415. return triangles.concat();
  17416. },
  17417. isClockWise: function ( pts ) {
  17418. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  17419. },
  17420. // Bezier Curves formulas obtained from
  17421. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  17422. // Quad Bezier Functions
  17423. b2p0: function ( t, p ) {
  17424. var k = 1 - t;
  17425. return k * k * p;
  17426. },
  17427. b2p1: function ( t, p ) {
  17428. return 2 * ( 1 - t ) * t * p;
  17429. },
  17430. b2p2: function ( t, p ) {
  17431. return t * t * p;
  17432. },
  17433. b2: function ( t, p0, p1, p2 ) {
  17434. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  17435. },
  17436. // Cubic Bezier Functions
  17437. b3p0: function ( t, p ) {
  17438. var k = 1 - t;
  17439. return k * k * k * p;
  17440. },
  17441. b3p1: function ( t, p ) {
  17442. var k = 1 - t;
  17443. return 3 * k * k * t * p;
  17444. },
  17445. b3p2: function ( t, p ) {
  17446. var k = 1 - t;
  17447. return 3 * k * t * t * p;
  17448. },
  17449. b3p3: function ( t, p ) {
  17450. return t * t * t * p;
  17451. },
  17452. b3: function ( t, p0, p1, p2, p3 ) {
  17453. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  17454. }
  17455. };
  17456. // File:src/extras/curves/LineCurve.js
  17457. /**************************************************************
  17458. * Line
  17459. **************************************************************/
  17460. THREE.LineCurve = function ( v1, v2 ) {
  17461. this.v1 = v1;
  17462. this.v2 = v2;
  17463. };
  17464. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  17465. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  17466. THREE.LineCurve.prototype.getPoint = function ( t ) {
  17467. var point = this.v2.clone().sub( this.v1 );
  17468. point.multiplyScalar( t ).add( this.v1 );
  17469. return point;
  17470. };
  17471. // Line curve is linear, so we can overwrite default getPointAt
  17472. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  17473. return this.getPoint( u );
  17474. };
  17475. THREE.LineCurve.prototype.getTangent = function( t ) {
  17476. var tangent = this.v2.clone().sub( this.v1 );
  17477. return tangent.normalize();
  17478. };
  17479. // File:src/extras/curves/QuadraticBezierCurve.js
  17480. /**************************************************************
  17481. * Quadratic Bezier curve
  17482. **************************************************************/
  17483. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  17484. this.v0 = v0;
  17485. this.v1 = v1;
  17486. this.v2 = v2;
  17487. };
  17488. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17489. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  17490. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  17491. var vector = new THREE.Vector2();
  17492. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17493. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17494. return vector;
  17495. };
  17496. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  17497. var vector = new THREE.Vector2();
  17498. vector.x = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  17499. vector.y = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  17500. // returns unit vector
  17501. return vector.normalize();
  17502. };
  17503. // File:src/extras/curves/CubicBezierCurve.js
  17504. /**************************************************************
  17505. * Cubic Bezier curve
  17506. **************************************************************/
  17507. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  17508. this.v0 = v0;
  17509. this.v1 = v1;
  17510. this.v2 = v2;
  17511. this.v3 = v3;
  17512. };
  17513. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17514. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  17515. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  17516. var tx, ty;
  17517. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17518. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17519. return new THREE.Vector2( tx, ty );
  17520. };
  17521. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  17522. var tx, ty;
  17523. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17524. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17525. var tangent = new THREE.Vector2( tx, ty );
  17526. tangent.normalize();
  17527. return tangent;
  17528. };
  17529. // File:src/extras/curves/SplineCurve.js
  17530. /**************************************************************
  17531. * Spline curve
  17532. **************************************************************/
  17533. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  17534. this.points = ( points == undefined ) ? [] : points;
  17535. };
  17536. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  17537. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  17538. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  17539. var points = this.points;
  17540. var point = ( points.length - 1 ) * t;
  17541. var intPoint = Math.floor( point );
  17542. var weight = point - intPoint;
  17543. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  17544. var point1 = points[ intPoint ];
  17545. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17546. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17547. var vector = new THREE.Vector2();
  17548. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17549. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17550. return vector;
  17551. };
  17552. // File:src/extras/curves/EllipseCurve.js
  17553. /**************************************************************
  17554. * Ellipse curve
  17555. **************************************************************/
  17556. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise ) {
  17557. this.aX = aX;
  17558. this.aY = aY;
  17559. this.xRadius = xRadius;
  17560. this.yRadius = yRadius;
  17561. this.aStartAngle = aStartAngle;
  17562. this.aEndAngle = aEndAngle;
  17563. this.aClockwise = aClockwise;
  17564. };
  17565. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  17566. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  17567. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  17568. var deltaAngle = this.aEndAngle - this.aStartAngle;
  17569. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  17570. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  17571. var angle;
  17572. if ( this.aClockwise === true ) {
  17573. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  17574. } else {
  17575. angle = this.aStartAngle + t * deltaAngle;
  17576. }
  17577. var vector = new THREE.Vector2();
  17578. vector.x = this.aX + this.xRadius * Math.cos( angle );
  17579. vector.y = this.aY + this.yRadius * Math.sin( angle );
  17580. return vector;
  17581. };
  17582. // File:src/extras/curves/ArcCurve.js
  17583. /**************************************************************
  17584. * Arc curve
  17585. **************************************************************/
  17586. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17587. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17588. };
  17589. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  17590. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  17591. // File:src/extras/curves/LineCurve3.js
  17592. /**************************************************************
  17593. * Line3D
  17594. **************************************************************/
  17595. THREE.LineCurve3 = THREE.Curve.create(
  17596. function ( v1, v2 ) {
  17597. this.v1 = v1;
  17598. this.v2 = v2;
  17599. },
  17600. function ( t ) {
  17601. var vector = new THREE.Vector3();
  17602. vector.subVectors( this.v2, this.v1 ); // diff
  17603. vector.multiplyScalar( t );
  17604. vector.add( this.v1 );
  17605. return vector;
  17606. }
  17607. );
  17608. // File:src/extras/curves/QuadraticBezierCurve3.js
  17609. /**************************************************************
  17610. * Quadratic Bezier 3D curve
  17611. **************************************************************/
  17612. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  17613. function ( v0, v1, v2 ) {
  17614. this.v0 = v0;
  17615. this.v1 = v1;
  17616. this.v2 = v2;
  17617. },
  17618. function ( t ) {
  17619. var vector = new THREE.Vector3();
  17620. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17621. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17622. vector.z = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  17623. return vector;
  17624. }
  17625. );
  17626. // File:src/extras/curves/CubicBezierCurve3.js
  17627. /**************************************************************
  17628. * Cubic Bezier 3D curve
  17629. **************************************************************/
  17630. THREE.CubicBezierCurve3 = THREE.Curve.create(
  17631. function ( v0, v1, v2, v3 ) {
  17632. this.v0 = v0;
  17633. this.v1 = v1;
  17634. this.v2 = v2;
  17635. this.v3 = v3;
  17636. },
  17637. function ( t ) {
  17638. var vector = new THREE.Vector3();
  17639. vector.x = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17640. vector.y = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17641. vector.z = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  17642. return vector;
  17643. }
  17644. );
  17645. // File:src/extras/curves/SplineCurve3.js
  17646. /**************************************************************
  17647. * Spline 3D curve
  17648. **************************************************************/
  17649. THREE.SplineCurve3 = THREE.Curve.create(
  17650. function ( points /* array of Vector3 */ ) {
  17651. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  17652. this.points = ( points == undefined ) ? [] : points;
  17653. },
  17654. function ( t ) {
  17655. var points = this.points;
  17656. var point = ( points.length - 1 ) * t;
  17657. var intPoint = Math.floor( point );
  17658. var weight = point - intPoint;
  17659. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  17660. var point1 = points[ intPoint ];
  17661. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17662. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17663. var vector = new THREE.Vector3();
  17664. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17665. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17666. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17667. return vector;
  17668. }
  17669. );
  17670. // File:src/extras/curves/CatmullRomCurve3.js
  17671. /**
  17672. * @author zz85 https://github.com/zz85
  17673. *
  17674. * Centripetal CatmullRom Curve - which is useful for avoiding
  17675. * cusps and self-intersections in non-uniform catmull rom curves.
  17676. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  17677. *
  17678. * curve.type accepts centripetal(default), chordal and catmullrom
  17679. * curve.tension is used for catmullrom which defaults to 0.5
  17680. */
  17681. THREE.CatmullRomCurve3 = ( function() {
  17682. var
  17683. tmp = new THREE.Vector3(),
  17684. px = new CubicPoly(),
  17685. py = new CubicPoly(),
  17686. pz = new CubicPoly();
  17687. /*
  17688. Based on an optimized c++ solution in
  17689. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  17690. - http://ideone.com/NoEbVM
  17691. This CubicPoly class could be used for reusing some variables and calculations,
  17692. but for three.js curve use, it could be possible inlined and flatten into a single function call
  17693. which can be placed in CurveUtils.
  17694. */
  17695. function CubicPoly() {
  17696. }
  17697. /*
  17698. * Compute coefficients for a cubic polynomial
  17699. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  17700. * such that
  17701. * p(0) = x0, p(1) = x1
  17702. * and
  17703. * p'(0) = t0, p'(1) = t1.
  17704. */
  17705. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  17706. this.c0 = x0;
  17707. this.c1 = t0;
  17708. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  17709. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  17710. };
  17711. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  17712. // compute tangents when parameterized in [t1,t2]
  17713. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  17714. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  17715. // rescale tangents for parametrization in [0,1]
  17716. t1 *= dt1;
  17717. t2 *= dt1;
  17718. // initCubicPoly
  17719. this.init( x1, x2, t1, t2 );
  17720. };
  17721. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  17722. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  17723. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  17724. };
  17725. CubicPoly.prototype.calc = function( t ) {
  17726. var t2 = t * t;
  17727. var t3 = t2 * t;
  17728. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  17729. };
  17730. // Subclass Three.js curve
  17731. return THREE.Curve.create(
  17732. function ( p /* array of Vector3 */ ) {
  17733. this.points = p || [];
  17734. },
  17735. function ( t ) {
  17736. var points = this.points,
  17737. point, intPoint, weight, l;
  17738. l = points.length;
  17739. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  17740. point = ( l - 1 ) * t;
  17741. intPoint = Math.floor( point );
  17742. weight = point - intPoint;
  17743. if ( weight === 0 && intPoint === l - 1 ) {
  17744. intPoint = l - 2;
  17745. weight = 1;
  17746. }
  17747. var p0, p1, p2, p3;
  17748. if ( intPoint === 0 ) {
  17749. // extrapolate first point
  17750. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  17751. p0 = tmp;
  17752. } else {
  17753. p0 = points[ intPoint - 1 ];
  17754. }
  17755. p1 = points[ intPoint ];
  17756. p2 = points[ intPoint + 1 ];
  17757. if ( intPoint + 2 < l ) {
  17758. p3 = points[ intPoint + 2 ]
  17759. } else {
  17760. // extrapolate last point
  17761. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  17762. p3 = tmp;
  17763. }
  17764. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  17765. // init Centripetal / Chordal Catmull-Rom
  17766. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  17767. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  17768. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  17769. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  17770. // safety check for repeated points
  17771. if ( dt1 < 1e-4 ) dt1 = 1.0;
  17772. if ( dt0 < 1e-4 ) dt0 = dt1;
  17773. if ( dt2 < 1e-4 ) dt2 = dt1;
  17774. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  17775. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  17776. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  17777. } else if ( this.type === 'catmullrom' ) {
  17778. var tension = this.tension !== undefined ? this.tension : 0.5;
  17779. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  17780. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  17781. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  17782. }
  17783. var v = new THREE.Vector3(
  17784. px.calc( weight ),
  17785. py.calc( weight ),
  17786. pz.calc( weight )
  17787. );
  17788. return v;
  17789. }
  17790. );
  17791. } )();
  17792. // File:src/extras/curves/ClosedSplineCurve3.js
  17793. /**************************************************************
  17794. * Closed Spline 3D curve
  17795. **************************************************************/
  17796. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  17797. function ( points /* array of Vector3 */ ) {
  17798. this.points = ( points == undefined ) ? [] : points;
  17799. },
  17800. function ( t ) {
  17801. var points = this.points;
  17802. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  17803. var intPoint = Math.floor( point );
  17804. var weight = point - intPoint;
  17805. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  17806. var point0 = points[ ( intPoint - 1 ) % points.length ];
  17807. var point1 = points[ ( intPoint ) % points.length ];
  17808. var point2 = points[ ( intPoint + 1 ) % points.length ];
  17809. var point3 = points[ ( intPoint + 2 ) % points.length ];
  17810. var vector = new THREE.Vector3();
  17811. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17812. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17813. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17814. return vector;
  17815. }
  17816. );
  17817. // File:src/extras/animation/AnimationHandler.js
  17818. /**
  17819. * @author mikael emtinger / http://gomo.se/
  17820. */
  17821. THREE.AnimationHandler = {
  17822. LINEAR: 0,
  17823. CATMULLROM: 1,
  17824. CATMULLROM_FORWARD: 2,
  17825. //
  17826. add: function () {
  17827. console.warn( 'THREE.AnimationHandler.add() has been deprecated.' );
  17828. },
  17829. get: function () {
  17830. console.warn( 'THREE.AnimationHandler.get() has been deprecated.' );
  17831. },
  17832. remove: function () {
  17833. console.warn( 'THREE.AnimationHandler.remove() has been deprecated.' );
  17834. },
  17835. //
  17836. animations: [],
  17837. init: function ( data ) {
  17838. if ( data.initialized === true ) return data;
  17839. // loop through all keys
  17840. for ( var h = 0; h < data.hierarchy.length; h ++ ) {
  17841. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17842. // remove minus times
  17843. if ( data.hierarchy[ h ].keys[ k ].time < 0 ) {
  17844. data.hierarchy[ h ].keys[ k ].time = 0;
  17845. }
  17846. // create quaternions
  17847. if ( data.hierarchy[ h ].keys[ k ].rot !== undefined &&
  17848. ! ( data.hierarchy[ h ].keys[ k ].rot instanceof THREE.Quaternion ) ) {
  17849. var quat = data.hierarchy[ h ].keys[ k ].rot;
  17850. data.hierarchy[ h ].keys[ k ].rot = new THREE.Quaternion().fromArray( quat );
  17851. }
  17852. }
  17853. // prepare morph target keys
  17854. if ( data.hierarchy[ h ].keys.length && data.hierarchy[ h ].keys[ 0 ].morphTargets !== undefined ) {
  17855. // get all used
  17856. var usedMorphTargets = {};
  17857. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17858. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17859. var morphTargetName = data.hierarchy[ h ].keys[ k ].morphTargets[ m ];
  17860. usedMorphTargets[ morphTargetName ] = - 1;
  17861. }
  17862. }
  17863. data.hierarchy[ h ].usedMorphTargets = usedMorphTargets;
  17864. // set all used on all frames
  17865. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17866. var influences = {};
  17867. for ( var morphTargetName in usedMorphTargets ) {
  17868. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17869. if ( data.hierarchy[ h ].keys[ k ].morphTargets[ m ] === morphTargetName ) {
  17870. influences[ morphTargetName ] = data.hierarchy[ h ].keys[ k ].morphTargetsInfluences[ m ];
  17871. break;
  17872. }
  17873. }
  17874. if ( m === data.hierarchy[ h ].keys[ k ].morphTargets.length ) {
  17875. influences[ morphTargetName ] = 0;
  17876. }
  17877. }
  17878. data.hierarchy[ h ].keys[ k ].morphTargetsInfluences = influences;
  17879. }
  17880. }
  17881. // remove all keys that are on the same time
  17882. for ( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17883. if ( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
  17884. data.hierarchy[ h ].keys.splice( k, 1 );
  17885. k --;
  17886. }
  17887. }
  17888. // set index
  17889. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17890. data.hierarchy[ h ].keys[ k ].index = k;
  17891. }
  17892. }
  17893. data.initialized = true;
  17894. return data;
  17895. },
  17896. parse: function ( root ) {
  17897. var parseRecurseHierarchy = function ( root, hierarchy ) {
  17898. hierarchy.push( root );
  17899. for ( var c = 0; c < root.children.length; c ++ )
  17900. parseRecurseHierarchy( root.children[ c ], hierarchy );
  17901. };
  17902. // setup hierarchy
  17903. var hierarchy = [];
  17904. if ( root instanceof THREE.SkinnedMesh ) {
  17905. for ( var b = 0; b < root.skeleton.bones.length; b ++ ) {
  17906. hierarchy.push( root.skeleton.bones[ b ] );
  17907. }
  17908. } else {
  17909. parseRecurseHierarchy( root, hierarchy );
  17910. }
  17911. return hierarchy;
  17912. },
  17913. play: function ( animation ) {
  17914. if ( this.animations.indexOf( animation ) === - 1 ) {
  17915. this.animations.push( animation );
  17916. }
  17917. },
  17918. stop: function ( animation ) {
  17919. var index = this.animations.indexOf( animation );
  17920. if ( index !== - 1 ) {
  17921. this.animations.splice( index, 1 );
  17922. }
  17923. },
  17924. update: function ( deltaTimeMS ) {
  17925. for ( var i = 0; i < this.animations.length; i ++ ) {
  17926. this.animations[ i ].resetBlendWeights( );
  17927. }
  17928. for ( var i = 0; i < this.animations.length; i ++ ) {
  17929. this.animations[ i ].update( deltaTimeMS );
  17930. }
  17931. }
  17932. };
  17933. // File:src/extras/animation/Animation.js
  17934. /**
  17935. * @author mikael emtinger / http://gomo.se/
  17936. * @author mrdoob / http://mrdoob.com/
  17937. * @author alteredq / http://alteredqualia.com/
  17938. */
  17939. THREE.Animation = function ( root, data ) {
  17940. this.root = root;
  17941. this.data = THREE.AnimationHandler.init( data );
  17942. this.hierarchy = THREE.AnimationHandler.parse( root );
  17943. this.currentTime = 0;
  17944. this.timeScale = 1;
  17945. this.isPlaying = false;
  17946. this.loop = true;
  17947. this.weight = 0;
  17948. this.interpolationType = THREE.AnimationHandler.LINEAR;
  17949. };
  17950. THREE.Animation.prototype = {
  17951. constructor: THREE.Animation,
  17952. keyTypes: [ "pos", "rot", "scl" ],
  17953. play: function ( startTime, weight ) {
  17954. this.currentTime = startTime !== undefined ? startTime : 0;
  17955. this.weight = weight !== undefined ? weight : 1;
  17956. this.isPlaying = true;
  17957. this.reset();
  17958. THREE.AnimationHandler.play( this );
  17959. },
  17960. stop: function() {
  17961. this.isPlaying = false;
  17962. THREE.AnimationHandler.stop( this );
  17963. },
  17964. reset: function () {
  17965. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17966. var object = this.hierarchy[ h ];
  17967. if ( object.animationCache === undefined ) {
  17968. object.animationCache = {
  17969. animations: {},
  17970. blending: {
  17971. positionWeight: 0.0,
  17972. quaternionWeight: 0.0,
  17973. scaleWeight: 0.0
  17974. }
  17975. };
  17976. }
  17977. var name = this.data.name;
  17978. var animations = object.animationCache.animations;
  17979. var animationCache = animations[ name ];
  17980. if ( animationCache === undefined ) {
  17981. animationCache = {
  17982. prevKey: { pos: 0, rot: 0, scl: 0 },
  17983. nextKey: { pos: 0, rot: 0, scl: 0 },
  17984. originalMatrix: object.matrix
  17985. };
  17986. animations[ name ] = animationCache;
  17987. }
  17988. // Get keys to match our current time
  17989. for ( var t = 0; t < 3; t ++ ) {
  17990. var type = this.keyTypes[ t ];
  17991. var prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  17992. var nextKey = this.getNextKeyWith( type, h, 1 );
  17993. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  17994. prevKey = nextKey;
  17995. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  17996. }
  17997. animationCache.prevKey[ type ] = prevKey;
  17998. animationCache.nextKey[ type ] = nextKey;
  17999. }
  18000. }
  18001. },
  18002. resetBlendWeights: function () {
  18003. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18004. var object = this.hierarchy[ h ];
  18005. var animationCache = object.animationCache;
  18006. if ( animationCache !== undefined ) {
  18007. var blending = animationCache.blending;
  18008. blending.positionWeight = 0.0;
  18009. blending.quaternionWeight = 0.0;
  18010. blending.scaleWeight = 0.0;
  18011. }
  18012. }
  18013. },
  18014. update: ( function() {
  18015. var points = [];
  18016. var target = new THREE.Vector3();
  18017. var newVector = new THREE.Vector3();
  18018. var newQuat = new THREE.Quaternion();
  18019. // Catmull-Rom spline
  18020. var interpolateCatmullRom = function ( points, scale ) {
  18021. var c = [], v3 = [],
  18022. point, intPoint, weight, w2, w3,
  18023. pa, pb, pc, pd;
  18024. point = ( points.length - 1 ) * scale;
  18025. intPoint = Math.floor( point );
  18026. weight = point - intPoint;
  18027. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  18028. c[ 1 ] = intPoint;
  18029. c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
  18030. c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;
  18031. pa = points[ c[ 0 ] ];
  18032. pb = points[ c[ 1 ] ];
  18033. pc = points[ c[ 2 ] ];
  18034. pd = points[ c[ 3 ] ];
  18035. w2 = weight * weight;
  18036. w3 = weight * w2;
  18037. v3[ 0 ] = interpolate( pa[ 0 ], pb[ 0 ], pc[ 0 ], pd[ 0 ], weight, w2, w3 );
  18038. v3[ 1 ] = interpolate( pa[ 1 ], pb[ 1 ], pc[ 1 ], pd[ 1 ], weight, w2, w3 );
  18039. v3[ 2 ] = interpolate( pa[ 2 ], pb[ 2 ], pc[ 2 ], pd[ 2 ], weight, w2, w3 );
  18040. return v3;
  18041. };
  18042. var interpolate = function ( p0, p1, p2, p3, t, t2, t3 ) {
  18043. var v0 = ( p2 - p0 ) * 0.5,
  18044. v1 = ( p3 - p1 ) * 0.5;
  18045. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  18046. };
  18047. return function ( delta ) {
  18048. if ( this.isPlaying === false ) return;
  18049. this.currentTime += delta * this.timeScale;
  18050. if ( this.weight === 0 )
  18051. return;
  18052. //
  18053. var duration = this.data.length;
  18054. if ( this.currentTime > duration || this.currentTime < 0 ) {
  18055. if ( this.loop ) {
  18056. this.currentTime %= duration;
  18057. if ( this.currentTime < 0 )
  18058. this.currentTime += duration;
  18059. this.reset();
  18060. } else {
  18061. this.stop();
  18062. }
  18063. }
  18064. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18065. var object = this.hierarchy[ h ];
  18066. var animationCache = object.animationCache.animations[ this.data.name ];
  18067. var blending = object.animationCache.blending;
  18068. // loop through pos/rot/scl
  18069. for ( var t = 0; t < 3; t ++ ) {
  18070. // get keys
  18071. var type = this.keyTypes[ t ];
  18072. var prevKey = animationCache.prevKey[ type ];
  18073. var nextKey = animationCache.nextKey[ type ];
  18074. if ( ( this.timeScale > 0 && nextKey.time <= this.currentTime ) ||
  18075. ( this.timeScale < 0 && prevKey.time >= this.currentTime ) ) {
  18076. prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  18077. nextKey = this.getNextKeyWith( type, h, 1 );
  18078. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18079. prevKey = nextKey;
  18080. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  18081. }
  18082. animationCache.prevKey[ type ] = prevKey;
  18083. animationCache.nextKey[ type ] = nextKey;
  18084. }
  18085. var scale = ( this.currentTime - prevKey.time ) / ( nextKey.time - prevKey.time );
  18086. var prevXYZ = prevKey[ type ];
  18087. var nextXYZ = nextKey[ type ];
  18088. if ( scale < 0 ) scale = 0;
  18089. if ( scale > 1 ) scale = 1;
  18090. // interpolate
  18091. if ( type === "pos" ) {
  18092. if ( this.interpolationType === THREE.AnimationHandler.LINEAR ) {
  18093. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  18094. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  18095. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  18096. // blend
  18097. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  18098. object.position.lerp( newVector, proportionalWeight );
  18099. blending.positionWeight += this.weight;
  18100. } else if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18101. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18102. points[ 0 ] = this.getPrevKeyWith( "pos", h, prevKey.index - 1 )[ "pos" ];
  18103. points[ 1 ] = prevXYZ;
  18104. points[ 2 ] = nextXYZ;
  18105. points[ 3 ] = this.getNextKeyWith( "pos", h, nextKey.index + 1 )[ "pos" ];
  18106. scale = scale * 0.33 + 0.33;
  18107. var currentPoint = interpolateCatmullRom( points, scale );
  18108. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  18109. blending.positionWeight += this.weight;
  18110. // blend
  18111. var vector = object.position;
  18112. vector.x = vector.x + ( currentPoint[ 0 ] - vector.x ) * proportionalWeight;
  18113. vector.y = vector.y + ( currentPoint[ 1 ] - vector.y ) * proportionalWeight;
  18114. vector.z = vector.z + ( currentPoint[ 2 ] - vector.z ) * proportionalWeight;
  18115. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18116. var forwardPoint = interpolateCatmullRom( points, scale * 1.01 );
  18117. target.set( forwardPoint[ 0 ], forwardPoint[ 1 ], forwardPoint[ 2 ] );
  18118. target.sub( vector );
  18119. target.y = 0;
  18120. target.normalize();
  18121. var angle = Math.atan2( target.x, target.z );
  18122. object.rotation.set( 0, angle, 0 );
  18123. }
  18124. }
  18125. } else if ( type === "rot" ) {
  18126. THREE.Quaternion.slerp( prevXYZ, nextXYZ, newQuat, scale );
  18127. // Avoid paying the cost of an additional slerp if we don't have to
  18128. if ( blending.quaternionWeight === 0 ) {
  18129. object.quaternion.copy( newQuat );
  18130. blending.quaternionWeight = this.weight;
  18131. } else {
  18132. var proportionalWeight = this.weight / ( this.weight + blending.quaternionWeight );
  18133. THREE.Quaternion.slerp( object.quaternion, newQuat, object.quaternion, proportionalWeight );
  18134. blending.quaternionWeight += this.weight;
  18135. }
  18136. } else if ( type === "scl" ) {
  18137. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  18138. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  18139. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  18140. var proportionalWeight = this.weight / ( this.weight + blending.scaleWeight );
  18141. object.scale.lerp( newVector, proportionalWeight );
  18142. blending.scaleWeight += this.weight;
  18143. }
  18144. }
  18145. }
  18146. return true;
  18147. };
  18148. } )(),
  18149. getNextKeyWith: function ( type, h, key ) {
  18150. var keys = this.data.hierarchy[ h ].keys;
  18151. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18152. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18153. key = key < keys.length - 1 ? key : keys.length - 1;
  18154. } else {
  18155. key = key % keys.length;
  18156. }
  18157. for ( ; key < keys.length; key ++ ) {
  18158. if ( keys[ key ][ type ] !== undefined ) {
  18159. return keys[ key ];
  18160. }
  18161. }
  18162. return this.data.hierarchy[ h ].keys[ 0 ];
  18163. },
  18164. getPrevKeyWith: function ( type, h, key ) {
  18165. var keys = this.data.hierarchy[ h ].keys;
  18166. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18167. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18168. key = key > 0 ? key : 0;
  18169. } else {
  18170. key = key >= 0 ? key : key + keys.length;
  18171. }
  18172. for ( ; key >= 0; key -- ) {
  18173. if ( keys[ key ][ type ] !== undefined ) {
  18174. return keys[ key ];
  18175. }
  18176. }
  18177. return this.data.hierarchy[ h ].keys[ keys.length - 1 ];
  18178. }
  18179. };
  18180. // File:src/extras/animation/KeyFrameAnimation.js
  18181. /**
  18182. * @author mikael emtinger / http://gomo.se/
  18183. * @author mrdoob / http://mrdoob.com/
  18184. * @author alteredq / http://alteredqualia.com/
  18185. * @author khang duong
  18186. * @author erik kitson
  18187. */
  18188. THREE.KeyFrameAnimation = function ( data ) {
  18189. this.root = data.node;
  18190. this.data = THREE.AnimationHandler.init( data );
  18191. this.hierarchy = THREE.AnimationHandler.parse( this.root );
  18192. this.currentTime = 0;
  18193. this.timeScale = 0.001;
  18194. this.isPlaying = false;
  18195. this.isPaused = true;
  18196. this.loop = true;
  18197. // initialize to first keyframes
  18198. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18199. var keys = this.data.hierarchy[ h ].keys,
  18200. sids = this.data.hierarchy[ h ].sids,
  18201. obj = this.hierarchy[ h ];
  18202. if ( keys.length && sids ) {
  18203. for ( var s = 0; s < sids.length; s ++ ) {
  18204. var sid = sids[ s ],
  18205. next = this.getNextKeyWith( sid, h, 0 );
  18206. if ( next ) {
  18207. next.apply( sid );
  18208. }
  18209. }
  18210. obj.matrixAutoUpdate = false;
  18211. this.data.hierarchy[ h ].node.updateMatrix();
  18212. obj.matrixWorldNeedsUpdate = true;
  18213. }
  18214. }
  18215. };
  18216. THREE.KeyFrameAnimation.prototype = {
  18217. constructor: THREE.KeyFrameAnimation,
  18218. play: function ( startTime ) {
  18219. this.currentTime = startTime !== undefined ? startTime : 0;
  18220. if ( this.isPlaying === false ) {
  18221. this.isPlaying = true;
  18222. // reset key cache
  18223. var h, hl = this.hierarchy.length,
  18224. object,
  18225. node;
  18226. for ( h = 0; h < hl; h ++ ) {
  18227. object = this.hierarchy[ h ];
  18228. node = this.data.hierarchy[ h ];
  18229. if ( node.animationCache === undefined ) {
  18230. node.animationCache = {};
  18231. node.animationCache.prevKey = null;
  18232. node.animationCache.nextKey = null;
  18233. node.animationCache.originalMatrix = object.matrix;
  18234. }
  18235. var keys = this.data.hierarchy[ h ].keys;
  18236. if ( keys.length ) {
  18237. node.animationCache.prevKey = keys[ 0 ];
  18238. node.animationCache.nextKey = keys[ 1 ];
  18239. this.startTime = Math.min( keys[ 0 ].time, this.startTime );
  18240. this.endTime = Math.max( keys[ keys.length - 1 ].time, this.endTime );
  18241. }
  18242. }
  18243. this.update( 0 );
  18244. }
  18245. this.isPaused = false;
  18246. THREE.AnimationHandler.play( this );
  18247. },
  18248. stop: function () {
  18249. this.isPlaying = false;
  18250. this.isPaused = false;
  18251. THREE.AnimationHandler.stop( this );
  18252. // reset JIT matrix and remove cache
  18253. for ( var h = 0; h < this.data.hierarchy.length; h ++ ) {
  18254. var obj = this.hierarchy[ h ];
  18255. var node = this.data.hierarchy[ h ];
  18256. if ( node.animationCache !== undefined ) {
  18257. var original = node.animationCache.originalMatrix;
  18258. original.copy( obj.matrix );
  18259. obj.matrix = original;
  18260. delete node.animationCache;
  18261. }
  18262. }
  18263. },
  18264. update: function ( delta ) {
  18265. if ( this.isPlaying === false ) return;
  18266. this.currentTime += delta * this.timeScale;
  18267. //
  18268. var duration = this.data.length;
  18269. if ( this.loop === true && this.currentTime > duration ) {
  18270. this.currentTime %= duration;
  18271. }
  18272. this.currentTime = Math.min( this.currentTime, duration );
  18273. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18274. var object = this.hierarchy[ h ];
  18275. var node = this.data.hierarchy[ h ];
  18276. var keys = node.keys,
  18277. animationCache = node.animationCache;
  18278. if ( keys.length ) {
  18279. var prevKey = animationCache.prevKey;
  18280. var nextKey = animationCache.nextKey;
  18281. if ( nextKey.time <= this.currentTime ) {
  18282. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18283. prevKey = nextKey;
  18284. nextKey = keys[ prevKey.index + 1 ];
  18285. }
  18286. animationCache.prevKey = prevKey;
  18287. animationCache.nextKey = nextKey;
  18288. }
  18289. if ( nextKey.time >= this.currentTime ) {
  18290. prevKey.interpolate( nextKey, this.currentTime );
  18291. } else {
  18292. prevKey.interpolate( nextKey, nextKey.time );
  18293. }
  18294. this.data.hierarchy[ h ].node.updateMatrix();
  18295. object.matrixWorldNeedsUpdate = true;
  18296. }
  18297. }
  18298. },
  18299. getNextKeyWith: function ( sid, h, key ) {
  18300. var keys = this.data.hierarchy[ h ].keys;
  18301. key = key % keys.length;
  18302. for ( ; key < keys.length; key ++ ) {
  18303. if ( keys[ key ].hasTarget( sid ) ) {
  18304. return keys[ key ];
  18305. }
  18306. }
  18307. return keys[ 0 ];
  18308. },
  18309. getPrevKeyWith: function ( sid, h, key ) {
  18310. var keys = this.data.hierarchy[ h ].keys;
  18311. key = key >= 0 ? key : key + keys.length;
  18312. for ( ; key >= 0; key -- ) {
  18313. if ( keys[ key ].hasTarget( sid ) ) {
  18314. return keys[ key ];
  18315. }
  18316. }
  18317. return keys[ keys.length - 1 ];
  18318. }
  18319. };
  18320. // File:src/extras/animation/MorphAnimation.js
  18321. /**
  18322. * @author mrdoob / http://mrdoob.com
  18323. * @author willy-vvu / http://willy-vvu.github.io
  18324. */
  18325. THREE.MorphAnimation = function ( mesh ) {
  18326. this.mesh = mesh;
  18327. this.frames = mesh.morphTargetInfluences.length;
  18328. this.currentTime = 0;
  18329. this.duration = 1000;
  18330. this.loop = true;
  18331. this.lastFrame = 0;
  18332. this.currentFrame = 0;
  18333. this.isPlaying = false;
  18334. };
  18335. THREE.MorphAnimation.prototype = {
  18336. constructor: THREE.MorphAnimation,
  18337. play: function () {
  18338. this.isPlaying = true;
  18339. },
  18340. pause: function () {
  18341. this.isPlaying = false;
  18342. },
  18343. update: function ( delta ) {
  18344. if ( this.isPlaying === false ) return;
  18345. this.currentTime += delta;
  18346. if ( this.loop === true && this.currentTime > this.duration ) {
  18347. this.currentTime %= this.duration;
  18348. }
  18349. this.currentTime = Math.min( this.currentTime, this.duration );
  18350. var frameTime = this.duration / this.frames;
  18351. var frame = Math.floor( this.currentTime / frameTime );
  18352. var influences = this.mesh.morphTargetInfluences;
  18353. if ( frame !== this.currentFrame ) {
  18354. influences[ this.lastFrame ] = 0;
  18355. influences[ this.currentFrame ] = 1;
  18356. influences[ frame ] = 0;
  18357. this.lastFrame = this.currentFrame;
  18358. this.currentFrame = frame;
  18359. }
  18360. var mix = ( this.currentTime % frameTime ) / frameTime;
  18361. influences[ frame ] = mix;
  18362. influences[ this.lastFrame ] = 1 - mix;
  18363. }
  18364. };
  18365. // File:src/extras/geometries/BoxGeometry.js
  18366. /**
  18367. * @author mrdoob / http://mrdoob.com/
  18368. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  18369. */
  18370. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  18371. THREE.Geometry.call( this );
  18372. this.type = 'BoxGeometry';
  18373. this.parameters = {
  18374. width: width,
  18375. height: height,
  18376. depth: depth,
  18377. widthSegments: widthSegments,
  18378. heightSegments: heightSegments,
  18379. depthSegments: depthSegments
  18380. };
  18381. this.widthSegments = widthSegments || 1;
  18382. this.heightSegments = heightSegments || 1;
  18383. this.depthSegments = depthSegments || 1;
  18384. var scope = this;
  18385. var width_half = width / 2;
  18386. var height_half = height / 2;
  18387. var depth_half = depth / 2;
  18388. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  18389. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  18390. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  18391. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  18392. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  18393. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  18394. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  18395. var w, ix, iy,
  18396. gridX = scope.widthSegments,
  18397. gridY = scope.heightSegments,
  18398. width_half = width / 2,
  18399. height_half = height / 2,
  18400. offset = scope.vertices.length;
  18401. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  18402. w = 'z';
  18403. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  18404. w = 'y';
  18405. gridY = scope.depthSegments;
  18406. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  18407. w = 'x';
  18408. gridX = scope.depthSegments;
  18409. }
  18410. var gridX1 = gridX + 1,
  18411. gridY1 = gridY + 1,
  18412. segment_width = width / gridX,
  18413. segment_height = height / gridY,
  18414. normal = new THREE.Vector3();
  18415. normal[ w ] = depth > 0 ? 1 : - 1;
  18416. for ( iy = 0; iy < gridY1; iy ++ ) {
  18417. for ( ix = 0; ix < gridX1; ix ++ ) {
  18418. var vector = new THREE.Vector3();
  18419. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  18420. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  18421. vector[ w ] = depth;
  18422. scope.vertices.push( vector );
  18423. }
  18424. }
  18425. for ( iy = 0; iy < gridY; iy ++ ) {
  18426. for ( ix = 0; ix < gridX; ix ++ ) {
  18427. var a = ix + gridX1 * iy;
  18428. var b = ix + gridX1 * ( iy + 1 );
  18429. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  18430. var d = ( ix + 1 ) + gridX1 * iy;
  18431. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  18432. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  18433. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  18434. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  18435. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  18436. face.normal.copy( normal );
  18437. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18438. face.materialIndex = materialIndex;
  18439. scope.faces.push( face );
  18440. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  18441. face = new THREE.Face3( b + offset, c + offset, d + offset );
  18442. face.normal.copy( normal );
  18443. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18444. face.materialIndex = materialIndex;
  18445. scope.faces.push( face );
  18446. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  18447. }
  18448. }
  18449. }
  18450. this.mergeVertices();
  18451. };
  18452. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18453. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  18454. THREE.BoxGeometry.prototype.clone = function () {
  18455. var geometry = new THREE.BoxGeometry(
  18456. this.parameters.width,
  18457. this.parameters.height,
  18458. this.parameters.depth,
  18459. this.parameters.widthSegments,
  18460. this.parameters.heightSegments,
  18461. this.parameters.depthSegments
  18462. );
  18463. return geometry;
  18464. };
  18465. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  18466. // File:src/extras/geometries/CircleGeometry.js
  18467. /**
  18468. * @author hughes
  18469. */
  18470. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18471. THREE.Geometry.call( this );
  18472. this.type = 'CircleGeometry';
  18473. this.parameters = {
  18474. radius: radius,
  18475. segments: segments,
  18476. thetaStart: thetaStart,
  18477. thetaLength: thetaLength
  18478. };
  18479. radius = radius || 50;
  18480. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18481. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18482. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18483. var i, uvs = [],
  18484. center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
  18485. this.vertices.push( center );
  18486. uvs.push( centerUV );
  18487. for ( i = 0; i <= segments; i ++ ) {
  18488. var vertex = new THREE.Vector3();
  18489. var segment = thetaStart + i / segments * thetaLength;
  18490. vertex.x = radius * Math.cos( segment );
  18491. vertex.y = radius * Math.sin( segment );
  18492. this.vertices.push( vertex );
  18493. uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, ( vertex.y / radius + 1 ) / 2 ) );
  18494. }
  18495. var n = new THREE.Vector3( 0, 0, 1 );
  18496. for ( i = 1; i <= segments; i ++ ) {
  18497. this.faces.push( new THREE.Face3( i, i + 1, 0, [ n.clone(), n.clone(), n.clone() ] ) );
  18498. this.faceVertexUvs[ 0 ].push( [ uvs[ i ].clone(), uvs[ i + 1 ].clone(), centerUV.clone() ] );
  18499. }
  18500. this.computeFaceNormals();
  18501. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18502. };
  18503. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18504. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  18505. THREE.CircleGeometry.prototype.clone = function () {
  18506. var geometry = new THREE.CircleGeometry(
  18507. this.parameters.radius,
  18508. this.parameters.segments,
  18509. this.parameters.thetaStart,
  18510. this.parameters.thetaLength
  18511. );
  18512. return geometry;
  18513. };
  18514. // File:src/extras/geometries/CircleBufferGeometry.js
  18515. /**
  18516. * @author benaadams / https://twitter.com/ben_a_adams
  18517. */
  18518. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18519. THREE.BufferGeometry.call( this );
  18520. this.type = 'CircleBufferGeometry';
  18521. this.parameters = {
  18522. radius: radius,
  18523. segments: segments,
  18524. thetaStart: thetaStart,
  18525. thetaLength: thetaLength
  18526. };
  18527. radius = radius || 50;
  18528. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18529. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18530. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18531. var vertices = segments + 2;
  18532. var positions = new Float32Array( vertices * 3 );
  18533. var normals = new Float32Array( vertices * 3 );
  18534. var uvs = new Float32Array( vertices * 2 );
  18535. // center data is already zero, but need to set a few extras
  18536. normals[ 3 ] = 1.0;
  18537. uvs[ 0 ] = 0.5;
  18538. uvs[ 1 ] = 0.5;
  18539. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  18540. var segment = thetaStart + s / segments * thetaLength;
  18541. positions[ i ] = radius * Math.cos( segment );
  18542. positions[ i + 1 ] = radius * Math.sin( segment );
  18543. normals[ i + 2 ] = 1; // normal z
  18544. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  18545. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  18546. }
  18547. var indices = [];
  18548. for ( var i = 1; i <= segments; i ++ ) {
  18549. indices.push( i );
  18550. indices.push( i + 1 );
  18551. indices.push( 0 );
  18552. }
  18553. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  18554. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  18555. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  18556. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  18557. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18558. };
  18559. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18560. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  18561. THREE.CircleBufferGeometry.prototype.clone = function () {
  18562. var geometry = new THREE.CircleBufferGeometry(
  18563. this.parameters.radius,
  18564. this.parameters.segments,
  18565. this.parameters.thetaStart,
  18566. this.parameters.thetaLength
  18567. );
  18568. geometry.copy( this );
  18569. return geometry;
  18570. };
  18571. // File:src/extras/geometries/CylinderGeometry.js
  18572. /**
  18573. * @author mrdoob / http://mrdoob.com/
  18574. */
  18575. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18576. THREE.Geometry.call( this );
  18577. this.type = 'CylinderGeometry';
  18578. this.parameters = {
  18579. radiusTop: radiusTop,
  18580. radiusBottom: radiusBottom,
  18581. height: height,
  18582. radialSegments: radialSegments,
  18583. heightSegments: heightSegments,
  18584. openEnded: openEnded,
  18585. thetaStart: thetaStart,
  18586. thetaLength: thetaLength
  18587. };
  18588. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  18589. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  18590. height = height !== undefined ? height : 100;
  18591. radialSegments = radialSegments || 8;
  18592. heightSegments = heightSegments || 1;
  18593. openEnded = openEnded !== undefined ? openEnded : false;
  18594. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18595. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  18596. var heightHalf = height / 2;
  18597. var x, y, vertices = [], uvs = [];
  18598. for ( y = 0; y <= heightSegments; y ++ ) {
  18599. var verticesRow = [];
  18600. var uvsRow = [];
  18601. var v = y / heightSegments;
  18602. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18603. for ( x = 0; x <= radialSegments; x ++ ) {
  18604. var u = x / radialSegments;
  18605. var vertex = new THREE.Vector3();
  18606. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  18607. vertex.y = - v * height + heightHalf;
  18608. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  18609. this.vertices.push( vertex );
  18610. verticesRow.push( this.vertices.length - 1 );
  18611. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  18612. }
  18613. vertices.push( verticesRow );
  18614. uvs.push( uvsRow );
  18615. }
  18616. var tanTheta = ( radiusBottom - radiusTop ) / height;
  18617. var na, nb;
  18618. for ( x = 0; x < radialSegments; x ++ ) {
  18619. if ( radiusTop !== 0 ) {
  18620. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  18621. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  18622. } else {
  18623. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  18624. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  18625. }
  18626. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  18627. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  18628. for ( y = 0; y < heightSegments; y ++ ) {
  18629. var v1 = vertices[ y ][ x ];
  18630. var v2 = vertices[ y + 1 ][ x ];
  18631. var v3 = vertices[ y + 1 ][ x + 1 ];
  18632. var v4 = vertices[ y ][ x + 1 ];
  18633. var n1 = na.clone();
  18634. var n2 = na.clone();
  18635. var n3 = nb.clone();
  18636. var n4 = nb.clone();
  18637. var uv1 = uvs[ y ][ x ].clone();
  18638. var uv2 = uvs[ y + 1 ][ x ].clone();
  18639. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  18640. var uv4 = uvs[ y ][ x + 1 ].clone();
  18641. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  18642. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  18643. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  18644. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  18645. }
  18646. }
  18647. // top cap
  18648. if ( openEnded === false && radiusTop > 0 ) {
  18649. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  18650. for ( x = 0; x < radialSegments; x ++ ) {
  18651. var v1 = vertices[ 0 ][ x ];
  18652. var v2 = vertices[ 0 ][ x + 1 ];
  18653. var v3 = this.vertices.length - 1;
  18654. var n1 = new THREE.Vector3( 0, 1, 0 );
  18655. var n2 = new THREE.Vector3( 0, 1, 0 );
  18656. var n3 = new THREE.Vector3( 0, 1, 0 );
  18657. var uv1 = uvs[ 0 ][ x ].clone();
  18658. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  18659. var uv3 = new THREE.Vector2( uv2.x, 0 );
  18660. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18661. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18662. }
  18663. }
  18664. // bottom cap
  18665. if ( openEnded === false && radiusBottom > 0 ) {
  18666. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  18667. for ( x = 0; x < radialSegments; x ++ ) {
  18668. var v1 = vertices[ heightSegments ][ x + 1 ];
  18669. var v2 = vertices[ heightSegments ][ x ];
  18670. var v3 = this.vertices.length - 1;
  18671. var n1 = new THREE.Vector3( 0, - 1, 0 );
  18672. var n2 = new THREE.Vector3( 0, - 1, 0 );
  18673. var n3 = new THREE.Vector3( 0, - 1, 0 );
  18674. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  18675. var uv2 = uvs[ heightSegments ][ x ].clone();
  18676. var uv3 = new THREE.Vector2( uv2.x, 1 );
  18677. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18678. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18679. }
  18680. }
  18681. this.computeFaceNormals();
  18682. };
  18683. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18684. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  18685. THREE.CylinderGeometry.prototype.clone = function () {
  18686. var geometry = new THREE.CylinderGeometry(
  18687. this.parameters.radiusTop,
  18688. this.parameters.radiusBottom,
  18689. this.parameters.height,
  18690. this.parameters.radialSegments,
  18691. this.parameters.heightSegments,
  18692. this.parameters.openEnded,
  18693. this.parameters.thetaStart,
  18694. this.parameters.thetaLength
  18695. );
  18696. return geometry;
  18697. };
  18698. // File:src/extras/geometries/EdgesGeometry.js
  18699. /**
  18700. * @author WestLangley / http://github.com/WestLangley
  18701. */
  18702. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  18703. THREE.BufferGeometry.call( this );
  18704. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18705. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  18706. var edge = [ 0, 0 ], hash = {};
  18707. var sortFunction = function ( a, b ) {
  18708. return a - b;
  18709. };
  18710. var keys = [ 'a', 'b', 'c' ];
  18711. var geometry2;
  18712. if ( geometry instanceof THREE.BufferGeometry ) {
  18713. geometry2 = new THREE.Geometry();
  18714. geometry2.fromBufferGeometry( geometry );
  18715. } else {
  18716. geometry2 = geometry.clone();
  18717. }
  18718. geometry2.mergeVertices();
  18719. geometry2.computeFaceNormals();
  18720. var vertices = geometry2.vertices;
  18721. var faces = geometry2.faces;
  18722. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18723. var face = faces[ i ];
  18724. for ( var j = 0; j < 3; j ++ ) {
  18725. edge[ 0 ] = face[ keys[ j ] ];
  18726. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  18727. edge.sort( sortFunction );
  18728. var key = edge.toString();
  18729. if ( hash[ key ] === undefined ) {
  18730. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  18731. } else {
  18732. hash[ key ].face2 = i;
  18733. }
  18734. }
  18735. }
  18736. var coords = [];
  18737. for ( var key in hash ) {
  18738. var h = hash[ key ];
  18739. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  18740. var vertex = vertices[ h.vert1 ];
  18741. coords.push( vertex.x );
  18742. coords.push( vertex.y );
  18743. coords.push( vertex.z );
  18744. vertex = vertices[ h.vert2 ];
  18745. coords.push( vertex.x );
  18746. coords.push( vertex.y );
  18747. coords.push( vertex.z );
  18748. }
  18749. }
  18750. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  18751. };
  18752. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18753. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  18754. // File:src/extras/geometries/ExtrudeGeometry.js
  18755. /**
  18756. * @author zz85 / http://www.lab4games.net/zz85/blog
  18757. *
  18758. * Creates extruded geometry from a path shape.
  18759. *
  18760. * parameters = {
  18761. *
  18762. * curveSegments: <int>, // number of points on the curves
  18763. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18764. * amount: <int>, // Depth to extrude the shape
  18765. *
  18766. * bevelEnabled: <bool>, // turn on bevel
  18767. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18768. * bevelSize: <float>, // how far from shape outline is bevel
  18769. * bevelSegments: <int>, // number of bevel layers
  18770. *
  18771. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  18772. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  18773. *
  18774. * uvGenerator: <Object> // object that provides UV generator functions
  18775. *
  18776. * }
  18777. **/
  18778. THREE.ExtrudeGeometry = function ( shapes, options ) {
  18779. if ( typeof( shapes ) === "undefined" ) {
  18780. shapes = [];
  18781. return;
  18782. }
  18783. THREE.Geometry.call( this );
  18784. this.type = 'ExtrudeGeometry';
  18785. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18786. this.addShapeList( shapes, options );
  18787. this.computeFaceNormals();
  18788. // can't really use automatic vertex normals
  18789. // as then front and back sides get smoothed too
  18790. // should do separate smoothing just for sides
  18791. //this.computeVertexNormals();
  18792. //console.log( "took", ( Date.now() - startTime ) );
  18793. };
  18794. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18795. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  18796. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  18797. var sl = shapes.length;
  18798. for ( var s = 0; s < sl; s ++ ) {
  18799. var shape = shapes[ s ];
  18800. this.addShape( shape, options );
  18801. }
  18802. };
  18803. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  18804. var amount = options.amount !== undefined ? options.amount : 100;
  18805. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  18806. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  18807. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18808. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  18809. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18810. var steps = options.steps !== undefined ? options.steps : 1;
  18811. var extrudePath = options.extrudePath;
  18812. var extrudePts, extrudeByPath = false;
  18813. // Use default WorldUVGenerator if no UV generators are specified.
  18814. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  18815. var splineTube, binormal, normal, position2;
  18816. if ( extrudePath ) {
  18817. extrudePts = extrudePath.getSpacedPoints( steps );
  18818. extrudeByPath = true;
  18819. bevelEnabled = false; // bevels not supported for path extrusion
  18820. // SETUP TNB variables
  18821. // Reuse TNB from TubeGeomtry for now.
  18822. // TODO1 - have a .isClosed in spline?
  18823. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  18824. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18825. binormal = new THREE.Vector3();
  18826. normal = new THREE.Vector3();
  18827. position2 = new THREE.Vector3();
  18828. }
  18829. // Safeguards if bevels are not enabled
  18830. if ( ! bevelEnabled ) {
  18831. bevelSegments = 0;
  18832. bevelThickness = 0;
  18833. bevelSize = 0;
  18834. }
  18835. // Variables initialization
  18836. var ahole, h, hl; // looping of holes
  18837. var scope = this;
  18838. var shapesOffset = this.vertices.length;
  18839. var shapePoints = shape.extractPoints( curveSegments );
  18840. var vertices = shapePoints.shape;
  18841. var holes = shapePoints.holes;
  18842. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  18843. if ( reverse ) {
  18844. vertices = vertices.reverse();
  18845. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18846. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18847. ahole = holes[ h ];
  18848. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  18849. holes[ h ] = ahole.reverse();
  18850. }
  18851. }
  18852. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  18853. }
  18854. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  18855. /* Vertices */
  18856. var contour = vertices; // vertices has all points but contour has only points of circumference
  18857. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18858. ahole = holes[ h ];
  18859. vertices = vertices.concat( ahole );
  18860. }
  18861. function scalePt2 ( pt, vec, size ) {
  18862. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  18863. return vec.clone().multiplyScalar( size ).add( pt );
  18864. }
  18865. var b, bs, t, z,
  18866. vert, vlen = vertices.length,
  18867. face, flen = faces.length;
  18868. // Find directions for point movement
  18869. function getBevelVec( inPt, inPrev, inNext ) {
  18870. var EPSILON = 0.0000000001;
  18871. // computes for inPt the corresponding point inPt' on a new contour
  18872. // shifted by 1 unit (length of normalized vector) to the left
  18873. // if we walk along contour clockwise, this new contour is outside the old one
  18874. //
  18875. // inPt' is the intersection of the two lines parallel to the two
  18876. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18877. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  18878. // good reading for geometry algorithms (here: line-line intersection)
  18879. // http://geomalgorithms.com/a05-_intersect-1.html
  18880. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  18881. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  18882. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18883. // check for collinear edges
  18884. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18885. if ( Math.abs( collinear0 ) > EPSILON ) {
  18886. // not collinear
  18887. // length of vectors for normalizing
  18888. var v_prev_len = Math.sqrt( v_prev_lensq );
  18889. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18890. // shift adjacent points by unit vectors to the left
  18891. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18892. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18893. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18894. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18895. // scaling factor for v_prev to intersection point
  18896. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18897. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18898. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18899. // vector from inPt to intersection point
  18900. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18901. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18902. // Don't normalize!, otherwise sharp corners become ugly
  18903. // but prevent crazy spikes
  18904. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18905. if ( v_trans_lensq <= 2 ) {
  18906. return new THREE.Vector2( v_trans_x, v_trans_y );
  18907. } else {
  18908. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18909. }
  18910. } else {
  18911. // handle special case of collinear edges
  18912. var direction_eq = false; // assumes: opposite
  18913. if ( v_prev_x > EPSILON ) {
  18914. if ( v_next_x > EPSILON ) {
  18915. direction_eq = true;
  18916. }
  18917. } else {
  18918. if ( v_prev_x < - EPSILON ) {
  18919. if ( v_next_x < - EPSILON ) {
  18920. direction_eq = true;
  18921. }
  18922. } else {
  18923. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  18924. direction_eq = true;
  18925. }
  18926. }
  18927. }
  18928. if ( direction_eq ) {
  18929. // console.log("Warning: lines are a straight sequence");
  18930. v_trans_x = - v_prev_y;
  18931. v_trans_y = v_prev_x;
  18932. shrink_by = Math.sqrt( v_prev_lensq );
  18933. } else {
  18934. // console.log("Warning: lines are a straight spike");
  18935. v_trans_x = v_prev_x;
  18936. v_trans_y = v_prev_y;
  18937. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18938. }
  18939. }
  18940. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18941. }
  18942. var contourMovements = [];
  18943. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18944. if ( j === il ) j = 0;
  18945. if ( k === il ) k = 0;
  18946. // (j)---(i)---(k)
  18947. // console.log('i,j,k', i, j , k)
  18948. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18949. }
  18950. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  18951. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18952. ahole = holes[ h ];
  18953. oneHoleMovements = [];
  18954. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18955. if ( j === il ) j = 0;
  18956. if ( k === il ) k = 0;
  18957. // (j)---(i)---(k)
  18958. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  18959. }
  18960. holesMovements.push( oneHoleMovements );
  18961. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18962. }
  18963. // Loop bevelSegments, 1 for the front, 1 for the back
  18964. for ( b = 0; b < bevelSegments; b ++ ) {
  18965. //for ( b = bevelSegments; b > 0; b -- ) {
  18966. t = b / bevelSegments;
  18967. z = bevelThickness * ( 1 - t );
  18968. //z = bevelThickness * t;
  18969. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  18970. //bs = bevelSize * t; // linear
  18971. // contract shape
  18972. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18973. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18974. v( vert.x, vert.y, - z );
  18975. }
  18976. // expand holes
  18977. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18978. ahole = holes[ h ];
  18979. oneHoleMovements = holesMovements[ h ];
  18980. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18981. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18982. v( vert.x, vert.y, - z );
  18983. }
  18984. }
  18985. }
  18986. bs = bevelSize;
  18987. // Back facing vertices
  18988. for ( i = 0; i < vlen; i ++ ) {
  18989. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18990. if ( ! extrudeByPath ) {
  18991. v( vert.x, vert.y, 0 );
  18992. } else {
  18993. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18994. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  18995. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  18996. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  18997. v( position2.x, position2.y, position2.z );
  18998. }
  18999. }
  19000. // Add stepped vertices...
  19001. // Including front facing vertices
  19002. var s;
  19003. for ( s = 1; s <= steps; s ++ ) {
  19004. for ( i = 0; i < vlen; i ++ ) {
  19005. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19006. if ( ! extrudeByPath ) {
  19007. v( vert.x, vert.y, amount / steps * s );
  19008. } else {
  19009. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  19010. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  19011. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  19012. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  19013. v( position2.x, position2.y, position2.z );
  19014. }
  19015. }
  19016. }
  19017. // Add bevel segments planes
  19018. //for ( b = 1; b <= bevelSegments; b ++ ) {
  19019. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  19020. t = b / bevelSegments;
  19021. z = bevelThickness * ( 1 - t );
  19022. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  19023. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  19024. // contract shape
  19025. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19026. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19027. v( vert.x, vert.y, amount + z );
  19028. }
  19029. // expand holes
  19030. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19031. ahole = holes[ h ];
  19032. oneHoleMovements = holesMovements[ h ];
  19033. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19034. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19035. if ( ! extrudeByPath ) {
  19036. v( vert.x, vert.y, amount + z );
  19037. } else {
  19038. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  19039. }
  19040. }
  19041. }
  19042. }
  19043. /* Faces */
  19044. // Top and bottom faces
  19045. buildLidFaces();
  19046. // Sides faces
  19047. buildSideFaces();
  19048. ///// Internal functions
  19049. function buildLidFaces() {
  19050. if ( bevelEnabled ) {
  19051. var layer = 0; // steps + 1
  19052. var offset = vlen * layer;
  19053. // Bottom faces
  19054. for ( i = 0; i < flen; i ++ ) {
  19055. face = faces[ i ];
  19056. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  19057. }
  19058. layer = steps + bevelSegments * 2;
  19059. offset = vlen * layer;
  19060. // Top faces
  19061. for ( i = 0; i < flen; i ++ ) {
  19062. face = faces[ i ];
  19063. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  19064. }
  19065. } else {
  19066. // Bottom faces
  19067. for ( i = 0; i < flen; i ++ ) {
  19068. face = faces[ i ];
  19069. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  19070. }
  19071. // Top faces
  19072. for ( i = 0; i < flen; i ++ ) {
  19073. face = faces[ i ];
  19074. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  19075. }
  19076. }
  19077. }
  19078. // Create faces for the z-sides of the shape
  19079. function buildSideFaces() {
  19080. var layeroffset = 0;
  19081. sidewalls( contour, layeroffset );
  19082. layeroffset += contour.length;
  19083. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19084. ahole = holes[ h ];
  19085. sidewalls( ahole, layeroffset );
  19086. //, true
  19087. layeroffset += ahole.length;
  19088. }
  19089. }
  19090. function sidewalls( contour, layeroffset ) {
  19091. var j, k;
  19092. i = contour.length;
  19093. while ( -- i >= 0 ) {
  19094. j = i;
  19095. k = i - 1;
  19096. if ( k < 0 ) k = contour.length - 1;
  19097. //console.log('b', i,j, i-1, k,vertices.length);
  19098. var s = 0, sl = steps + bevelSegments * 2;
  19099. for ( s = 0; s < sl; s ++ ) {
  19100. var slen1 = vlen * s;
  19101. var slen2 = vlen * ( s + 1 );
  19102. var a = layeroffset + j + slen1,
  19103. b = layeroffset + k + slen1,
  19104. c = layeroffset + k + slen2,
  19105. d = layeroffset + j + slen2;
  19106. f4( a, b, c, d, contour, s, sl, j, k );
  19107. }
  19108. }
  19109. }
  19110. function v( x, y, z ) {
  19111. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  19112. }
  19113. function f3( a, b, c ) {
  19114. a += shapesOffset;
  19115. b += shapesOffset;
  19116. c += shapesOffset;
  19117. scope.faces.push( new THREE.Face3( a, b, c ) );
  19118. var uvs = uvgen.generateTopUV( scope, a, b, c );
  19119. scope.faceVertexUvs[ 0 ].push( uvs );
  19120. }
  19121. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  19122. a += shapesOffset;
  19123. b += shapesOffset;
  19124. c += shapesOffset;
  19125. d += shapesOffset;
  19126. scope.faces.push( new THREE.Face3( a, b, d ) );
  19127. scope.faces.push( new THREE.Face3( b, c, d ) );
  19128. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  19129. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  19130. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  19131. }
  19132. };
  19133. THREE.ExtrudeGeometry.WorldUVGenerator = {
  19134. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  19135. var vertices = geometry.vertices;
  19136. var a = vertices[ indexA ];
  19137. var b = vertices[ indexB ];
  19138. var c = vertices[ indexC ];
  19139. return [
  19140. new THREE.Vector2( a.x, a.y ),
  19141. new THREE.Vector2( b.x, b.y ),
  19142. new THREE.Vector2( c.x, c.y )
  19143. ];
  19144. },
  19145. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  19146. var vertices = geometry.vertices;
  19147. var a = vertices[ indexA ];
  19148. var b = vertices[ indexB ];
  19149. var c = vertices[ indexC ];
  19150. var d = vertices[ indexD ];
  19151. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  19152. return [
  19153. new THREE.Vector2( a.x, 1 - a.z ),
  19154. new THREE.Vector2( b.x, 1 - b.z ),
  19155. new THREE.Vector2( c.x, 1 - c.z ),
  19156. new THREE.Vector2( d.x, 1 - d.z )
  19157. ];
  19158. } else {
  19159. return [
  19160. new THREE.Vector2( a.y, 1 - a.z ),
  19161. new THREE.Vector2( b.y, 1 - b.z ),
  19162. new THREE.Vector2( c.y, 1 - c.z ),
  19163. new THREE.Vector2( d.y, 1 - d.z )
  19164. ];
  19165. }
  19166. }
  19167. };
  19168. // File:src/extras/geometries/ShapeGeometry.js
  19169. /**
  19170. * @author jonobr1 / http://jonobr1.com
  19171. *
  19172. * Creates a one-sided polygonal geometry from a path shape. Similar to
  19173. * ExtrudeGeometry.
  19174. *
  19175. * parameters = {
  19176. *
  19177. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  19178. *
  19179. * material: <int> // material index for front and back faces
  19180. * uvGenerator: <Object> // object that provides UV generator functions
  19181. *
  19182. * }
  19183. **/
  19184. THREE.ShapeGeometry = function ( shapes, options ) {
  19185. THREE.Geometry.call( this );
  19186. this.type = 'ShapeGeometry';
  19187. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  19188. this.addShapeList( shapes, options );
  19189. this.computeFaceNormals();
  19190. };
  19191. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19192. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  19193. /**
  19194. * Add an array of shapes to THREE.ShapeGeometry.
  19195. */
  19196. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19197. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19198. this.addShape( shapes[ i ], options );
  19199. }
  19200. return this;
  19201. };
  19202. /**
  19203. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  19204. */
  19205. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  19206. if ( options === undefined ) options = {};
  19207. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19208. var material = options.material;
  19209. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  19210. //
  19211. var i, l, hole;
  19212. var shapesOffset = this.vertices.length;
  19213. var shapePoints = shape.extractPoints( curveSegments );
  19214. var vertices = shapePoints.shape;
  19215. var holes = shapePoints.holes;
  19216. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19217. if ( reverse ) {
  19218. vertices = vertices.reverse();
  19219. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  19220. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19221. hole = holes[ i ];
  19222. if ( THREE.Shape.Utils.isClockWise( hole ) ) {
  19223. holes[ i ] = hole.reverse();
  19224. }
  19225. }
  19226. reverse = false;
  19227. }
  19228. var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
  19229. // Vertices
  19230. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19231. hole = holes[ i ];
  19232. vertices = vertices.concat( hole );
  19233. }
  19234. //
  19235. var vert, vlen = vertices.length;
  19236. var face, flen = faces.length;
  19237. for ( i = 0; i < vlen; i ++ ) {
  19238. vert = vertices[ i ];
  19239. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  19240. }
  19241. for ( i = 0; i < flen; i ++ ) {
  19242. face = faces[ i ];
  19243. var a = face[ 0 ] + shapesOffset;
  19244. var b = face[ 1 ] + shapesOffset;
  19245. var c = face[ 2 ] + shapesOffset;
  19246. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  19247. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  19248. }
  19249. };
  19250. // File:src/extras/geometries/LatheGeometry.js
  19251. /**
  19252. * @author astrodud / http://astrodud.isgreat.org/
  19253. * @author zz85 / https://github.com/zz85
  19254. * @author bhouston / http://exocortex.com
  19255. */
  19256. // points - to create a closed torus, one must use a set of points
  19257. // like so: [ a, b, c, d, a ], see first is the same as last.
  19258. // segments - the number of circumference segments to create
  19259. // phiStart - the starting radian
  19260. // phiLength - the radian (0 to 2*PI) range of the lathed section
  19261. // 2*pi is a closed lathe, less than 2PI is a portion.
  19262. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  19263. THREE.Geometry.call( this );
  19264. this.type = 'LatheGeometry';
  19265. this.parameters = {
  19266. points: points,
  19267. segments: segments,
  19268. phiStart: phiStart,
  19269. phiLength: phiLength
  19270. };
  19271. segments = segments || 12;
  19272. phiStart = phiStart || 0;
  19273. phiLength = phiLength || 2 * Math.PI;
  19274. var inversePointLength = 1.0 / ( points.length - 1 );
  19275. var inverseSegments = 1.0 / segments;
  19276. for ( var i = 0, il = segments; i <= il; i ++ ) {
  19277. var phi = phiStart + i * inverseSegments * phiLength;
  19278. var c = Math.cos( phi ),
  19279. s = Math.sin( phi );
  19280. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  19281. var pt = points[ j ];
  19282. var vertex = new THREE.Vector3();
  19283. vertex.x = c * pt.x - s * pt.y;
  19284. vertex.y = s * pt.x + c * pt.y;
  19285. vertex.z = pt.z;
  19286. this.vertices.push( vertex );
  19287. }
  19288. }
  19289. var np = points.length;
  19290. for ( var i = 0, il = segments; i < il; i ++ ) {
  19291. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  19292. var base = j + np * i;
  19293. var a = base;
  19294. var b = base + np;
  19295. var c = base + 1 + np;
  19296. var d = base + 1;
  19297. var u0 = i * inverseSegments;
  19298. var v0 = j * inversePointLength;
  19299. var u1 = u0 + inverseSegments;
  19300. var v1 = v0 + inversePointLength;
  19301. this.faces.push( new THREE.Face3( a, b, d ) );
  19302. this.faceVertexUvs[ 0 ].push( [
  19303. new THREE.Vector2( u0, v0 ),
  19304. new THREE.Vector2( u1, v0 ),
  19305. new THREE.Vector2( u0, v1 )
  19306. ] );
  19307. this.faces.push( new THREE.Face3( b, c, d ) );
  19308. this.faceVertexUvs[ 0 ].push( [
  19309. new THREE.Vector2( u1, v0 ),
  19310. new THREE.Vector2( u1, v1 ),
  19311. new THREE.Vector2( u0, v1 )
  19312. ] );
  19313. }
  19314. }
  19315. this.mergeVertices();
  19316. this.computeFaceNormals();
  19317. this.computeVertexNormals();
  19318. };
  19319. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19320. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  19321. // File:src/extras/geometries/PlaneGeometry.js
  19322. /**
  19323. * @author mrdoob / http://mrdoob.com/
  19324. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19325. */
  19326. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  19327. THREE.Geometry.call( this );
  19328. this.type = 'PlaneGeometry';
  19329. this.parameters = {
  19330. width: width,
  19331. height: height,
  19332. widthSegments: widthSegments,
  19333. heightSegments: heightSegments
  19334. };
  19335. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  19336. };
  19337. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19338. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  19339. THREE.PlaneGeometry.prototype.clone = function () {
  19340. var geometry = new THREE.PlaneGeometry(
  19341. this.parameters.width,
  19342. this.parameters.height,
  19343. this.parameters.widthSegments,
  19344. this.parameters.heightSegments
  19345. );
  19346. return geometry;
  19347. };
  19348. // File:src/extras/geometries/PlaneBufferGeometry.js
  19349. /**
  19350. * @author mrdoob / http://mrdoob.com/
  19351. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19352. */
  19353. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  19354. THREE.BufferGeometry.call( this );
  19355. this.type = 'PlaneBufferGeometry';
  19356. this.parameters = {
  19357. width: width,
  19358. height: height,
  19359. widthSegments: widthSegments,
  19360. heightSegments: heightSegments
  19361. };
  19362. var width_half = width / 2;
  19363. var height_half = height / 2;
  19364. var gridX = Math.floor( widthSegments ) || 1;
  19365. var gridY = Math.floor( heightSegments ) || 1;
  19366. var gridX1 = gridX + 1;
  19367. var gridY1 = gridY + 1;
  19368. var segment_width = width / gridX;
  19369. var segment_height = height / gridY;
  19370. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  19371. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  19372. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  19373. var offset = 0;
  19374. var offset2 = 0;
  19375. for ( var iy = 0; iy < gridY1; iy ++ ) {
  19376. var y = iy * segment_height - height_half;
  19377. for ( var ix = 0; ix < gridX1; ix ++ ) {
  19378. var x = ix * segment_width - width_half;
  19379. vertices[ offset ] = x;
  19380. vertices[ offset + 1 ] = - y;
  19381. normals[ offset + 2 ] = 1;
  19382. uvs[ offset2 ] = ix / gridX;
  19383. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  19384. offset += 3;
  19385. offset2 += 2;
  19386. }
  19387. }
  19388. offset = 0;
  19389. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  19390. for ( var iy = 0; iy < gridY; iy ++ ) {
  19391. for ( var ix = 0; ix < gridX; ix ++ ) {
  19392. var a = ix + gridX1 * iy;
  19393. var b = ix + gridX1 * ( iy + 1 );
  19394. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  19395. var d = ( ix + 1 ) + gridX1 * iy;
  19396. indices[ offset ] = a;
  19397. indices[ offset + 1 ] = b;
  19398. indices[ offset + 2 ] = d;
  19399. indices[ offset + 3 ] = b;
  19400. indices[ offset + 4 ] = c;
  19401. indices[ offset + 5 ] = d;
  19402. offset += 6;
  19403. }
  19404. }
  19405. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  19406. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  19407. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  19408. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  19409. };
  19410. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19411. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  19412. THREE.PlaneBufferGeometry.prototype.clone = function () {
  19413. var geometry = new THREE.PlaneBufferGeometry(
  19414. this.parameters.width,
  19415. this.parameters.height,
  19416. this.parameters.widthSegments,
  19417. this.parameters.heightSegments
  19418. );
  19419. geometry.copy( this );
  19420. return geometry;
  19421. };
  19422. // File:src/extras/geometries/RingGeometry.js
  19423. /**
  19424. * @author Kaleb Murphy
  19425. */
  19426. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19427. THREE.Geometry.call( this );
  19428. this.type = 'RingGeometry';
  19429. this.parameters = {
  19430. innerRadius: innerRadius,
  19431. outerRadius: outerRadius,
  19432. thetaSegments: thetaSegments,
  19433. phiSegments: phiSegments,
  19434. thetaStart: thetaStart,
  19435. thetaLength: thetaLength
  19436. };
  19437. innerRadius = innerRadius || 0;
  19438. outerRadius = outerRadius || 50;
  19439. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19440. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19441. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  19442. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  19443. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19444. for ( i = 0; i < phiSegments + 1; i ++ ) {
  19445. // concentric circles inside ring
  19446. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  19447. // number of segments per circle
  19448. var vertex = new THREE.Vector3();
  19449. var segment = thetaStart + o / thetaSegments * thetaLength;
  19450. vertex.x = radius * Math.cos( segment );
  19451. vertex.y = radius * Math.sin( segment );
  19452. this.vertices.push( vertex );
  19453. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  19454. }
  19455. radius += radiusStep;
  19456. }
  19457. var n = new THREE.Vector3( 0, 0, 1 );
  19458. for ( i = 0; i < phiSegments; i ++ ) {
  19459. // concentric circles inside ring
  19460. var thetaSegment = i * ( thetaSegments + 1 );
  19461. for ( o = 0; o < thetaSegments ; o ++ ) {
  19462. // number of segments per circle
  19463. var segment = o + thetaSegment;
  19464. var v1 = segment;
  19465. var v2 = segment + thetaSegments + 1;
  19466. var v3 = segment + thetaSegments + 2;
  19467. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19468. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  19469. v1 = segment;
  19470. v2 = segment + thetaSegments + 2;
  19471. v3 = segment + 1;
  19472. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19473. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  19474. }
  19475. }
  19476. this.computeFaceNormals();
  19477. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19478. };
  19479. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19480. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  19481. THREE.RingGeometry.prototype.clone = function () {
  19482. var geometry = new THREE.RingGeometry(
  19483. this.parameters.innerRadius,
  19484. this.parameters.outerRadius,
  19485. this.parameters.thetaSegments,
  19486. this.parameters.phiSegments,
  19487. this.parameters.thetaStart,
  19488. this.parameters.thetaLength
  19489. );
  19490. return geometry;
  19491. };
  19492. // File:src/extras/geometries/SphereGeometry.js
  19493. /**
  19494. * @author mrdoob / http://mrdoob.com/
  19495. */
  19496. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19497. console.log( 'THREE.SphereGeometry: Consider using THREE.SphereBufferGeometry for lower memory footprint.' );
  19498. THREE.Geometry.call( this );
  19499. this.type = 'SphereGeometry';
  19500. this.parameters = {
  19501. radius: radius,
  19502. widthSegments: widthSegments,
  19503. heightSegments: heightSegments,
  19504. phiStart: phiStart,
  19505. phiLength: phiLength,
  19506. thetaStart: thetaStart,
  19507. thetaLength: thetaLength
  19508. };
  19509. radius = radius || 50;
  19510. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19511. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19512. phiStart = phiStart !== undefined ? phiStart : 0;
  19513. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19514. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19515. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19516. var x, y, vertices = [], uvs = [];
  19517. for ( y = 0; y <= heightSegments; y ++ ) {
  19518. var verticesRow = [];
  19519. var uvsRow = [];
  19520. for ( x = 0; x <= widthSegments; x ++ ) {
  19521. var u = x / widthSegments;
  19522. var v = y / heightSegments;
  19523. var vertex = new THREE.Vector3();
  19524. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19525. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  19526. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19527. this.vertices.push( vertex );
  19528. verticesRow.push( this.vertices.length - 1 );
  19529. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  19530. }
  19531. vertices.push( verticesRow );
  19532. uvs.push( uvsRow );
  19533. }
  19534. for ( y = 0; y < heightSegments; y ++ ) {
  19535. for ( x = 0; x < widthSegments; x ++ ) {
  19536. var v1 = vertices[ y ][ x + 1 ];
  19537. var v2 = vertices[ y ][ x ];
  19538. var v3 = vertices[ y + 1 ][ x ];
  19539. var v4 = vertices[ y + 1 ][ x + 1 ];
  19540. var n1 = this.vertices[ v1 ].clone().normalize();
  19541. var n2 = this.vertices[ v2 ].clone().normalize();
  19542. var n3 = this.vertices[ v3 ].clone().normalize();
  19543. var n4 = this.vertices[ v4 ].clone().normalize();
  19544. var uv1 = uvs[ y ][ x + 1 ].clone();
  19545. var uv2 = uvs[ y ][ x ].clone();
  19546. var uv3 = uvs[ y + 1 ][ x ].clone();
  19547. var uv4 = uvs[ y + 1 ][ x + 1 ].clone();
  19548. if ( Math.abs( this.vertices[ v1 ].y ) === radius ) {
  19549. uv1.x = ( uv1.x + uv2.x ) / 2;
  19550. this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
  19551. this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
  19552. } else if ( Math.abs( this.vertices[ v3 ].y ) === radius ) {
  19553. uv3.x = ( uv3.x + uv4.x ) / 2;
  19554. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  19555. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19556. } else {
  19557. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  19558. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  19559. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  19560. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  19561. }
  19562. }
  19563. }
  19564. this.computeFaceNormals();
  19565. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19566. };
  19567. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19568. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  19569. THREE.SphereGeometry.prototype.clone = function () {
  19570. var geometry = new THREE.SphereGeometry(
  19571. this.parameters.radius,
  19572. this.parameters.widthSegments,
  19573. this.parameters.heightSegments,
  19574. this.parameters.phiStart,
  19575. this.parameters.phiLength,
  19576. this.parameters.thetaStart,
  19577. this.parameters.thetaLength
  19578. );
  19579. return geometry;
  19580. };
  19581. // File:src/extras/geometries/SphereBufferGeometry.js
  19582. /**
  19583. * @author benaadams / https://twitter.com/ben_a_adams
  19584. * based on THREE.SphereGeometry
  19585. */
  19586. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19587. THREE.BufferGeometry.call( this );
  19588. this.type = 'SphereBufferGeometry';
  19589. this.parameters = {
  19590. radius: radius,
  19591. widthSegments: widthSegments,
  19592. heightSegments: heightSegments,
  19593. phiStart: phiStart,
  19594. phiLength: phiLength,
  19595. thetaStart: thetaStart,
  19596. thetaLength: thetaLength
  19597. };
  19598. radius = radius || 50;
  19599. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19600. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19601. phiStart = phiStart !== undefined ? phiStart : 0;
  19602. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19603. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19604. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19605. var thetaEnd = thetaStart + thetaLength;
  19606. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  19607. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19608. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19609. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  19610. var index = 0, vertices = [], normal = new THREE.Vector3();
  19611. for ( var y = 0; y <= heightSegments; y ++ ) {
  19612. var verticesRow = [];
  19613. var v = y / heightSegments;
  19614. for ( var x = 0; x <= widthSegments; x ++ ) {
  19615. var u = x / widthSegments;
  19616. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19617. var py = radius * Math.cos( thetaStart + v * thetaLength );
  19618. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19619. normal.set( px, py, pz ).normalize();
  19620. positions.setXYZ( index, px, py, pz );
  19621. normals.setXYZ( index, normal.x, normal.y, normal.z );
  19622. uvs.setXY( index, u, 1 - v );
  19623. verticesRow.push( index );
  19624. index ++;
  19625. }
  19626. vertices.push( verticesRow );
  19627. }
  19628. var indices = [];
  19629. for ( var y = 0; y < heightSegments; y ++ ) {
  19630. for ( var x = 0; x < widthSegments; x ++ ) {
  19631. var v1 = vertices[ y ][ x + 1 ];
  19632. var v2 = vertices[ y ][ x ];
  19633. var v3 = vertices[ y + 1 ][ x ];
  19634. var v4 = vertices[ y + 1 ][ x + 1 ];
  19635. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  19636. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  19637. }
  19638. }
  19639. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  19640. this.addAttribute( 'position', positions );
  19641. this.addAttribute( 'normal', normals );
  19642. this.addAttribute( 'uv', uvs );
  19643. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19644. };
  19645. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19646. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  19647. THREE.SphereBufferGeometry.prototype.clone = function () {
  19648. var geometry = new THREE.SphereBufferGeometry(
  19649. this.parameters.radius,
  19650. this.parameters.widthSegments,
  19651. this.parameters.heightSegments,
  19652. this.parameters.phiStart,
  19653. this.parameters.phiLength,
  19654. this.parameters.thetaStart,
  19655. this.parameters.thetaLength
  19656. );
  19657. geometry.copy( this );
  19658. return geometry;
  19659. };
  19660. // File:src/extras/geometries/TextGeometry.js
  19661. /**
  19662. * @author zz85 / http://www.lab4games.net/zz85/blog
  19663. * @author alteredq / http://alteredqualia.com/
  19664. *
  19665. * For creating 3D text geometry in three.js
  19666. *
  19667. * Text = 3D Text
  19668. *
  19669. * parameters = {
  19670. * size: <float>, // size of the text
  19671. * height: <float>, // thickness to extrude text
  19672. * curveSegments: <int>, // number of points on the curves
  19673. *
  19674. * font: <string>, // font name
  19675. * weight: <string>, // font weight (normal, bold)
  19676. * style: <string>, // font style (normal, italics)
  19677. *
  19678. * bevelEnabled: <bool>, // turn on bevel
  19679. * bevelThickness: <float>, // how deep into text bevel goes
  19680. * bevelSize: <float>, // how far from text outline is bevel
  19681. * }
  19682. *
  19683. */
  19684. /* Usage Examples
  19685. // TextGeometry wrapper
  19686. var text3d = new TextGeometry( text, options );
  19687. // Complete manner
  19688. var textShapes = THREE.FontUtils.generateShapes( text, options );
  19689. var text3d = new ExtrudeGeometry( textShapes, options );
  19690. */
  19691. THREE.TextGeometry = function ( text, parameters ) {
  19692. parameters = parameters || {};
  19693. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  19694. // translate parameters to ExtrudeGeometry API
  19695. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  19696. // defaults
  19697. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  19698. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  19699. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  19700. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  19701. this.type = 'TextGeometry';
  19702. };
  19703. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  19704. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  19705. // File:src/extras/geometries/TorusGeometry.js
  19706. /**
  19707. * @author oosmoxiecode
  19708. * @author mrdoob / http://mrdoob.com/
  19709. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  19710. */
  19711. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  19712. THREE.Geometry.call( this );
  19713. this.type = 'TorusGeometry';
  19714. this.parameters = {
  19715. radius: radius,
  19716. tube: tube,
  19717. radialSegments: radialSegments,
  19718. tubularSegments: tubularSegments,
  19719. arc: arc
  19720. };
  19721. radius = radius || 100;
  19722. tube = tube || 40;
  19723. radialSegments = radialSegments || 8;
  19724. tubularSegments = tubularSegments || 6;
  19725. arc = arc || Math.PI * 2;
  19726. var center = new THREE.Vector3(), uvs = [], normals = [];
  19727. for ( var j = 0; j <= radialSegments; j ++ ) {
  19728. for ( var i = 0; i <= tubularSegments; i ++ ) {
  19729. var u = i / tubularSegments * arc;
  19730. var v = j / radialSegments * Math.PI * 2;
  19731. center.x = radius * Math.cos( u );
  19732. center.y = radius * Math.sin( u );
  19733. var vertex = new THREE.Vector3();
  19734. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  19735. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  19736. vertex.z = tube * Math.sin( v );
  19737. this.vertices.push( vertex );
  19738. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  19739. normals.push( vertex.clone().sub( center ).normalize() );
  19740. }
  19741. }
  19742. for ( var j = 1; j <= radialSegments; j ++ ) {
  19743. for ( var i = 1; i <= tubularSegments; i ++ ) {
  19744. var a = ( tubularSegments + 1 ) * j + i - 1;
  19745. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  19746. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  19747. var d = ( tubularSegments + 1 ) * j + i;
  19748. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  19749. this.faces.push( face );
  19750. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  19751. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  19752. this.faces.push( face );
  19753. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  19754. }
  19755. }
  19756. this.computeFaceNormals();
  19757. };
  19758. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19759. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  19760. THREE.TorusGeometry.prototype.clone = function () {
  19761. var geometry = new THREE.TorusGeometry(
  19762. this.parameters.radius,
  19763. this.parameters.tube,
  19764. this.parameters.radialSegments,
  19765. this.parameters.tubularSegments,
  19766. this.parameters.arc
  19767. );
  19768. return geometry;
  19769. };
  19770. // File:src/extras/geometries/TorusKnotGeometry.js
  19771. /**
  19772. * @author oosmoxiecode
  19773. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  19774. */
  19775. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  19776. THREE.Geometry.call( this );
  19777. this.type = 'TorusKnotGeometry';
  19778. this.parameters = {
  19779. radius: radius,
  19780. tube: tube,
  19781. radialSegments: radialSegments,
  19782. tubularSegments: tubularSegments,
  19783. p: p,
  19784. q: q,
  19785. heightScale: heightScale
  19786. };
  19787. radius = radius || 100;
  19788. tube = tube || 40;
  19789. radialSegments = radialSegments || 64;
  19790. tubularSegments = tubularSegments || 8;
  19791. p = p || 2;
  19792. q = q || 3;
  19793. heightScale = heightScale || 1;
  19794. var grid = new Array( radialSegments );
  19795. var tang = new THREE.Vector3();
  19796. var n = new THREE.Vector3();
  19797. var bitan = new THREE.Vector3();
  19798. for ( var i = 0; i < radialSegments; ++ i ) {
  19799. grid[ i ] = new Array( tubularSegments );
  19800. var u = i / radialSegments * 2 * p * Math.PI;
  19801. var p1 = getPos( u, q, p, radius, heightScale );
  19802. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  19803. tang.subVectors( p2, p1 );
  19804. n.addVectors( p2, p1 );
  19805. bitan.crossVectors( tang, n );
  19806. n.crossVectors( bitan, tang );
  19807. bitan.normalize();
  19808. n.normalize();
  19809. for ( var j = 0; j < tubularSegments; ++ j ) {
  19810. var v = j / tubularSegments * 2 * Math.PI;
  19811. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19812. var cy = tube * Math.sin( v );
  19813. var pos = new THREE.Vector3();
  19814. pos.x = p1.x + cx * n.x + cy * bitan.x;
  19815. pos.y = p1.y + cx * n.y + cy * bitan.y;
  19816. pos.z = p1.z + cx * n.z + cy * bitan.z;
  19817. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  19818. }
  19819. }
  19820. for ( var i = 0; i < radialSegments; ++ i ) {
  19821. for ( var j = 0; j < tubularSegments; ++ j ) {
  19822. var ip = ( i + 1 ) % radialSegments;
  19823. var jp = ( j + 1 ) % tubularSegments;
  19824. var a = grid[ i ][ j ];
  19825. var b = grid[ ip ][ j ];
  19826. var c = grid[ ip ][ jp ];
  19827. var d = grid[ i ][ jp ];
  19828. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  19829. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  19830. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  19831. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  19832. this.faces.push( new THREE.Face3( a, b, d ) );
  19833. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19834. this.faces.push( new THREE.Face3( b, c, d ) );
  19835. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19836. }
  19837. }
  19838. this.computeFaceNormals();
  19839. this.computeVertexNormals();
  19840. function getPos( u, in_q, in_p, radius, heightScale ) {
  19841. var cu = Math.cos( u );
  19842. var su = Math.sin( u );
  19843. var quOverP = in_q / in_p * u;
  19844. var cs = Math.cos( quOverP );
  19845. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  19846. var ty = radius * ( 2 + cs ) * su * 0.5;
  19847. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  19848. return new THREE.Vector3( tx, ty, tz );
  19849. }
  19850. };
  19851. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19852. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  19853. THREE.TorusKnotGeometry.prototype.clone = function () {
  19854. var geometry = new THREE.TorusKnotGeometry(
  19855. this.parameters.radius,
  19856. this.parameters.tube,
  19857. this.parameters.radialSegments,
  19858. this.parameters.tubularSegments,
  19859. this.parameters.p,
  19860. this.parameters.q,
  19861. this.parameters.heightScale
  19862. );
  19863. return geometry;
  19864. };
  19865. // File:src/extras/geometries/TubeGeometry.js
  19866. /**
  19867. * @author WestLangley / https://github.com/WestLangley
  19868. * @author zz85 / https://github.com/zz85
  19869. * @author miningold / https://github.com/miningold
  19870. * @author jonobr1 / https://github.com/jonobr1
  19871. *
  19872. * Modified from the TorusKnotGeometry by @oosmoxiecode
  19873. *
  19874. * Creates a tube which extrudes along a 3d spline
  19875. *
  19876. * Uses parallel transport frames as described in
  19877. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  19878. */
  19879. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  19880. THREE.Geometry.call( this );
  19881. this.type = 'TubeGeometry';
  19882. this.parameters = {
  19883. path: path,
  19884. segments: segments,
  19885. radius: radius,
  19886. radialSegments: radialSegments,
  19887. closed: closed
  19888. };
  19889. segments = segments || 64;
  19890. radius = radius || 1;
  19891. radialSegments = radialSegments || 8;
  19892. closed = closed || false;
  19893. taper = taper || THREE.TubeGeometry.NoTaper;
  19894. var grid = [];
  19895. var scope = this,
  19896. tangent,
  19897. normal,
  19898. binormal,
  19899. numpoints = segments + 1,
  19900. u, v, r,
  19901. cx, cy,
  19902. pos, pos2 = new THREE.Vector3(),
  19903. i, j,
  19904. ip, jp,
  19905. a, b, c, d,
  19906. uva, uvb, uvc, uvd;
  19907. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  19908. tangents = frames.tangents,
  19909. normals = frames.normals,
  19910. binormals = frames.binormals;
  19911. // proxy internals
  19912. this.tangents = tangents;
  19913. this.normals = normals;
  19914. this.binormals = binormals;
  19915. function vert( x, y, z ) {
  19916. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  19917. }
  19918. // construct the grid
  19919. for ( i = 0; i < numpoints; i ++ ) {
  19920. grid[ i ] = [];
  19921. u = i / ( numpoints - 1 );
  19922. pos = path.getPointAt( u );
  19923. tangent = tangents[ i ];
  19924. normal = normals[ i ];
  19925. binormal = binormals[ i ];
  19926. r = radius * taper( u );
  19927. for ( j = 0; j < radialSegments; j ++ ) {
  19928. v = j / radialSegments * 2 * Math.PI;
  19929. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19930. cy = r * Math.sin( v );
  19931. pos2.copy( pos );
  19932. pos2.x += cx * normal.x + cy * binormal.x;
  19933. pos2.y += cx * normal.y + cy * binormal.y;
  19934. pos2.z += cx * normal.z + cy * binormal.z;
  19935. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  19936. }
  19937. }
  19938. // construct the mesh
  19939. for ( i = 0; i < segments; i ++ ) {
  19940. for ( j = 0; j < radialSegments; j ++ ) {
  19941. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  19942. jp = ( j + 1 ) % radialSegments;
  19943. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  19944. b = grid[ ip ][ j ];
  19945. c = grid[ ip ][ jp ];
  19946. d = grid[ i ][ jp ];
  19947. uva = new THREE.Vector2( i / segments, j / radialSegments );
  19948. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  19949. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  19950. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  19951. this.faces.push( new THREE.Face3( a, b, d ) );
  19952. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19953. this.faces.push( new THREE.Face3( b, c, d ) );
  19954. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19955. }
  19956. }
  19957. this.computeFaceNormals();
  19958. this.computeVertexNormals();
  19959. };
  19960. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19961. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  19962. THREE.TubeGeometry.NoTaper = function ( u ) {
  19963. return 1;
  19964. };
  19965. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  19966. return Math.sin( Math.PI * u );
  19967. };
  19968. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  19969. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  19970. var normal = new THREE.Vector3(),
  19971. tangents = [],
  19972. normals = [],
  19973. binormals = [],
  19974. vec = new THREE.Vector3(),
  19975. mat = new THREE.Matrix4(),
  19976. numpoints = segments + 1,
  19977. theta,
  19978. epsilon = 0.0001,
  19979. smallest,
  19980. tx, ty, tz,
  19981. i, u;
  19982. // expose internals
  19983. this.tangents = tangents;
  19984. this.normals = normals;
  19985. this.binormals = binormals;
  19986. // compute the tangent vectors for each segment on the path
  19987. for ( i = 0; i < numpoints; i ++ ) {
  19988. u = i / ( numpoints - 1 );
  19989. tangents[ i ] = path.getTangentAt( u );
  19990. tangents[ i ].normalize();
  19991. }
  19992. initialNormal3();
  19993. /*
  19994. function initialNormal1(lastBinormal) {
  19995. // fixed start binormal. Has dangers of 0 vectors
  19996. normals[ 0 ] = new THREE.Vector3();
  19997. binormals[ 0 ] = new THREE.Vector3();
  19998. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  19999. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  20000. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20001. }
  20002. function initialNormal2() {
  20003. // This uses the Frenet-Serret formula for deriving binormal
  20004. var t2 = path.getTangentAt( epsilon );
  20005. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  20006. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  20007. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  20008. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20009. }
  20010. */
  20011. function initialNormal3() {
  20012. // select an initial normal vector perpendicular to the first tangent vector,
  20013. // and in the direction of the smallest tangent xyz component
  20014. normals[ 0 ] = new THREE.Vector3();
  20015. binormals[ 0 ] = new THREE.Vector3();
  20016. smallest = Number.MAX_VALUE;
  20017. tx = Math.abs( tangents[ 0 ].x );
  20018. ty = Math.abs( tangents[ 0 ].y );
  20019. tz = Math.abs( tangents[ 0 ].z );
  20020. if ( tx <= smallest ) {
  20021. smallest = tx;
  20022. normal.set( 1, 0, 0 );
  20023. }
  20024. if ( ty <= smallest ) {
  20025. smallest = ty;
  20026. normal.set( 0, 1, 0 );
  20027. }
  20028. if ( tz <= smallest ) {
  20029. normal.set( 0, 0, 1 );
  20030. }
  20031. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20032. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20033. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20034. }
  20035. // compute the slowly-varying normal and binormal vectors for each segment on the path
  20036. for ( i = 1; i < numpoints; i ++ ) {
  20037. normals[ i ] = normals[ i - 1 ].clone();
  20038. binormals[ i ] = binormals[ i - 1 ].clone();
  20039. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20040. if ( vec.length() > epsilon ) {
  20041. vec.normalize();
  20042. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20043. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20044. }
  20045. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20046. }
  20047. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20048. if ( closed ) {
  20049. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  20050. theta /= ( numpoints - 1 );
  20051. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  20052. theta = - theta;
  20053. }
  20054. for ( i = 1; i < numpoints; i ++ ) {
  20055. // twist a little...
  20056. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  20057. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20058. }
  20059. }
  20060. };
  20061. // File:src/extras/geometries/PolyhedronGeometry.js
  20062. /**
  20063. * @author clockworkgeek / https://github.com/clockworkgeek
  20064. * @author timothypratley / https://github.com/timothypratley
  20065. * @author WestLangley / http://github.com/WestLangley
  20066. */
  20067. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  20068. THREE.Geometry.call( this );
  20069. this.type = 'PolyhedronGeometry';
  20070. this.parameters = {
  20071. vertices: vertices,
  20072. indices: indices,
  20073. radius: radius,
  20074. detail: detail
  20075. };
  20076. radius = radius || 1;
  20077. detail = detail || 0;
  20078. var that = this;
  20079. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  20080. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  20081. }
  20082. var p = this.vertices;
  20083. var faces = [];
  20084. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  20085. var v1 = p[ indices[ i ] ];
  20086. var v2 = p[ indices[ i + 1 ] ];
  20087. var v3 = p[ indices[ i + 2 ] ];
  20088. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  20089. }
  20090. var centroid = new THREE.Vector3();
  20091. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20092. subdivide( faces[ i ], detail );
  20093. }
  20094. // Handle case when face straddles the seam
  20095. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  20096. var uvs = this.faceVertexUvs[ 0 ][ i ];
  20097. var x0 = uvs[ 0 ].x;
  20098. var x1 = uvs[ 1 ].x;
  20099. var x2 = uvs[ 2 ].x;
  20100. var max = Math.max( x0, Math.max( x1, x2 ) );
  20101. var min = Math.min( x0, Math.min( x1, x2 ) );
  20102. if ( max > 0.9 && min < 0.1 ) {
  20103. // 0.9 is somewhat arbitrary
  20104. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  20105. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  20106. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  20107. }
  20108. }
  20109. // Apply radius
  20110. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  20111. this.vertices[ i ].multiplyScalar( radius );
  20112. }
  20113. // Merge vertices
  20114. this.mergeVertices();
  20115. this.computeFaceNormals();
  20116. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20117. // Project vector onto sphere's surface
  20118. function prepare( vector ) {
  20119. var vertex = vector.normalize().clone();
  20120. vertex.index = that.vertices.push( vertex ) - 1;
  20121. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  20122. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  20123. var v = inclination( vector ) / Math.PI + 0.5;
  20124. vertex.uv = new THREE.Vector2( u, 1 - v );
  20125. return vertex;
  20126. }
  20127. // Approximate a curved face with recursively sub-divided triangles.
  20128. function make( v1, v2, v3 ) {
  20129. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  20130. that.faces.push( face );
  20131. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  20132. var azi = azimuth( centroid );
  20133. that.faceVertexUvs[ 0 ].push( [
  20134. correctUV( v1.uv, v1, azi ),
  20135. correctUV( v2.uv, v2, azi ),
  20136. correctUV( v3.uv, v3, azi )
  20137. ] );
  20138. }
  20139. // Analytically subdivide a face to the required detail level.
  20140. function subdivide( face, detail ) {
  20141. var cols = Math.pow( 2, detail );
  20142. var a = prepare( that.vertices[ face.a ] );
  20143. var b = prepare( that.vertices[ face.b ] );
  20144. var c = prepare( that.vertices[ face.c ] );
  20145. var v = [];
  20146. // Construct all of the vertices for this subdivision.
  20147. for ( var i = 0 ; i <= cols; i ++ ) {
  20148. v[ i ] = [];
  20149. var aj = prepare( a.clone().lerp( c, i / cols ) );
  20150. var bj = prepare( b.clone().lerp( c, i / cols ) );
  20151. var rows = cols - i;
  20152. for ( var j = 0; j <= rows; j ++ ) {
  20153. if ( j === 0 && i === cols ) {
  20154. v[ i ][ j ] = aj;
  20155. } else {
  20156. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  20157. }
  20158. }
  20159. }
  20160. // Construct all of the faces.
  20161. for ( var i = 0; i < cols ; i ++ ) {
  20162. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  20163. var k = Math.floor( j / 2 );
  20164. if ( j % 2 === 0 ) {
  20165. make(
  20166. v[ i ][ k + 1 ],
  20167. v[ i + 1 ][ k ],
  20168. v[ i ][ k ]
  20169. );
  20170. } else {
  20171. make(
  20172. v[ i ][ k + 1 ],
  20173. v[ i + 1 ][ k + 1 ],
  20174. v[ i + 1 ][ k ]
  20175. );
  20176. }
  20177. }
  20178. }
  20179. }
  20180. // Angle around the Y axis, counter-clockwise when looking from above.
  20181. function azimuth( vector ) {
  20182. return Math.atan2( vector.z, - vector.x );
  20183. }
  20184. // Angle above the XZ plane.
  20185. function inclination( vector ) {
  20186. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  20187. }
  20188. // Texture fixing helper. Spheres have some odd behaviours.
  20189. function correctUV( uv, vector, azimuth ) {
  20190. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  20191. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  20192. return uv.clone();
  20193. }
  20194. };
  20195. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20196. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  20197. THREE.PolyhedronGeometry.prototype.clone = function () {
  20198. var geometry = new THREE.PolyhedronGeometry(
  20199. this.parameters.vertices,
  20200. this.parameters.indices,
  20201. this.parameters.radius,
  20202. this.parameters.detail
  20203. );
  20204. return geometry.copy( this );
  20205. };
  20206. THREE.PolyhedronGeometry.prototype.copy = function ( source ) {
  20207. THREE.Geometry.prototype.copy.call( this, source );
  20208. return this;
  20209. };
  20210. // File:src/extras/geometries/DodecahedronGeometry.js
  20211. /**
  20212. * @author Abe Pazos / https://hamoid.com
  20213. */
  20214. THREE.DodecahedronGeometry = function ( radius, detail ) {
  20215. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20216. var r = 1 / t;
  20217. var vertices = [
  20218. // (±1, ±1, ±1)
  20219. - 1, - 1, - 1, - 1, - 1, 1,
  20220. - 1, 1, - 1, - 1, 1, 1,
  20221. 1, - 1, - 1, 1, - 1, 1,
  20222. 1, 1, - 1, 1, 1, 1,
  20223. // (0, ±1/φ, ±φ)
  20224. 0, - r, - t, 0, - r, t,
  20225. 0, r, - t, 0, r, t,
  20226. // (±1/φ, ±φ, 0)
  20227. - r, - t, 0, - r, t, 0,
  20228. r, - t, 0, r, t, 0,
  20229. // (±φ, 0, ±1/φ)
  20230. - t, 0, - r, t, 0, - r,
  20231. - t, 0, r, t, 0, r
  20232. ];
  20233. var indices = [
  20234. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  20235. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  20236. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  20237. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  20238. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  20239. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  20240. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  20241. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  20242. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  20243. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  20244. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  20245. 1, 12, 14, 1, 14, 5, 1, 5, 9
  20246. ];
  20247. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20248. this.type = 'DodecahedronGeometry';
  20249. this.parameters = {
  20250. radius: radius,
  20251. detail: detail
  20252. };
  20253. };
  20254. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20255. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  20256. THREE.DodecahedronGeometry.prototype.clone = function () {
  20257. var geometry = new THREE.DodecahedronGeometry(
  20258. this.parameters.radius,
  20259. this.parameters.detail
  20260. );
  20261. geometry.copy( this );
  20262. return geometry;
  20263. };
  20264. // File:src/extras/geometries/IcosahedronGeometry.js
  20265. /**
  20266. * @author timothypratley / https://github.com/timothypratley
  20267. */
  20268. THREE.IcosahedronGeometry = function ( radius, detail ) {
  20269. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20270. var vertices = [
  20271. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  20272. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  20273. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  20274. ];
  20275. var indices = [
  20276. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  20277. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  20278. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  20279. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  20280. ];
  20281. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20282. this.type = 'IcosahedronGeometry';
  20283. this.parameters = {
  20284. radius: radius,
  20285. detail: detail
  20286. };
  20287. };
  20288. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20289. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  20290. THREE.IcosahedronGeometry.prototype.clone = function () {
  20291. var geometry = new THREE.IcosahedronGeometry(
  20292. this.parameters.radius,
  20293. this.parameters.detail
  20294. );
  20295. geometry.copy( this );
  20296. return geometry;
  20297. };
  20298. // File:src/extras/geometries/OctahedronGeometry.js
  20299. /**
  20300. * @author timothypratley / https://github.com/timothypratley
  20301. */
  20302. THREE.OctahedronGeometry = function ( radius, detail ) {
  20303. var vertices = [
  20304. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  20305. ];
  20306. var indices = [
  20307. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  20308. ];
  20309. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20310. this.type = 'OctahedronGeometry';
  20311. this.parameters = {
  20312. radius: radius,
  20313. detail: detail
  20314. };
  20315. };
  20316. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20317. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  20318. THREE.OctahedronGeometry.prototype.clone = function () {
  20319. var geometry = new THREE.OctahedronGeometry(
  20320. this.parameters.radius,
  20321. this.parameters.detail
  20322. );
  20323. geometry.copy( this );
  20324. return geometry;
  20325. };
  20326. // File:src/extras/geometries/TetrahedronGeometry.js
  20327. /**
  20328. * @author timothypratley / https://github.com/timothypratley
  20329. */
  20330. THREE.TetrahedronGeometry = function ( radius, detail ) {
  20331. var vertices = [
  20332. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20333. ];
  20334. var indices = [
  20335. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20336. ];
  20337. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20338. this.type = 'TetrahedronGeometry';
  20339. this.parameters = {
  20340. radius: radius,
  20341. detail: detail
  20342. };
  20343. };
  20344. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20345. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  20346. THREE.TetrahedronGeometry.prototype.clone = function () {
  20347. var geometry = new THREE.TetrahedronGeometry(
  20348. this.parameters.radius,
  20349. this.parameters.detail
  20350. );
  20351. geometry.copy( this );
  20352. return geometry;
  20353. };
  20354. // File:src/extras/geometries/ParametricGeometry.js
  20355. /**
  20356. * @author zz85 / https://github.com/zz85
  20357. * Parametric Surfaces Geometry
  20358. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  20359. *
  20360. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  20361. *
  20362. */
  20363. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  20364. THREE.Geometry.call( this );
  20365. this.type = 'ParametricGeometry';
  20366. this.parameters = {
  20367. func: func,
  20368. slices: slices,
  20369. stacks: stacks
  20370. };
  20371. var verts = this.vertices;
  20372. var faces = this.faces;
  20373. var uvs = this.faceVertexUvs[ 0 ];
  20374. var i, j, p;
  20375. var u, v;
  20376. var sliceCount = slices + 1;
  20377. for ( i = 0; i <= stacks; i ++ ) {
  20378. v = i / stacks;
  20379. for ( j = 0; j <= slices; j ++ ) {
  20380. u = j / slices;
  20381. p = func( u, v );
  20382. verts.push( p );
  20383. }
  20384. }
  20385. var a, b, c, d;
  20386. var uva, uvb, uvc, uvd;
  20387. for ( i = 0; i < stacks; i ++ ) {
  20388. for ( j = 0; j < slices; j ++ ) {
  20389. a = i * sliceCount + j;
  20390. b = i * sliceCount + j + 1;
  20391. c = ( i + 1 ) * sliceCount + j + 1;
  20392. d = ( i + 1 ) * sliceCount + j;
  20393. uva = new THREE.Vector2( j / slices, i / stacks );
  20394. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  20395. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  20396. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  20397. faces.push( new THREE.Face3( a, b, d ) );
  20398. uvs.push( [ uva, uvb, uvd ] );
  20399. faces.push( new THREE.Face3( b, c, d ) );
  20400. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  20401. }
  20402. }
  20403. // console.log(this);
  20404. // magic bullet
  20405. // var diff = this.mergeVertices();
  20406. // console.log('removed ', diff, ' vertices by merging');
  20407. this.computeFaceNormals();
  20408. this.computeVertexNormals();
  20409. };
  20410. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20411. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  20412. // File:src/extras/geometries/WireframeGeometry.js
  20413. /**
  20414. * @author mrdoob / http://mrdoob.com/
  20415. */
  20416. THREE.WireframeGeometry = function ( geometry ) {
  20417. THREE.BufferGeometry.call( this );
  20418. var edge = [ 0, 0 ], hash = {};
  20419. var sortFunction = function ( a, b ) {
  20420. return a - b;
  20421. };
  20422. var keys = [ 'a', 'b', 'c' ];
  20423. if ( geometry instanceof THREE.Geometry ) {
  20424. var vertices = geometry.vertices;
  20425. var faces = geometry.faces;
  20426. var numEdges = 0;
  20427. // allocate maximal size
  20428. var edges = new Uint32Array( 6 * faces.length );
  20429. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20430. var face = faces[ i ];
  20431. for ( var j = 0; j < 3; j ++ ) {
  20432. edge[ 0 ] = face[ keys[ j ] ];
  20433. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  20434. edge.sort( sortFunction );
  20435. var key = edge.toString();
  20436. if ( hash[ key ] === undefined ) {
  20437. edges[ 2 * numEdges ] = edge[ 0 ];
  20438. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20439. hash[ key ] = true;
  20440. numEdges ++;
  20441. }
  20442. }
  20443. }
  20444. var coords = new Float32Array( numEdges * 2 * 3 );
  20445. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20446. for ( var j = 0; j < 2; j ++ ) {
  20447. var vertex = vertices[ edges [ 2 * i + j ] ];
  20448. var index = 6 * i + 3 * j;
  20449. coords[ index + 0 ] = vertex.x;
  20450. coords[ index + 1 ] = vertex.y;
  20451. coords[ index + 2 ] = vertex.z;
  20452. }
  20453. }
  20454. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20455. } else if ( geometry instanceof THREE.BufferGeometry ) {
  20456. if ( geometry.attributes.index !== undefined ) {
  20457. // Indexed BufferGeometry
  20458. var vertices = geometry.attributes.position;
  20459. var indices = geometry.attributes.index.array;
  20460. var drawcalls = geometry.drawcalls;
  20461. var numEdges = 0;
  20462. if ( drawcalls.length === 0 ) {
  20463. drawcalls = [ { count : indices.length, index : 0, start : 0 } ];
  20464. }
  20465. // allocate maximal size
  20466. var edges = new Uint32Array( 2 * indices.length );
  20467. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  20468. var start = drawcalls[ o ].start;
  20469. var count = drawcalls[ o ].count;
  20470. var index = drawcalls[ o ].index;
  20471. for ( var i = start, il = start + count; i < il; i += 3 ) {
  20472. for ( var j = 0; j < 3; j ++ ) {
  20473. edge[ 0 ] = index + indices[ i + j ];
  20474. edge[ 1 ] = index + indices[ i + ( j + 1 ) % 3 ];
  20475. edge.sort( sortFunction );
  20476. var key = edge.toString();
  20477. if ( hash[ key ] === undefined ) {
  20478. edges[ 2 * numEdges ] = edge[ 0 ];
  20479. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20480. hash[ key ] = true;
  20481. numEdges ++;
  20482. }
  20483. }
  20484. }
  20485. }
  20486. var coords = new Float32Array( numEdges * 2 * 3 );
  20487. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20488. for ( var j = 0; j < 2; j ++ ) {
  20489. var index = 6 * i + 3 * j;
  20490. var index2 = edges[ 2 * i + j ];
  20491. coords[ index + 0 ] = vertices.getX( index2 );
  20492. coords[ index + 1 ] = vertices.getY( index2 );
  20493. coords[ index + 2 ] = vertices.getZ( index2 );
  20494. }
  20495. }
  20496. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20497. } else {
  20498. // non-indexed BufferGeometry
  20499. var vertices = geometry.attributes.position.array;
  20500. var numEdges = vertices.length / 3;
  20501. var numTris = numEdges / 3;
  20502. var coords = new Float32Array( numEdges * 2 * 3 );
  20503. for ( var i = 0, l = numTris; i < l; i ++ ) {
  20504. for ( var j = 0; j < 3; j ++ ) {
  20505. var index = 18 * i + 6 * j;
  20506. var index1 = 9 * i + 3 * j;
  20507. coords[ index + 0 ] = vertices[ index1 ];
  20508. coords[ index + 1 ] = vertices[ index1 + 1 ];
  20509. coords[ index + 2 ] = vertices[ index1 + 2 ];
  20510. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  20511. coords[ index + 3 ] = vertices[ index2 ];
  20512. coords[ index + 4 ] = vertices[ index2 + 1 ];
  20513. coords[ index + 5 ] = vertices[ index2 + 2 ];
  20514. }
  20515. }
  20516. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20517. }
  20518. }
  20519. };
  20520. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20521. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  20522. // File:src/extras/helpers/AxisHelper.js
  20523. /**
  20524. * @author sroucheray / http://sroucheray.org/
  20525. * @author mrdoob / http://mrdoob.com/
  20526. */
  20527. THREE.AxisHelper = function ( size ) {
  20528. size = size || 1;
  20529. var vertices = new Float32Array( [
  20530. 0, 0, 0, size, 0, 0,
  20531. 0, 0, 0, 0, size, 0,
  20532. 0, 0, 0, 0, 0, size
  20533. ] );
  20534. var colors = new Float32Array( [
  20535. 1, 0, 0, 1, 0.6, 0,
  20536. 0, 1, 0, 0.6, 1, 0,
  20537. 0, 0, 1, 0, 0.6, 1
  20538. ] );
  20539. var geometry = new THREE.BufferGeometry();
  20540. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  20541. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  20542. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20543. THREE.LineSegments.call( this, geometry, material );
  20544. };
  20545. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20546. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  20547. // File:src/extras/helpers/ArrowHelper.js
  20548. /**
  20549. * @author WestLangley / http://github.com/WestLangley
  20550. * @author zz85 / http://github.com/zz85
  20551. * @author bhouston / http://exocortex.com
  20552. *
  20553. * Creates an arrow for visualizing directions
  20554. *
  20555. * Parameters:
  20556. * dir - Vector3
  20557. * origin - Vector3
  20558. * length - Number
  20559. * color - color in hex value
  20560. * headLength - Number
  20561. * headWidth - Number
  20562. */
  20563. THREE.ArrowHelper = ( function () {
  20564. var lineGeometry = new THREE.Geometry();
  20565. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  20566. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  20567. coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  20568. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  20569. // dir is assumed to be normalized
  20570. THREE.Object3D.call( this );
  20571. if ( color === undefined ) color = 0xffff00;
  20572. if ( length === undefined ) length = 1;
  20573. if ( headLength === undefined ) headLength = 0.2 * length;
  20574. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20575. this.position.copy( origin );
  20576. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  20577. this.line.matrixAutoUpdate = false;
  20578. this.add( this.line );
  20579. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  20580. this.cone.matrixAutoUpdate = false;
  20581. this.add( this.cone );
  20582. this.setDirection( dir );
  20583. this.setLength( length, headLength, headWidth );
  20584. }
  20585. }() );
  20586. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  20587. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  20588. THREE.ArrowHelper.prototype.setDirection = ( function () {
  20589. var axis = new THREE.Vector3();
  20590. var radians;
  20591. return function setDirection( dir ) {
  20592. // dir is assumed to be normalized
  20593. if ( dir.y > 0.99999 ) {
  20594. this.quaternion.set( 0, 0, 0, 1 );
  20595. } else if ( dir.y < - 0.99999 ) {
  20596. this.quaternion.set( 1, 0, 0, 0 );
  20597. } else {
  20598. axis.set( dir.z, 0, - dir.x ).normalize();
  20599. radians = Math.acos( dir.y );
  20600. this.quaternion.setFromAxisAngle( axis, radians );
  20601. }
  20602. };
  20603. }() );
  20604. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  20605. if ( headLength === undefined ) headLength = 0.2 * length;
  20606. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20607. this.line.scale.set( 1, length - headLength, 1 );
  20608. this.line.updateMatrix();
  20609. this.cone.scale.set( headWidth, headLength, headWidth );
  20610. this.cone.position.y = length;
  20611. this.cone.updateMatrix();
  20612. };
  20613. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  20614. this.line.material.color.set( color );
  20615. this.cone.material.color.set( color );
  20616. };
  20617. // File:src/extras/helpers/BoxHelper.js
  20618. /**
  20619. * @author mrdoob / http://mrdoob.com/
  20620. */
  20621. THREE.BoxHelper = function ( object ) {
  20622. var geometry = new THREE.BufferGeometry();
  20623. geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( 72 ), 3 ) );
  20624. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  20625. if ( object !== undefined ) {
  20626. this.update( object );
  20627. }
  20628. };
  20629. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20630. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  20631. THREE.BoxHelper.prototype.update = ( function () {
  20632. var box = new THREE.Box3();
  20633. return function ( object ) {
  20634. box.setFromObject( object );
  20635. if ( box.empty() ) return;
  20636. var min = box.min;
  20637. var max = box.max;
  20638. /*
  20639. 5____4
  20640. 1/___0/|
  20641. | 6__|_7
  20642. 2/___3/
  20643. 0: max.x, max.y, max.z
  20644. 1: min.x, max.y, max.z
  20645. 2: min.x, min.y, max.z
  20646. 3: max.x, min.y, max.z
  20647. 4: max.x, max.y, min.z
  20648. 5: min.x, max.y, min.z
  20649. 6: min.x, min.y, min.z
  20650. 7: max.x, min.y, min.z
  20651. */
  20652. var vertices = this.geometry.attributes.position.array;
  20653. vertices[ 0 ] = max.x; vertices[ 1 ] = max.y; vertices[ 2 ] = max.z;
  20654. vertices[ 3 ] = min.x; vertices[ 4 ] = max.y; vertices[ 5 ] = max.z;
  20655. vertices[ 6 ] = min.x; vertices[ 7 ] = max.y; vertices[ 8 ] = max.z;
  20656. vertices[ 9 ] = min.x; vertices[ 10 ] = min.y; vertices[ 11 ] = max.z;
  20657. vertices[ 12 ] = min.x; vertices[ 13 ] = min.y; vertices[ 14 ] = max.z;
  20658. vertices[ 15 ] = max.x; vertices[ 16 ] = min.y; vertices[ 17 ] = max.z;
  20659. vertices[ 18 ] = max.x; vertices[ 19 ] = min.y; vertices[ 20 ] = max.z;
  20660. vertices[ 21 ] = max.x; vertices[ 22 ] = max.y; vertices[ 23 ] = max.z;
  20661. //
  20662. vertices[ 24 ] = max.x; vertices[ 25 ] = max.y; vertices[ 26 ] = min.z;
  20663. vertices[ 27 ] = min.x; vertices[ 28 ] = max.y; vertices[ 29 ] = min.z;
  20664. vertices[ 30 ] = min.x; vertices[ 31 ] = max.y; vertices[ 32 ] = min.z;
  20665. vertices[ 33 ] = min.x; vertices[ 34 ] = min.y; vertices[ 35 ] = min.z;
  20666. vertices[ 36 ] = min.x; vertices[ 37 ] = min.y; vertices[ 38 ] = min.z;
  20667. vertices[ 39 ] = max.x; vertices[ 40 ] = min.y; vertices[ 41 ] = min.z;
  20668. vertices[ 42 ] = max.x; vertices[ 43 ] = min.y; vertices[ 44 ] = min.z;
  20669. vertices[ 45 ] = max.x; vertices[ 46 ] = max.y; vertices[ 47 ] = min.z;
  20670. //
  20671. vertices[ 48 ] = max.x; vertices[ 49 ] = max.y; vertices[ 50 ] = max.z;
  20672. vertices[ 51 ] = max.x; vertices[ 52 ] = max.y; vertices[ 53 ] = min.z;
  20673. vertices[ 54 ] = min.x; vertices[ 55 ] = max.y; vertices[ 56 ] = max.z;
  20674. vertices[ 57 ] = min.x; vertices[ 58 ] = max.y; vertices[ 59 ] = min.z;
  20675. vertices[ 60 ] = min.x; vertices[ 61 ] = min.y; vertices[ 62 ] = max.z;
  20676. vertices[ 63 ] = min.x; vertices[ 64 ] = min.y; vertices[ 65 ] = min.z;
  20677. vertices[ 66 ] = max.x; vertices[ 67 ] = min.y; vertices[ 68 ] = max.z;
  20678. vertices[ 69 ] = max.x; vertices[ 70 ] = min.y; vertices[ 71 ] = min.z;
  20679. this.geometry.attributes.position.needsUpdate = true;
  20680. this.geometry.computeBoundingSphere();
  20681. }
  20682. } )();
  20683. // File:src/extras/helpers/BoundingBoxHelper.js
  20684. /**
  20685. * @author WestLangley / http://github.com/WestLangley
  20686. */
  20687. // a helper to show the world-axis-aligned bounding box for an object
  20688. THREE.BoundingBoxHelper = function ( object, hex ) {
  20689. var color = ( hex !== undefined ) ? hex : 0x888888;
  20690. this.object = object;
  20691. this.box = new THREE.Box3();
  20692. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  20693. };
  20694. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  20695. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  20696. THREE.BoundingBoxHelper.prototype.update = function () {
  20697. this.box.setFromObject( this.object );
  20698. this.box.size( this.scale );
  20699. this.box.center( this.position );
  20700. };
  20701. // File:src/extras/helpers/CameraHelper.js
  20702. /**
  20703. * @author alteredq / http://alteredqualia.com/
  20704. *
  20705. * - shows frustum, line of sight and up of the camera
  20706. * - suitable for fast updates
  20707. * - based on frustum visualization in lightgl.js shadowmap example
  20708. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  20709. */
  20710. THREE.CameraHelper = function ( camera ) {
  20711. var geometry = new THREE.Geometry();
  20712. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  20713. var pointMap = {};
  20714. // colors
  20715. var hexFrustum = 0xffaa00;
  20716. var hexCone = 0xff0000;
  20717. var hexUp = 0x00aaff;
  20718. var hexTarget = 0xffffff;
  20719. var hexCross = 0x333333;
  20720. // near
  20721. addLine( "n1", "n2", hexFrustum );
  20722. addLine( "n2", "n4", hexFrustum );
  20723. addLine( "n4", "n3", hexFrustum );
  20724. addLine( "n3", "n1", hexFrustum );
  20725. // far
  20726. addLine( "f1", "f2", hexFrustum );
  20727. addLine( "f2", "f4", hexFrustum );
  20728. addLine( "f4", "f3", hexFrustum );
  20729. addLine( "f3", "f1", hexFrustum );
  20730. // sides
  20731. addLine( "n1", "f1", hexFrustum );
  20732. addLine( "n2", "f2", hexFrustum );
  20733. addLine( "n3", "f3", hexFrustum );
  20734. addLine( "n4", "f4", hexFrustum );
  20735. // cone
  20736. addLine( "p", "n1", hexCone );
  20737. addLine( "p", "n2", hexCone );
  20738. addLine( "p", "n3", hexCone );
  20739. addLine( "p", "n4", hexCone );
  20740. // up
  20741. addLine( "u1", "u2", hexUp );
  20742. addLine( "u2", "u3", hexUp );
  20743. addLine( "u3", "u1", hexUp );
  20744. // target
  20745. addLine( "c", "t", hexTarget );
  20746. addLine( "p", "c", hexCross );
  20747. // cross
  20748. addLine( "cn1", "cn2", hexCross );
  20749. addLine( "cn3", "cn4", hexCross );
  20750. addLine( "cf1", "cf2", hexCross );
  20751. addLine( "cf3", "cf4", hexCross );
  20752. function addLine( a, b, hex ) {
  20753. addPoint( a, hex );
  20754. addPoint( b, hex );
  20755. }
  20756. function addPoint( id, hex ) {
  20757. geometry.vertices.push( new THREE.Vector3() );
  20758. geometry.colors.push( new THREE.Color( hex ) );
  20759. if ( pointMap[ id ] === undefined ) {
  20760. pointMap[ id ] = [];
  20761. }
  20762. pointMap[ id ].push( geometry.vertices.length - 1 );
  20763. }
  20764. THREE.LineSegments.call( this, geometry, material );
  20765. this.camera = camera;
  20766. this.matrix = camera.matrixWorld;
  20767. this.matrixAutoUpdate = false;
  20768. this.pointMap = pointMap;
  20769. this.update();
  20770. };
  20771. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20772. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  20773. THREE.CameraHelper.prototype.update = function () {
  20774. var geometry, pointMap;
  20775. var vector = new THREE.Vector3();
  20776. var camera = new THREE.Camera();
  20777. var setPoint = function ( point, x, y, z ) {
  20778. vector.set( x, y, z ).unproject( camera );
  20779. var points = pointMap[ point ];
  20780. if ( points !== undefined ) {
  20781. for ( var i = 0, il = points.length; i < il; i ++ ) {
  20782. geometry.vertices[ points[ i ] ].copy( vector );
  20783. }
  20784. }
  20785. };
  20786. return function () {
  20787. geometry = this.geometry;
  20788. pointMap = this.pointMap;
  20789. var w = 1, h = 1;
  20790. // we need just camera projection matrix
  20791. // world matrix must be identity
  20792. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  20793. // center / target
  20794. setPoint( "c", 0, 0, - 1 );
  20795. setPoint( "t", 0, 0, 1 );
  20796. // near
  20797. setPoint( "n1", - w, - h, - 1 );
  20798. setPoint( "n2", w, - h, - 1 );
  20799. setPoint( "n3", - w, h, - 1 );
  20800. setPoint( "n4", w, h, - 1 );
  20801. // far
  20802. setPoint( "f1", - w, - h, 1 );
  20803. setPoint( "f2", w, - h, 1 );
  20804. setPoint( "f3", - w, h, 1 );
  20805. setPoint( "f4", w, h, 1 );
  20806. // up
  20807. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  20808. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  20809. setPoint( "u3", 0, h * 2, - 1 );
  20810. // cross
  20811. setPoint( "cf1", - w, 0, 1 );
  20812. setPoint( "cf2", w, 0, 1 );
  20813. setPoint( "cf3", 0, - h, 1 );
  20814. setPoint( "cf4", 0, h, 1 );
  20815. setPoint( "cn1", - w, 0, - 1 );
  20816. setPoint( "cn2", w, 0, - 1 );
  20817. setPoint( "cn3", 0, - h, - 1 );
  20818. setPoint( "cn4", 0, h, - 1 );
  20819. geometry.verticesNeedUpdate = true;
  20820. };
  20821. }();
  20822. // File:src/extras/helpers/DirectionalLightHelper.js
  20823. /**
  20824. * @author alteredq / http://alteredqualia.com/
  20825. * @author mrdoob / http://mrdoob.com/
  20826. * @author WestLangley / http://github.com/WestLangley
  20827. */
  20828. THREE.DirectionalLightHelper = function ( light, size ) {
  20829. THREE.Object3D.call( this );
  20830. this.light = light;
  20831. this.light.updateMatrixWorld();
  20832. this.matrix = light.matrixWorld;
  20833. this.matrixAutoUpdate = false;
  20834. size = size || 1;
  20835. var geometry = new THREE.Geometry();
  20836. geometry.vertices.push(
  20837. new THREE.Vector3( - size, size, 0 ),
  20838. new THREE.Vector3( size, size, 0 ),
  20839. new THREE.Vector3( size, - size, 0 ),
  20840. new THREE.Vector3( - size, - size, 0 ),
  20841. new THREE.Vector3( - size, size, 0 )
  20842. );
  20843. var material = new THREE.LineBasicMaterial( { fog: false } );
  20844. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20845. this.lightPlane = new THREE.Line( geometry, material );
  20846. this.add( this.lightPlane );
  20847. geometry = new THREE.Geometry();
  20848. geometry.vertices.push(
  20849. new THREE.Vector3(),
  20850. new THREE.Vector3()
  20851. );
  20852. material = new THREE.LineBasicMaterial( { fog: false } );
  20853. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20854. this.targetLine = new THREE.Line( geometry, material );
  20855. this.add( this.targetLine );
  20856. this.update();
  20857. };
  20858. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20859. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  20860. THREE.DirectionalLightHelper.prototype.dispose = function () {
  20861. this.lightPlane.geometry.dispose();
  20862. this.lightPlane.material.dispose();
  20863. this.targetLine.geometry.dispose();
  20864. this.targetLine.material.dispose();
  20865. };
  20866. THREE.DirectionalLightHelper.prototype.update = function () {
  20867. var v1 = new THREE.Vector3();
  20868. var v2 = new THREE.Vector3();
  20869. var v3 = new THREE.Vector3();
  20870. return function () {
  20871. v1.setFromMatrixPosition( this.light.matrixWorld );
  20872. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  20873. v3.subVectors( v2, v1 );
  20874. this.lightPlane.lookAt( v3 );
  20875. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20876. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  20877. this.targetLine.geometry.verticesNeedUpdate = true;
  20878. this.targetLine.material.color.copy( this.lightPlane.material.color );
  20879. };
  20880. }();
  20881. // File:src/extras/helpers/EdgesHelper.js
  20882. /**
  20883. * @author WestLangley / http://github.com/WestLangley
  20884. * @param object THREE.Mesh whose geometry will be used
  20885. * @param hex line color
  20886. * @param thresholdAngle the minimum angle (in degrees),
  20887. * between the face normals of adjacent faces,
  20888. * that is required to render an edge. A value of 10 means
  20889. * an edge is only rendered if the angle is at least 10 degrees.
  20890. */
  20891. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  20892. var color = ( hex !== undefined ) ? hex : 0xffffff;
  20893. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  20894. this.matrix = object.matrixWorld;
  20895. this.matrixAutoUpdate = false;
  20896. };
  20897. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20898. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  20899. // File:src/extras/helpers/FaceNormalsHelper.js
  20900. /**
  20901. * @author mrdoob / http://mrdoob.com/
  20902. * @author WestLangley / http://github.com/WestLangley
  20903. */
  20904. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  20905. // FaceNormalsHelper only supports THREE.Geometry
  20906. this.object = object;
  20907. this.size = ( size !== undefined ) ? size : 1;
  20908. var color = ( hex !== undefined ) ? hex : 0xffff00;
  20909. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20910. //
  20911. var nNormals = 0;
  20912. var objGeometry = this.object.geometry;
  20913. if ( objGeometry instanceof THREE.Geometry ) {
  20914. nNormals = objGeometry.faces.length;
  20915. } else {
  20916. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  20917. }
  20918. //
  20919. var geometry = new THREE.BufferGeometry();
  20920. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  20921. geometry.addAttribute( 'position', positions );
  20922. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20923. //
  20924. this.matrixAutoUpdate = false;
  20925. this.normalMatrix = new THREE.Matrix3();
  20926. this.update();
  20927. };
  20928. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20929. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  20930. THREE.FaceNormalsHelper.prototype.update = ( function () {
  20931. var v1 = new THREE.Vector3();
  20932. var v2 = new THREE.Vector3();
  20933. return function update() {
  20934. this.object.updateMatrixWorld( true );
  20935. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  20936. var matrixWorld = this.object.matrixWorld;
  20937. var position = this.geometry.attributes.position;
  20938. //
  20939. var objGeometry = this.object.geometry;
  20940. var vertices = objGeometry.vertices;
  20941. var faces = objGeometry.faces;
  20942. var idx = 0;
  20943. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20944. var face = faces[ i ];
  20945. var normal = face.normal;
  20946. v1.copy( vertices[ face.a ] )
  20947. .add( vertices[ face.b ] )
  20948. .add( vertices[ face.c ] )
  20949. .divideScalar( 3 )
  20950. .applyMatrix4( matrixWorld );
  20951. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  20952. position.setXYZ( idx, v1.x, v1.y, v1.z );
  20953. idx = idx + 1;
  20954. position.setXYZ( idx, v2.x, v2.y, v2.z );
  20955. idx = idx + 1;
  20956. }
  20957. position.needsUpdate = true;
  20958. return this;
  20959. }
  20960. }() );
  20961. // File:src/extras/helpers/GridHelper.js
  20962. /**
  20963. * @author mrdoob / http://mrdoob.com/
  20964. */
  20965. THREE.GridHelper = function ( size, step ) {
  20966. var geometry = new THREE.Geometry();
  20967. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20968. this.color1 = new THREE.Color( 0x444444 );
  20969. this.color2 = new THREE.Color( 0x888888 );
  20970. for ( var i = - size; i <= size; i += step ) {
  20971. geometry.vertices.push(
  20972. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  20973. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  20974. );
  20975. var color = i === 0 ? this.color1 : this.color2;
  20976. geometry.colors.push( color, color, color, color );
  20977. }
  20978. THREE.LineSegments.call( this, geometry, material );
  20979. };
  20980. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20981. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  20982. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  20983. this.color1.set( colorCenterLine );
  20984. this.color2.set( colorGrid );
  20985. this.geometry.colorsNeedUpdate = true;
  20986. };
  20987. // File:src/extras/helpers/HemisphereLightHelper.js
  20988. /**
  20989. * @author alteredq / http://alteredqualia.com/
  20990. * @author mrdoob / http://mrdoob.com/
  20991. */
  20992. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  20993. THREE.Object3D.call( this );
  20994. this.light = light;
  20995. this.light.updateMatrixWorld();
  20996. this.matrix = light.matrixWorld;
  20997. this.matrixAutoUpdate = false;
  20998. this.colors = [ new THREE.Color(), new THREE.Color() ];
  20999. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21000. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  21001. for ( var i = 0, il = 8; i < il; i ++ ) {
  21002. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  21003. }
  21004. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  21005. this.lightSphere = new THREE.Mesh( geometry, material );
  21006. this.add( this.lightSphere );
  21007. this.update();
  21008. };
  21009. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21010. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  21011. THREE.HemisphereLightHelper.prototype.dispose = function () {
  21012. this.lightSphere.geometry.dispose();
  21013. this.lightSphere.material.dispose();
  21014. };
  21015. THREE.HemisphereLightHelper.prototype.update = function () {
  21016. var vector = new THREE.Vector3();
  21017. return function () {
  21018. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  21019. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  21020. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  21021. this.lightSphere.geometry.colorsNeedUpdate = true;
  21022. }
  21023. }();
  21024. // File:src/extras/helpers/PointLightHelper.js
  21025. /**
  21026. * @author alteredq / http://alteredqualia.com/
  21027. * @author mrdoob / http://mrdoob.com/
  21028. */
  21029. THREE.PointLightHelper = function ( light, sphereSize ) {
  21030. this.light = light;
  21031. this.light.updateMatrixWorld();
  21032. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21033. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21034. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21035. THREE.Mesh.call( this, geometry, material );
  21036. this.matrix = this.light.matrixWorld;
  21037. this.matrixAutoUpdate = false;
  21038. /*
  21039. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  21040. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  21041. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  21042. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  21043. var d = light.distance;
  21044. if ( d === 0.0 ) {
  21045. this.lightDistance.visible = false;
  21046. } else {
  21047. this.lightDistance.scale.set( d, d, d );
  21048. }
  21049. this.add( this.lightDistance );
  21050. */
  21051. };
  21052. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  21053. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  21054. THREE.PointLightHelper.prototype.dispose = function () {
  21055. this.geometry.dispose();
  21056. this.material.dispose();
  21057. };
  21058. THREE.PointLightHelper.prototype.update = function () {
  21059. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21060. /*
  21061. var d = this.light.distance;
  21062. if ( d === 0.0 ) {
  21063. this.lightDistance.visible = false;
  21064. } else {
  21065. this.lightDistance.visible = true;
  21066. this.lightDistance.scale.set( d, d, d );
  21067. }
  21068. */
  21069. };
  21070. // File:src/extras/helpers/SkeletonHelper.js
  21071. /**
  21072. * @author Sean Griffin / http://twitter.com/sgrif
  21073. * @author Michael Guerrero / http://realitymeltdown.com
  21074. * @author mrdoob / http://mrdoob.com/
  21075. * @author ikerr / http://verold.com
  21076. */
  21077. THREE.SkeletonHelper = function ( object ) {
  21078. this.bones = this.getBoneList( object );
  21079. var geometry = new THREE.Geometry();
  21080. for ( var i = 0; i < this.bones.length; i ++ ) {
  21081. var bone = this.bones[ i ];
  21082. if ( bone.parent instanceof THREE.Bone ) {
  21083. geometry.vertices.push( new THREE.Vector3() );
  21084. geometry.vertices.push( new THREE.Vector3() );
  21085. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  21086. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  21087. }
  21088. }
  21089. geometry.dynamic = true;
  21090. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  21091. THREE.LineSegments.call( this, geometry, material );
  21092. this.root = object;
  21093. this.matrix = object.matrixWorld;
  21094. this.matrixAutoUpdate = false;
  21095. this.update();
  21096. };
  21097. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21098. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  21099. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  21100. var boneList = [];
  21101. if ( object instanceof THREE.Bone ) {
  21102. boneList.push( object );
  21103. }
  21104. for ( var i = 0; i < object.children.length; i ++ ) {
  21105. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  21106. }
  21107. return boneList;
  21108. };
  21109. THREE.SkeletonHelper.prototype.update = function () {
  21110. var geometry = this.geometry;
  21111. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  21112. var boneMatrix = new THREE.Matrix4();
  21113. var j = 0;
  21114. for ( var i = 0; i < this.bones.length; i ++ ) {
  21115. var bone = this.bones[ i ];
  21116. if ( bone.parent instanceof THREE.Bone ) {
  21117. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  21118. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  21119. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  21120. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  21121. j += 2;
  21122. }
  21123. }
  21124. geometry.verticesNeedUpdate = true;
  21125. geometry.computeBoundingSphere();
  21126. };
  21127. // File:src/extras/helpers/SpotLightHelper.js
  21128. /**
  21129. * @author alteredq / http://alteredqualia.com/
  21130. * @author mrdoob / http://mrdoob.com/
  21131. * @author WestLangley / http://github.com/WestLangley
  21132. */
  21133. THREE.SpotLightHelper = function ( light ) {
  21134. THREE.Object3D.call( this );
  21135. this.light = light;
  21136. this.light.updateMatrixWorld();
  21137. this.matrix = light.matrixWorld;
  21138. this.matrixAutoUpdate = false;
  21139. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  21140. geometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  21141. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  21142. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21143. this.cone = new THREE.Mesh( geometry, material );
  21144. this.add( this.cone );
  21145. this.update();
  21146. };
  21147. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21148. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  21149. THREE.SpotLightHelper.prototype.dispose = function () {
  21150. this.cone.geometry.dispose();
  21151. this.cone.material.dispose();
  21152. };
  21153. THREE.SpotLightHelper.prototype.update = function () {
  21154. var vector = new THREE.Vector3();
  21155. var vector2 = new THREE.Vector3();
  21156. return function () {
  21157. var coneLength = this.light.distance ? this.light.distance : 10000;
  21158. var coneWidth = coneLength * Math.tan( this.light.angle );
  21159. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  21160. vector.setFromMatrixPosition( this.light.matrixWorld );
  21161. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  21162. this.cone.lookAt( vector2.sub( vector ) );
  21163. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21164. };
  21165. }();
  21166. // File:src/extras/helpers/VertexNormalsHelper.js
  21167. /**
  21168. * @author mrdoob / http://mrdoob.com/
  21169. * @author WestLangley / http://github.com/WestLangley
  21170. */
  21171. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  21172. this.object = object;
  21173. this.size = ( size !== undefined ) ? size : 1;
  21174. var color = ( hex !== undefined ) ? hex : 0xff0000;
  21175. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21176. //
  21177. var nNormals = 0;
  21178. var objGeometry = this.object.geometry;
  21179. if ( objGeometry instanceof THREE.Geometry ) {
  21180. nNormals = objGeometry.faces.length * 3;
  21181. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21182. nNormals = objGeometry.attributes.normal.count
  21183. }
  21184. //
  21185. var geometry = new THREE.BufferGeometry();
  21186. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21187. geometry.addAttribute( 'position', positions );
  21188. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21189. //
  21190. this.matrixAutoUpdate = false;
  21191. this.normalMatrix = new THREE.Matrix3();
  21192. this.update();
  21193. };
  21194. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21195. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  21196. THREE.VertexNormalsHelper.prototype.update = ( function () {
  21197. var v1 = new THREE.Vector3();
  21198. var v2 = new THREE.Vector3();
  21199. return function update() {
  21200. var keys = [ 'a', 'b', 'c' ];
  21201. this.object.updateMatrixWorld( true );
  21202. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21203. var matrixWorld = this.object.matrixWorld;
  21204. var position = this.geometry.attributes.position;
  21205. //
  21206. var objGeometry = this.object.geometry;
  21207. if ( objGeometry instanceof THREE.Geometry ) {
  21208. var vertices = objGeometry.vertices;
  21209. var faces = objGeometry.faces;
  21210. var idx = 0;
  21211. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21212. var face = faces[ i ];
  21213. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  21214. var vertex = vertices[ face[ keys[ j ] ] ];
  21215. var normal = face.vertexNormals[ j ];
  21216. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21217. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21218. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21219. idx = idx + 1;
  21220. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21221. idx = idx + 1;
  21222. }
  21223. }
  21224. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21225. var objPos = objGeometry.attributes.position;
  21226. var objNorm = objGeometry.attributes.normal;
  21227. var idx = 0;
  21228. // for simplicity, ignore index and drawcalls, and render every normal
  21229. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21230. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21231. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  21232. v2.applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21233. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21234. idx = idx + 1;
  21235. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21236. idx = idx + 1;
  21237. }
  21238. }
  21239. position.needsUpdate = true;
  21240. return this;
  21241. }
  21242. }() );
  21243. // File:src/extras/helpers/VertexTangentsHelper.js
  21244. /**
  21245. * @author mrdoob / http://mrdoob.com/
  21246. * @author WestLangley / http://github.com/WestLangley
  21247. */
  21248. THREE.VertexTangentsHelper = function ( object, size, hex, linewidth ) {
  21249. this.object = object;
  21250. this.size = ( size !== undefined ) ? size : 1;
  21251. var color = ( hex !== undefined ) ? hex : 0x0000ff;
  21252. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21253. //
  21254. var nTangents = 0;
  21255. var objGeometry = this.object.geometry;
  21256. if ( objGeometry instanceof THREE.Geometry ) {
  21257. nTangents = objGeometry.faces.length * 3;
  21258. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21259. nTangents = objGeometry.attributes.tangent.count
  21260. }
  21261. //
  21262. var geometry = new THREE.BufferGeometry();
  21263. var positions = new THREE.Float32Attribute( nTangents * 2 * 3, 3 );
  21264. geometry.addAttribute( 'position', positions );
  21265. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21266. //
  21267. this.matrixAutoUpdate = false;
  21268. this.update();
  21269. };
  21270. THREE.VertexTangentsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21271. THREE.VertexTangentsHelper.prototype.constructor = THREE.VertexTangentsHelper;
  21272. THREE.VertexTangentsHelper.prototype.update = ( function ( object ) {
  21273. var v1 = new THREE.Vector3();
  21274. var v2 = new THREE.Vector3();
  21275. return function() {
  21276. var keys = [ 'a', 'b', 'c' ];
  21277. this.object.updateMatrixWorld( true );
  21278. var matrixWorld = this.object.matrixWorld;
  21279. var position = this.geometry.attributes.position;
  21280. //
  21281. var objGeometry = this.object.geometry;
  21282. if ( objGeometry instanceof THREE.Geometry ) {
  21283. var vertices = objGeometry.vertices;
  21284. var faces = objGeometry.faces;
  21285. var idx = 0;
  21286. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21287. var face = faces[ i ];
  21288. for ( var j = 0, jl = face.vertexTangents.length; j < jl; j ++ ) {
  21289. var vertex = vertices[ face[ keys[ j ] ] ];
  21290. var tangent = face.vertexTangents[ j ];
  21291. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21292. v2.set( tangent.x, tangent.y, tangent.z ); // tangent.w used for bitangents only
  21293. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  21294. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21295. idx = idx + 1;
  21296. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21297. idx = idx + 1;
  21298. }
  21299. }
  21300. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21301. var objPos = objGeometry.attributes.position;
  21302. var objTan = objGeometry.attributes.tangent;
  21303. var idx = 0;
  21304. // for simplicity, ignore index and drawcalls, and render every tangent
  21305. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21306. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21307. v2.set( objTan.getX( j ), objTan.getY( j ), objTan.getZ( j ) ); // tangent.w used for bitangents only
  21308. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  21309. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21310. idx = idx + 1;
  21311. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21312. idx = idx + 1;
  21313. }
  21314. }
  21315. position.needsUpdate = true;
  21316. return this;
  21317. }
  21318. }() );
  21319. // File:src/extras/helpers/WireframeHelper.js
  21320. /**
  21321. * @author mrdoob / http://mrdoob.com/
  21322. */
  21323. THREE.WireframeHelper = function ( object, hex ) {
  21324. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21325. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  21326. this.matrix = object.matrixWorld;
  21327. this.matrixAutoUpdate = false;
  21328. };
  21329. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21330. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  21331. // File:src/extras/objects/ImmediateRenderObject.js
  21332. /**
  21333. * @author alteredq / http://alteredqualia.com/
  21334. */
  21335. THREE.ImmediateRenderObject = function () {
  21336. THREE.Object3D.call( this );
  21337. this.render = function ( renderCallback ) {};
  21338. };
  21339. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  21340. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  21341. // File:src/extras/objects/MorphBlendMesh.js
  21342. /**
  21343. * @author alteredq / http://alteredqualia.com/
  21344. */
  21345. THREE.MorphBlendMesh = function( geometry, material ) {
  21346. THREE.Mesh.call( this, geometry, material );
  21347. this.animationsMap = {};
  21348. this.animationsList = [];
  21349. // prepare default animation
  21350. // (all frames played together in 1 second)
  21351. var numFrames = this.geometry.morphTargets.length;
  21352. var name = "__default";
  21353. var startFrame = 0;
  21354. var endFrame = numFrames - 1;
  21355. var fps = numFrames / 1;
  21356. this.createAnimation( name, startFrame, endFrame, fps );
  21357. this.setAnimationWeight( name, 1 );
  21358. };
  21359. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  21360. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21361. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21362. var animation = {
  21363. startFrame: start,
  21364. endFrame: end,
  21365. length: end - start + 1,
  21366. fps: fps,
  21367. duration: ( end - start ) / fps,
  21368. lastFrame: 0,
  21369. currentFrame: 0,
  21370. active: false,
  21371. time: 0,
  21372. direction: 1,
  21373. weight: 1,
  21374. directionBackwards: false,
  21375. mirroredLoop: false
  21376. };
  21377. this.animationsMap[ name ] = animation;
  21378. this.animationsList.push( animation );
  21379. };
  21380. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21381. var pattern = /([a-z]+)_?(\d+)/;
  21382. var firstAnimation, frameRanges = {};
  21383. var geometry = this.geometry;
  21384. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21385. var morph = geometry.morphTargets[ i ];
  21386. var chunks = morph.name.match( pattern );
  21387. if ( chunks && chunks.length > 1 ) {
  21388. var name = chunks[ 1 ];
  21389. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  21390. var range = frameRanges[ name ];
  21391. if ( i < range.start ) range.start = i;
  21392. if ( i > range.end ) range.end = i;
  21393. if ( ! firstAnimation ) firstAnimation = name;
  21394. }
  21395. }
  21396. for ( var name in frameRanges ) {
  21397. var range = frameRanges[ name ];
  21398. this.createAnimation( name, range.start, range.end, fps );
  21399. }
  21400. this.firstAnimation = firstAnimation;
  21401. };
  21402. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21403. var animation = this.animationsMap[ name ];
  21404. if ( animation ) {
  21405. animation.direction = 1;
  21406. animation.directionBackwards = false;
  21407. }
  21408. };
  21409. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21410. var animation = this.animationsMap[ name ];
  21411. if ( animation ) {
  21412. animation.direction = - 1;
  21413. animation.directionBackwards = true;
  21414. }
  21415. };
  21416. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21417. var animation = this.animationsMap[ name ];
  21418. if ( animation ) {
  21419. animation.fps = fps;
  21420. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21421. }
  21422. };
  21423. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21424. var animation = this.animationsMap[ name ];
  21425. if ( animation ) {
  21426. animation.duration = duration;
  21427. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21428. }
  21429. };
  21430. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21431. var animation = this.animationsMap[ name ];
  21432. if ( animation ) {
  21433. animation.weight = weight;
  21434. }
  21435. };
  21436. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  21437. var animation = this.animationsMap[ name ];
  21438. if ( animation ) {
  21439. animation.time = time;
  21440. }
  21441. };
  21442. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  21443. var time = 0;
  21444. var animation = this.animationsMap[ name ];
  21445. if ( animation ) {
  21446. time = animation.time;
  21447. }
  21448. return time;
  21449. };
  21450. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  21451. var duration = - 1;
  21452. var animation = this.animationsMap[ name ];
  21453. if ( animation ) {
  21454. duration = animation.duration;
  21455. }
  21456. return duration;
  21457. };
  21458. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  21459. var animation = this.animationsMap[ name ];
  21460. if ( animation ) {
  21461. animation.time = 0;
  21462. animation.active = true;
  21463. } else {
  21464. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  21465. }
  21466. };
  21467. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  21468. var animation = this.animationsMap[ name ];
  21469. if ( animation ) {
  21470. animation.active = false;
  21471. }
  21472. };
  21473. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  21474. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  21475. var animation = this.animationsList[ i ];
  21476. if ( ! animation.active ) continue;
  21477. var frameTime = animation.duration / animation.length;
  21478. animation.time += animation.direction * delta;
  21479. if ( animation.mirroredLoop ) {
  21480. if ( animation.time > animation.duration || animation.time < 0 ) {
  21481. animation.direction *= - 1;
  21482. if ( animation.time > animation.duration ) {
  21483. animation.time = animation.duration;
  21484. animation.directionBackwards = true;
  21485. }
  21486. if ( animation.time < 0 ) {
  21487. animation.time = 0;
  21488. animation.directionBackwards = false;
  21489. }
  21490. }
  21491. } else {
  21492. animation.time = animation.time % animation.duration;
  21493. if ( animation.time < 0 ) animation.time += animation.duration;
  21494. }
  21495. var keyframe = animation.startFrame + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  21496. var weight = animation.weight;
  21497. if ( keyframe !== animation.currentFrame ) {
  21498. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  21499. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  21500. this.morphTargetInfluences[ keyframe ] = 0;
  21501. animation.lastFrame = animation.currentFrame;
  21502. animation.currentFrame = keyframe;
  21503. }
  21504. var mix = ( animation.time % frameTime ) / frameTime;
  21505. if ( animation.directionBackwards ) mix = 1 - mix;
  21506. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  21507. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  21508. }
  21509. };
粤ICP备19079148号