three.js 796 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '72dev' };
  6. //
  7. if ( typeof define === 'function' && define.amd ) {
  8. define( 'three', THREE );
  9. } else if ( 'undefined' !== typeof exports && 'undefined' !== typeof module ) {
  10. module.exports = THREE;
  11. }
  12. // polyfills
  13. ( function () {
  14. var lastTime = 0;
  15. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  16. for ( var x = 0; x < vendors.length && ! self.requestAnimationFrame; ++ x ) {
  17. self.requestAnimationFrame = self[ vendors[ x ] + 'RequestAnimationFrame' ];
  18. self.cancelAnimationFrame = self[ vendors[ x ] + 'CancelAnimationFrame' ] || self[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  19. }
  20. if ( self.requestAnimationFrame === undefined && self.setTimeout !== undefined ) {
  21. self.requestAnimationFrame = function ( callback ) {
  22. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  23. var id = self.setTimeout( function () {
  24. callback( currTime + timeToCall );
  25. }, timeToCall );
  26. lastTime = currTime + timeToCall;
  27. return id;
  28. };
  29. }
  30. if ( self.cancelAnimationFrame === undefined && self.clearTimeout !== undefined ) {
  31. self.cancelAnimationFrame = function ( id ) {
  32. self.clearTimeout( id );
  33. };
  34. }
  35. }() );
  36. if ( Math.sign === undefined ) {
  37. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  38. Math.sign = function ( x ) {
  39. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  40. };
  41. }
  42. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  43. // Missing in IE9-11.
  44. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  45. Object.defineProperty( Function.prototype, 'name', {
  46. get: function () {
  47. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  48. }
  49. } );
  50. }
  51. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  52. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  53. // GL STATE CONSTANTS
  54. THREE.CullFaceNone = 0;
  55. THREE.CullFaceBack = 1;
  56. THREE.CullFaceFront = 2;
  57. THREE.CullFaceFrontBack = 3;
  58. THREE.FrontFaceDirectionCW = 0;
  59. THREE.FrontFaceDirectionCCW = 1;
  60. // SHADOWING TYPES
  61. THREE.BasicShadowMap = 0;
  62. THREE.PCFShadowMap = 1;
  63. THREE.PCFSoftShadowMap = 2;
  64. // MATERIAL CONSTANTS
  65. // side
  66. THREE.FrontSide = 0;
  67. THREE.BackSide = 1;
  68. THREE.DoubleSide = 2;
  69. // shading
  70. THREE.NoShading = 0;
  71. THREE.FlatShading = 1;
  72. THREE.SmoothShading = 2;
  73. // colors
  74. THREE.NoColors = 0;
  75. THREE.FaceColors = 1;
  76. THREE.VertexColors = 2;
  77. // blending modes
  78. THREE.NoBlending = 0;
  79. THREE.NormalBlending = 1;
  80. THREE.AdditiveBlending = 2;
  81. THREE.SubtractiveBlending = 3;
  82. THREE.MultiplyBlending = 4;
  83. THREE.CustomBlending = 5;
  84. // custom blending equations
  85. // (numbers start from 100 not to clash with other
  86. // mappings to OpenGL constants defined in Texture.js)
  87. THREE.AddEquation = 100;
  88. THREE.SubtractEquation = 101;
  89. THREE.ReverseSubtractEquation = 102;
  90. THREE.MinEquation = 103;
  91. THREE.MaxEquation = 104;
  92. // custom blending destination factors
  93. THREE.ZeroFactor = 200;
  94. THREE.OneFactor = 201;
  95. THREE.SrcColorFactor = 202;
  96. THREE.OneMinusSrcColorFactor = 203;
  97. THREE.SrcAlphaFactor = 204;
  98. THREE.OneMinusSrcAlphaFactor = 205;
  99. THREE.DstAlphaFactor = 206;
  100. THREE.OneMinusDstAlphaFactor = 207;
  101. // custom blending source factors
  102. //THREE.ZeroFactor = 200;
  103. //THREE.OneFactor = 201;
  104. //THREE.SrcAlphaFactor = 204;
  105. //THREE.OneMinusSrcAlphaFactor = 205;
  106. //THREE.DstAlphaFactor = 206;
  107. //THREE.OneMinusDstAlphaFactor = 207;
  108. THREE.DstColorFactor = 208;
  109. THREE.OneMinusDstColorFactor = 209;
  110. THREE.SrcAlphaSaturateFactor = 210;
  111. // depth modes
  112. THREE.NeverDepth = 0;
  113. THREE.AlwaysDepth = 1;
  114. THREE.LessDepth = 2;
  115. THREE.LessEqualDepth = 3;
  116. THREE.EqualDepth = 4;
  117. THREE.GreaterEqualDepth = 5;
  118. THREE.GreaterDepth = 6;
  119. THREE.NotEqualDepth = 7;
  120. // TEXTURE CONSTANTS
  121. THREE.MultiplyOperation = 0;
  122. THREE.MixOperation = 1;
  123. THREE.AddOperation = 2;
  124. // Mapping modes
  125. THREE.UVMapping = 300;
  126. THREE.CubeReflectionMapping = 301;
  127. THREE.CubeRefractionMapping = 302;
  128. THREE.EquirectangularReflectionMapping = 303;
  129. THREE.EquirectangularRefractionMapping = 304;
  130. THREE.SphericalReflectionMapping = 305;
  131. // Wrapping modes
  132. THREE.RepeatWrapping = 1000;
  133. THREE.ClampToEdgeWrapping = 1001;
  134. THREE.MirroredRepeatWrapping = 1002;
  135. // Filters
  136. THREE.NearestFilter = 1003;
  137. THREE.NearestMipMapNearestFilter = 1004;
  138. THREE.NearestMipMapLinearFilter = 1005;
  139. THREE.LinearFilter = 1006;
  140. THREE.LinearMipMapNearestFilter = 1007;
  141. THREE.LinearMipMapLinearFilter = 1008;
  142. // Data types
  143. THREE.UnsignedByteType = 1009;
  144. THREE.ByteType = 1010;
  145. THREE.ShortType = 1011;
  146. THREE.UnsignedShortType = 1012;
  147. THREE.IntType = 1013;
  148. THREE.UnsignedIntType = 1014;
  149. THREE.FloatType = 1015;
  150. THREE.HalfFloatType = 1025;
  151. // Pixel types
  152. //THREE.UnsignedByteType = 1009;
  153. THREE.UnsignedShort4444Type = 1016;
  154. THREE.UnsignedShort5551Type = 1017;
  155. THREE.UnsignedShort565Type = 1018;
  156. // Pixel formats
  157. THREE.AlphaFormat = 1019;
  158. THREE.RGBFormat = 1020;
  159. THREE.RGBAFormat = 1021;
  160. THREE.LuminanceFormat = 1022;
  161. THREE.LuminanceAlphaFormat = 1023;
  162. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  163. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  164. // DDS / ST3C Compressed texture formats
  165. THREE.RGB_S3TC_DXT1_Format = 2001;
  166. THREE.RGBA_S3TC_DXT1_Format = 2002;
  167. THREE.RGBA_S3TC_DXT3_Format = 2003;
  168. THREE.RGBA_S3TC_DXT5_Format = 2004;
  169. // PVRTC compressed texture formats
  170. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  171. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  172. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  173. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  174. // DEPRECATED
  175. THREE.Projector = function () {
  176. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  177. this.projectVector = function ( vector, camera ) {
  178. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  179. vector.project( camera );
  180. };
  181. this.unprojectVector = function ( vector, camera ) {
  182. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  183. vector.unproject( camera );
  184. };
  185. this.pickingRay = function ( vector, camera ) {
  186. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  187. };
  188. };
  189. THREE.CanvasRenderer = function () {
  190. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  191. this.domElement = document.createElement( 'canvas' );
  192. this.clear = function () {};
  193. this.render = function () {};
  194. this.setClearColor = function () {};
  195. this.setSize = function () {};
  196. };
  197. // File:src/math/Color.js
  198. /**
  199. * @author mrdoob / http://mrdoob.com/
  200. */
  201. THREE.Color = function ( color ) {
  202. if ( arguments.length === 3 ) {
  203. return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
  204. }
  205. return this.set( color );
  206. };
  207. THREE.Color.prototype = {
  208. constructor: THREE.Color,
  209. r: 1, g: 1, b: 1,
  210. set: function ( value ) {
  211. if ( value instanceof THREE.Color ) {
  212. this.copy( value );
  213. } else if ( typeof value === 'number' ) {
  214. this.setHex( value );
  215. } else if ( typeof value === 'string' ) {
  216. this.setStyle( value );
  217. }
  218. return this;
  219. },
  220. setHex: function ( hex ) {
  221. hex = Math.floor( hex );
  222. this.r = ( hex >> 16 & 255 ) / 255;
  223. this.g = ( hex >> 8 & 255 ) / 255;
  224. this.b = ( hex & 255 ) / 255;
  225. return this;
  226. },
  227. setRGB: function ( r, g, b ) {
  228. this.r = r;
  229. this.g = g;
  230. this.b = b;
  231. return this;
  232. },
  233. setHSL: function () {
  234. function hue2rgb ( p, q, t ) {
  235. if ( t < 0 ) t += 1;
  236. if ( t > 1 ) t -= 1;
  237. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  238. if ( t < 1 / 2 ) return q;
  239. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  240. return p;
  241. }
  242. return function ( h, s, l ) {
  243. // h,s,l ranges are in 0.0 - 1.0
  244. h = THREE.Math.euclideanModulo( h, 1 );
  245. s = THREE.Math.clamp( s, 0, 1 );
  246. l = THREE.Math.clamp( l, 0, 1 );
  247. if ( s === 0 ) {
  248. this.r = this.g = this.b = l;
  249. } else {
  250. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  251. var q = ( 2 * l ) - p;
  252. this.r = hue2rgb( q, p, h + 1 / 3 );
  253. this.g = hue2rgb( q, p, h );
  254. this.b = hue2rgb( q, p, h - 1 / 3 );
  255. }
  256. return this;
  257. };
  258. }(),
  259. setStyle: function ( style ) {
  260. var parseAlpha = function ( strAlpha ) {
  261. var alpha = parseFloat( strAlpha );
  262. if ( alpha < 1 ) {
  263. console.warn( 'THREE.Color: Alpha component of color ' + style + ' will be ignored.' );
  264. }
  265. return alpha;
  266. }
  267. var m;
  268. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  269. // rgb / hsl
  270. var color;
  271. var name = m[ 1 ];
  272. var components = m[ 2 ];
  273. switch ( name ) {
  274. case 'rgb':
  275. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*$/.exec( components ) ) {
  276. // rgb(255,0,0)
  277. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  278. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  279. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  280. return this;
  281. }
  282. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  283. // rgb(100%,0%,0%)
  284. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  285. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  286. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  287. return this;
  288. }
  289. break;
  290. case 'rgba':
  291. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  292. // rgba(255,0,0,0.5)
  293. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  294. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  295. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  296. parseAlpha( color[ 4 ] );
  297. return this;
  298. }
  299. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  300. // rgba(100%,0%,0%,0.5)
  301. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  302. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  303. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  304. parseAlpha( color[ 4 ] );
  305. return this;
  306. }
  307. break;
  308. case 'hsl':
  309. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  310. // hsl(120,50%,50%)
  311. var h = parseFloat( color[ 1 ] );
  312. var s = parseInt( color[ 2 ], 10 ) / 100;
  313. var l = parseInt( color[ 3 ], 10 ) / 100;
  314. return this.setHSL( h, s, l );
  315. }
  316. break;
  317. case 'hsla':
  318. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  319. // hsla(120,50%,50%,0.5)
  320. var h = parseFloat( color[ 1 ] );
  321. var s = parseInt( color[ 2 ], 10 ) / 100;
  322. var l = parseInt( color[ 3 ], 10 ) / 100;
  323. parseAlpha( color[ 4 ] );
  324. return this.setHSL( h, s, l );
  325. }
  326. break;
  327. }
  328. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  329. // hex color
  330. var hex = m[ 1 ];
  331. var size = hex.length;
  332. if ( size === 3 ) {
  333. // #ff0
  334. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  335. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  336. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  337. return this;
  338. } else if ( size === 6 ) {
  339. // #ff0000
  340. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  341. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  342. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  343. return this;
  344. }
  345. }
  346. if ( style && style.length > 0 ) {
  347. // color keywords
  348. var hex = THREE.ColorKeywords[ style ];
  349. if ( hex !== undefined ) {
  350. // red
  351. this.setHex( hex );
  352. } else {
  353. // unknown color
  354. console.warn( 'THREE.Color: Unknown color ' + style );
  355. }
  356. }
  357. return this;
  358. },
  359. copy: function ( color ) {
  360. this.r = color.r;
  361. this.g = color.g;
  362. this.b = color.b;
  363. return this;
  364. },
  365. copyGammaToLinear: function ( color, gammaFactor ) {
  366. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  367. this.r = Math.pow( color.r, gammaFactor );
  368. this.g = Math.pow( color.g, gammaFactor );
  369. this.b = Math.pow( color.b, gammaFactor );
  370. return this;
  371. },
  372. copyLinearToGamma: function ( color, gammaFactor ) {
  373. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  374. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  375. this.r = Math.pow( color.r, safeInverse );
  376. this.g = Math.pow( color.g, safeInverse );
  377. this.b = Math.pow( color.b, safeInverse );
  378. return this;
  379. },
  380. convertGammaToLinear: function () {
  381. var r = this.r, g = this.g, b = this.b;
  382. this.r = r * r;
  383. this.g = g * g;
  384. this.b = b * b;
  385. return this;
  386. },
  387. convertLinearToGamma: function () {
  388. this.r = Math.sqrt( this.r );
  389. this.g = Math.sqrt( this.g );
  390. this.b = Math.sqrt( this.b );
  391. return this;
  392. },
  393. getHex: function () {
  394. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  395. },
  396. getHexString: function () {
  397. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  398. },
  399. getHSL: function ( optionalTarget ) {
  400. // h,s,l ranges are in 0.0 - 1.0
  401. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  402. var r = this.r, g = this.g, b = this.b;
  403. var max = Math.max( r, g, b );
  404. var min = Math.min( r, g, b );
  405. var hue, saturation;
  406. var lightness = ( min + max ) / 2.0;
  407. if ( min === max ) {
  408. hue = 0;
  409. saturation = 0;
  410. } else {
  411. var delta = max - min;
  412. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  413. switch ( max ) {
  414. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  415. case g: hue = ( b - r ) / delta + 2; break;
  416. case b: hue = ( r - g ) / delta + 4; break;
  417. }
  418. hue /= 6;
  419. }
  420. hsl.h = hue;
  421. hsl.s = saturation;
  422. hsl.l = lightness;
  423. return hsl;
  424. },
  425. getStyle: function () {
  426. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  427. },
  428. offsetHSL: function ( h, s, l ) {
  429. var hsl = this.getHSL();
  430. hsl.h += h; hsl.s += s; hsl.l += l;
  431. this.setHSL( hsl.h, hsl.s, hsl.l );
  432. return this;
  433. },
  434. add: function ( color ) {
  435. this.r += color.r;
  436. this.g += color.g;
  437. this.b += color.b;
  438. return this;
  439. },
  440. addColors: function ( color1, color2 ) {
  441. this.r = color1.r + color2.r;
  442. this.g = color1.g + color2.g;
  443. this.b = color1.b + color2.b;
  444. return this;
  445. },
  446. addScalar: function ( s ) {
  447. this.r += s;
  448. this.g += s;
  449. this.b += s;
  450. return this;
  451. },
  452. multiply: function ( color ) {
  453. this.r *= color.r;
  454. this.g *= color.g;
  455. this.b *= color.b;
  456. return this;
  457. },
  458. multiplyScalar: function ( s ) {
  459. this.r *= s;
  460. this.g *= s;
  461. this.b *= s;
  462. return this;
  463. },
  464. lerp: function ( color, alpha ) {
  465. this.r += ( color.r - this.r ) * alpha;
  466. this.g += ( color.g - this.g ) * alpha;
  467. this.b += ( color.b - this.b ) * alpha;
  468. return this;
  469. },
  470. equals: function ( c ) {
  471. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  472. },
  473. fromArray: function ( array ) {
  474. this.r = array[ 0 ];
  475. this.g = array[ 1 ];
  476. this.b = array[ 2 ];
  477. return this;
  478. },
  479. toArray: function ( array, offset ) {
  480. if ( array === undefined ) array = [];
  481. if ( offset === undefined ) offset = 0;
  482. array[ offset ] = this.r;
  483. array[ offset + 1 ] = this.g;
  484. array[ offset + 2 ] = this.b;
  485. return array;
  486. },
  487. clone: function () {
  488. return new THREE.Color().copy( this );
  489. }
  490. };
  491. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  492. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  493. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  494. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  495. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  496. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  497. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  498. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  499. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  500. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  501. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  502. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  503. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  504. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  505. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  506. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  507. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  508. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  509. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  510. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  511. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  512. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  513. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  514. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  515. // File:src/math/Quaternion.js
  516. /**
  517. * @author mikael emtinger / http://gomo.se/
  518. * @author alteredq / http://alteredqualia.com/
  519. * @author WestLangley / http://github.com/WestLangley
  520. * @author bhouston / http://exocortex.com
  521. */
  522. THREE.Quaternion = function ( x, y, z, w ) {
  523. this._x = x || 0;
  524. this._y = y || 0;
  525. this._z = z || 0;
  526. this._w = ( w !== undefined ) ? w : 1;
  527. };
  528. THREE.Quaternion.prototype = {
  529. constructor: THREE.Quaternion,
  530. get x () {
  531. return this._x;
  532. },
  533. set x ( value ) {
  534. this._x = value;
  535. this.onChangeCallback();
  536. },
  537. get y () {
  538. return this._y;
  539. },
  540. set y ( value ) {
  541. this._y = value;
  542. this.onChangeCallback();
  543. },
  544. get z () {
  545. return this._z;
  546. },
  547. set z ( value ) {
  548. this._z = value;
  549. this.onChangeCallback();
  550. },
  551. get w () {
  552. return this._w;
  553. },
  554. set w ( value ) {
  555. this._w = value;
  556. this.onChangeCallback();
  557. },
  558. set: function ( x, y, z, w ) {
  559. this._x = x;
  560. this._y = y;
  561. this._z = z;
  562. this._w = w;
  563. this.onChangeCallback();
  564. return this;
  565. },
  566. copy: function ( quaternion ) {
  567. this._x = quaternion.x;
  568. this._y = quaternion.y;
  569. this._z = quaternion.z;
  570. this._w = quaternion.w;
  571. this.onChangeCallback();
  572. return this;
  573. },
  574. setFromEuler: function ( euler, update ) {
  575. if ( euler instanceof THREE.Euler === false ) {
  576. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  577. }
  578. // http://www.mathworks.com/matlabcentral/fileexchange/
  579. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  580. // content/SpinCalc.m
  581. var c1 = Math.cos( euler._x / 2 );
  582. var c2 = Math.cos( euler._y / 2 );
  583. var c3 = Math.cos( euler._z / 2 );
  584. var s1 = Math.sin( euler._x / 2 );
  585. var s2 = Math.sin( euler._y / 2 );
  586. var s3 = Math.sin( euler._z / 2 );
  587. if ( euler.order === 'XYZ' ) {
  588. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  589. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  590. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  591. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  592. } else if ( euler.order === 'YXZ' ) {
  593. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  594. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  595. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  596. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  597. } else if ( euler.order === 'ZXY' ) {
  598. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  599. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  600. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  601. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  602. } else if ( euler.order === 'ZYX' ) {
  603. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  604. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  605. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  606. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  607. } else if ( euler.order === 'YZX' ) {
  608. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  609. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  610. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  611. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  612. } else if ( euler.order === 'XZY' ) {
  613. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  614. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  615. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  616. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  617. }
  618. if ( update !== false ) this.onChangeCallback();
  619. return this;
  620. },
  621. setFromAxisAngle: function ( axis, angle ) {
  622. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  623. // assumes axis is normalized
  624. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  625. this._x = axis.x * s;
  626. this._y = axis.y * s;
  627. this._z = axis.z * s;
  628. this._w = Math.cos( halfAngle );
  629. this.onChangeCallback();
  630. return this;
  631. },
  632. setFromRotationMatrix: function ( m ) {
  633. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  634. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  635. var te = m.elements,
  636. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  637. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  638. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  639. trace = m11 + m22 + m33,
  640. s;
  641. if ( trace > 0 ) {
  642. s = 0.5 / Math.sqrt( trace + 1.0 );
  643. this._w = 0.25 / s;
  644. this._x = ( m32 - m23 ) * s;
  645. this._y = ( m13 - m31 ) * s;
  646. this._z = ( m21 - m12 ) * s;
  647. } else if ( m11 > m22 && m11 > m33 ) {
  648. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  649. this._w = ( m32 - m23 ) / s;
  650. this._x = 0.25 * s;
  651. this._y = ( m12 + m21 ) / s;
  652. this._z = ( m13 + m31 ) / s;
  653. } else if ( m22 > m33 ) {
  654. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  655. this._w = ( m13 - m31 ) / s;
  656. this._x = ( m12 + m21 ) / s;
  657. this._y = 0.25 * s;
  658. this._z = ( m23 + m32 ) / s;
  659. } else {
  660. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  661. this._w = ( m21 - m12 ) / s;
  662. this._x = ( m13 + m31 ) / s;
  663. this._y = ( m23 + m32 ) / s;
  664. this._z = 0.25 * s;
  665. }
  666. this.onChangeCallback();
  667. return this;
  668. },
  669. setFromUnitVectors: function () {
  670. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  671. // assumes direction vectors vFrom and vTo are normalized
  672. var v1, r;
  673. var EPS = 0.000001;
  674. return function ( vFrom, vTo ) {
  675. if ( v1 === undefined ) v1 = new THREE.Vector3();
  676. r = vFrom.dot( vTo ) + 1;
  677. if ( r < EPS ) {
  678. r = 0;
  679. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  680. v1.set( - vFrom.y, vFrom.x, 0 );
  681. } else {
  682. v1.set( 0, - vFrom.z, vFrom.y );
  683. }
  684. } else {
  685. v1.crossVectors( vFrom, vTo );
  686. }
  687. this._x = v1.x;
  688. this._y = v1.y;
  689. this._z = v1.z;
  690. this._w = r;
  691. this.normalize();
  692. return this;
  693. }
  694. }(),
  695. inverse: function () {
  696. this.conjugate().normalize();
  697. return this;
  698. },
  699. conjugate: function () {
  700. this._x *= - 1;
  701. this._y *= - 1;
  702. this._z *= - 1;
  703. this.onChangeCallback();
  704. return this;
  705. },
  706. dot: function ( v ) {
  707. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  708. },
  709. lengthSq: function () {
  710. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  711. },
  712. length: function () {
  713. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  714. },
  715. normalize: function () {
  716. var l = this.length();
  717. if ( l === 0 ) {
  718. this._x = 0;
  719. this._y = 0;
  720. this._z = 0;
  721. this._w = 1;
  722. } else {
  723. l = 1 / l;
  724. this._x = this._x * l;
  725. this._y = this._y * l;
  726. this._z = this._z * l;
  727. this._w = this._w * l;
  728. }
  729. this.onChangeCallback();
  730. return this;
  731. },
  732. multiply: function ( q, p ) {
  733. if ( p !== undefined ) {
  734. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  735. return this.multiplyQuaternions( q, p );
  736. }
  737. return this.multiplyQuaternions( this, q );
  738. },
  739. multiplyQuaternions: function ( a, b ) {
  740. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  741. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  742. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  743. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  744. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  745. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  746. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  747. this.onChangeCallback();
  748. return this;
  749. },
  750. multiplyVector3: function ( vector ) {
  751. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  752. return vector.applyQuaternion( this );
  753. },
  754. slerp: function ( qb, t ) {
  755. if ( t === 0 ) return this;
  756. if ( t === 1 ) return this.copy( qb );
  757. var x = this._x, y = this._y, z = this._z, w = this._w;
  758. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  759. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  760. if ( cosHalfTheta < 0 ) {
  761. this._w = - qb._w;
  762. this._x = - qb._x;
  763. this._y = - qb._y;
  764. this._z = - qb._z;
  765. cosHalfTheta = - cosHalfTheta;
  766. } else {
  767. this.copy( qb );
  768. }
  769. if ( cosHalfTheta >= 1.0 ) {
  770. this._w = w;
  771. this._x = x;
  772. this._y = y;
  773. this._z = z;
  774. return this;
  775. }
  776. var halfTheta = Math.acos( cosHalfTheta );
  777. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  778. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  779. this._w = 0.5 * ( w + this._w );
  780. this._x = 0.5 * ( x + this._x );
  781. this._y = 0.5 * ( y + this._y );
  782. this._z = 0.5 * ( z + this._z );
  783. return this;
  784. }
  785. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  786. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  787. this._w = ( w * ratioA + this._w * ratioB );
  788. this._x = ( x * ratioA + this._x * ratioB );
  789. this._y = ( y * ratioA + this._y * ratioB );
  790. this._z = ( z * ratioA + this._z * ratioB );
  791. this.onChangeCallback();
  792. return this;
  793. },
  794. equals: function ( quaternion ) {
  795. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  796. },
  797. fromArray: function ( array, offset ) {
  798. if ( offset === undefined ) offset = 0;
  799. this._x = array[ offset ];
  800. this._y = array[ offset + 1 ];
  801. this._z = array[ offset + 2 ];
  802. this._w = array[ offset + 3 ];
  803. this.onChangeCallback();
  804. return this;
  805. },
  806. toArray: function ( array, offset ) {
  807. if ( array === undefined ) array = [];
  808. if ( offset === undefined ) offset = 0;
  809. array[ offset ] = this._x;
  810. array[ offset + 1 ] = this._y;
  811. array[ offset + 2 ] = this._z;
  812. array[ offset + 3 ] = this._w;
  813. return array;
  814. },
  815. onChange: function ( callback ) {
  816. this.onChangeCallback = callback;
  817. return this;
  818. },
  819. onChangeCallback: function () {},
  820. clone: function () {
  821. return new THREE.Quaternion( this._x, this._y, this._z, this._w );
  822. }
  823. };
  824. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  825. return qm.copy( qa ).slerp( qb, t );
  826. };
  827. // File:src/math/Vector2.js
  828. /**
  829. * @author mrdoob / http://mrdoob.com/
  830. * @author philogb / http://blog.thejit.org/
  831. * @author egraether / http://egraether.com/
  832. * @author zz85 / http://www.lab4games.net/zz85/blog
  833. */
  834. THREE.Vector2 = function ( x, y ) {
  835. this.x = x || 0;
  836. this.y = y || 0;
  837. };
  838. THREE.Vector2.prototype = {
  839. constructor: THREE.Vector2,
  840. set: function ( x, y ) {
  841. this.x = x;
  842. this.y = y;
  843. return this;
  844. },
  845. setX: function ( x ) {
  846. this.x = x;
  847. return this;
  848. },
  849. setY: function ( y ) {
  850. this.y = y;
  851. return this;
  852. },
  853. setComponent: function ( index, value ) {
  854. switch ( index ) {
  855. case 0: this.x = value; break;
  856. case 1: this.y = value; break;
  857. default: throw new Error( 'index is out of range: ' + index );
  858. }
  859. },
  860. getComponent: function ( index ) {
  861. switch ( index ) {
  862. case 0: return this.x;
  863. case 1: return this.y;
  864. default: throw new Error( 'index is out of range: ' + index );
  865. }
  866. },
  867. copy: function ( v ) {
  868. this.x = v.x;
  869. this.y = v.y;
  870. return this;
  871. },
  872. add: function ( v, w ) {
  873. if ( w !== undefined ) {
  874. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  875. return this.addVectors( v, w );
  876. }
  877. this.x += v.x;
  878. this.y += v.y;
  879. return this;
  880. },
  881. addScalar: function ( s ) {
  882. this.x += s;
  883. this.y += s;
  884. return this;
  885. },
  886. addVectors: function ( a, b ) {
  887. this.x = a.x + b.x;
  888. this.y = a.y + b.y;
  889. return this;
  890. },
  891. addScaledVector: function ( v, s ) {
  892. this.x += v.x * s;
  893. this.y += v.y * s;
  894. return this;
  895. },
  896. sub: function ( v, w ) {
  897. if ( w !== undefined ) {
  898. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  899. return this.subVectors( v, w );
  900. }
  901. this.x -= v.x;
  902. this.y -= v.y;
  903. return this;
  904. },
  905. subScalar: function ( s ) {
  906. this.x -= s;
  907. this.y -= s;
  908. return this;
  909. },
  910. subVectors: function ( a, b ) {
  911. this.x = a.x - b.x;
  912. this.y = a.y - b.y;
  913. return this;
  914. },
  915. multiply: function ( v ) {
  916. this.x *= v.x;
  917. this.y *= v.y;
  918. return this;
  919. },
  920. multiplyScalar: function ( s ) {
  921. this.x *= s;
  922. this.y *= s;
  923. return this;
  924. },
  925. divide: function ( v ) {
  926. this.x /= v.x;
  927. this.y /= v.y;
  928. return this;
  929. },
  930. divideScalar: function ( scalar ) {
  931. if ( scalar !== 0 ) {
  932. var invScalar = 1 / scalar;
  933. this.x *= invScalar;
  934. this.y *= invScalar;
  935. } else {
  936. this.x = 0;
  937. this.y = 0;
  938. }
  939. return this;
  940. },
  941. min: function ( v ) {
  942. if ( this.x > v.x ) {
  943. this.x = v.x;
  944. }
  945. if ( this.y > v.y ) {
  946. this.y = v.y;
  947. }
  948. return this;
  949. },
  950. max: function ( v ) {
  951. if ( this.x < v.x ) {
  952. this.x = v.x;
  953. }
  954. if ( this.y < v.y ) {
  955. this.y = v.y;
  956. }
  957. return this;
  958. },
  959. clamp: function ( min, max ) {
  960. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  961. if ( this.x < min.x ) {
  962. this.x = min.x;
  963. } else if ( this.x > max.x ) {
  964. this.x = max.x;
  965. }
  966. if ( this.y < min.y ) {
  967. this.y = min.y;
  968. } else if ( this.y > max.y ) {
  969. this.y = max.y;
  970. }
  971. return this;
  972. },
  973. clampScalar: function () {
  974. var min, max;
  975. return function clampScalar( minVal, maxVal ) {
  976. if ( min === undefined ) {
  977. min = new THREE.Vector2();
  978. max = new THREE.Vector2();
  979. }
  980. min.set( minVal, minVal );
  981. max.set( maxVal, maxVal );
  982. return this.clamp( min, max );
  983. };
  984. }(),
  985. floor: function () {
  986. this.x = Math.floor( this.x );
  987. this.y = Math.floor( this.y );
  988. return this;
  989. },
  990. ceil: function () {
  991. this.x = Math.ceil( this.x );
  992. this.y = Math.ceil( this.y );
  993. return this;
  994. },
  995. round: function () {
  996. this.x = Math.round( this.x );
  997. this.y = Math.round( this.y );
  998. return this;
  999. },
  1000. roundToZero: function () {
  1001. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1002. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1003. return this;
  1004. },
  1005. negate: function () {
  1006. this.x = - this.x;
  1007. this.y = - this.y;
  1008. return this;
  1009. },
  1010. dot: function ( v ) {
  1011. return this.x * v.x + this.y * v.y;
  1012. },
  1013. lengthSq: function () {
  1014. return this.x * this.x + this.y * this.y;
  1015. },
  1016. length: function () {
  1017. return Math.sqrt( this.x * this.x + this.y * this.y );
  1018. },
  1019. lengthManhattan: function() {
  1020. return Math.abs( this.x ) + Math.abs( this.y );
  1021. },
  1022. normalize: function () {
  1023. return this.divideScalar( this.length() );
  1024. },
  1025. distanceTo: function ( v ) {
  1026. return Math.sqrt( this.distanceToSquared( v ) );
  1027. },
  1028. distanceToSquared: function ( v ) {
  1029. var dx = this.x - v.x, dy = this.y - v.y;
  1030. return dx * dx + dy * dy;
  1031. },
  1032. setLength: function ( l ) {
  1033. var oldLength = this.length();
  1034. if ( oldLength !== 0 && l !== oldLength ) {
  1035. this.multiplyScalar( l / oldLength );
  1036. }
  1037. return this;
  1038. },
  1039. lerp: function ( v, alpha ) {
  1040. this.x += ( v.x - this.x ) * alpha;
  1041. this.y += ( v.y - this.y ) * alpha;
  1042. return this;
  1043. },
  1044. lerpVectors: function ( v1, v2, alpha ) {
  1045. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1046. return this;
  1047. },
  1048. equals: function ( v ) {
  1049. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1050. },
  1051. fromArray: function ( array, offset ) {
  1052. if ( offset === undefined ) offset = 0;
  1053. this.x = array[ offset ];
  1054. this.y = array[ offset + 1 ];
  1055. return this;
  1056. },
  1057. toArray: function ( array, offset ) {
  1058. if ( array === undefined ) array = [];
  1059. if ( offset === undefined ) offset = 0;
  1060. array[ offset ] = this.x;
  1061. array[ offset + 1 ] = this.y;
  1062. return array;
  1063. },
  1064. fromAttribute: function ( attribute, index, offset ) {
  1065. if ( offset === undefined ) offset = 0;
  1066. index = index * attribute.itemSize + offset;
  1067. this.x = attribute.array[ index ];
  1068. this.y = attribute.array[ index + 1 ];
  1069. return this;
  1070. },
  1071. clone: function () {
  1072. return new THREE.Vector2( this.x, this.y );
  1073. }
  1074. };
  1075. // File:src/math/Vector3.js
  1076. /**
  1077. * @author mrdoob / http://mrdoob.com/
  1078. * @author *kile / http://kile.stravaganza.org/
  1079. * @author philogb / http://blog.thejit.org/
  1080. * @author mikael emtinger / http://gomo.se/
  1081. * @author egraether / http://egraether.com/
  1082. * @author WestLangley / http://github.com/WestLangley
  1083. */
  1084. THREE.Vector3 = function ( x, y, z ) {
  1085. this.x = x || 0;
  1086. this.y = y || 0;
  1087. this.z = z || 0;
  1088. };
  1089. THREE.Vector3.prototype = {
  1090. constructor: THREE.Vector3,
  1091. set: function ( x, y, z ) {
  1092. this.x = x;
  1093. this.y = y;
  1094. this.z = z;
  1095. return this;
  1096. },
  1097. setX: function ( x ) {
  1098. this.x = x;
  1099. return this;
  1100. },
  1101. setY: function ( y ) {
  1102. this.y = y;
  1103. return this;
  1104. },
  1105. setZ: function ( z ) {
  1106. this.z = z;
  1107. return this;
  1108. },
  1109. setComponent: function ( index, value ) {
  1110. switch ( index ) {
  1111. case 0: this.x = value; break;
  1112. case 1: this.y = value; break;
  1113. case 2: this.z = value; break;
  1114. default: throw new Error( 'index is out of range: ' + index );
  1115. }
  1116. },
  1117. getComponent: function ( index ) {
  1118. switch ( index ) {
  1119. case 0: return this.x;
  1120. case 1: return this.y;
  1121. case 2: return this.z;
  1122. default: throw new Error( 'index is out of range: ' + index );
  1123. }
  1124. },
  1125. copy: function ( v ) {
  1126. this.x = v.x;
  1127. this.y = v.y;
  1128. this.z = v.z;
  1129. return this;
  1130. },
  1131. add: function ( v, w ) {
  1132. if ( w !== undefined ) {
  1133. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1134. return this.addVectors( v, w );
  1135. }
  1136. this.x += v.x;
  1137. this.y += v.y;
  1138. this.z += v.z;
  1139. return this;
  1140. },
  1141. addScalar: function ( s ) {
  1142. this.x += s;
  1143. this.y += s;
  1144. this.z += s;
  1145. return this;
  1146. },
  1147. addVectors: function ( a, b ) {
  1148. this.x = a.x + b.x;
  1149. this.y = a.y + b.y;
  1150. this.z = a.z + b.z;
  1151. return this;
  1152. },
  1153. addScaledVector: function ( v, s ) {
  1154. this.x += v.x * s;
  1155. this.y += v.y * s;
  1156. this.z += v.z * s;
  1157. return this;
  1158. },
  1159. sub: function ( v, w ) {
  1160. if ( w !== undefined ) {
  1161. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1162. return this.subVectors( v, w );
  1163. }
  1164. this.x -= v.x;
  1165. this.y -= v.y;
  1166. this.z -= v.z;
  1167. return this;
  1168. },
  1169. subScalar: function ( s ) {
  1170. this.x -= s;
  1171. this.y -= s;
  1172. this.z -= s;
  1173. return this;
  1174. },
  1175. subVectors: function ( a, b ) {
  1176. this.x = a.x - b.x;
  1177. this.y = a.y - b.y;
  1178. this.z = a.z - b.z;
  1179. return this;
  1180. },
  1181. multiply: function ( v, w ) {
  1182. if ( w !== undefined ) {
  1183. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1184. return this.multiplyVectors( v, w );
  1185. }
  1186. this.x *= v.x;
  1187. this.y *= v.y;
  1188. this.z *= v.z;
  1189. return this;
  1190. },
  1191. multiplyScalar: function ( scalar ) {
  1192. this.x *= scalar;
  1193. this.y *= scalar;
  1194. this.z *= scalar;
  1195. return this;
  1196. },
  1197. multiplyVectors: function ( a, b ) {
  1198. this.x = a.x * b.x;
  1199. this.y = a.y * b.y;
  1200. this.z = a.z * b.z;
  1201. return this;
  1202. },
  1203. applyEuler: function () {
  1204. var quaternion;
  1205. return function applyEuler( euler ) {
  1206. if ( euler instanceof THREE.Euler === false ) {
  1207. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1208. }
  1209. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1210. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1211. return this;
  1212. };
  1213. }(),
  1214. applyAxisAngle: function () {
  1215. var quaternion;
  1216. return function applyAxisAngle( axis, angle ) {
  1217. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1218. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1219. return this;
  1220. };
  1221. }(),
  1222. applyMatrix3: function ( m ) {
  1223. var x = this.x;
  1224. var y = this.y;
  1225. var z = this.z;
  1226. var e = m.elements;
  1227. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1228. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1229. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1230. return this;
  1231. },
  1232. applyMatrix4: function ( m ) {
  1233. // input: THREE.Matrix4 affine matrix
  1234. var x = this.x, y = this.y, z = this.z;
  1235. var e = m.elements;
  1236. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1237. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1238. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1239. return this;
  1240. },
  1241. applyProjection: function ( m ) {
  1242. // input: THREE.Matrix4 projection matrix
  1243. var x = this.x, y = this.y, z = this.z;
  1244. var e = m.elements;
  1245. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1246. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1247. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1248. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1249. return this;
  1250. },
  1251. applyQuaternion: function ( q ) {
  1252. var x = this.x;
  1253. var y = this.y;
  1254. var z = this.z;
  1255. var qx = q.x;
  1256. var qy = q.y;
  1257. var qz = q.z;
  1258. var qw = q.w;
  1259. // calculate quat * vector
  1260. var ix = qw * x + qy * z - qz * y;
  1261. var iy = qw * y + qz * x - qx * z;
  1262. var iz = qw * z + qx * y - qy * x;
  1263. var iw = - qx * x - qy * y - qz * z;
  1264. // calculate result * inverse quat
  1265. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1266. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1267. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1268. return this;
  1269. },
  1270. project: function () {
  1271. var matrix;
  1272. return function project( camera ) {
  1273. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1274. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1275. return this.applyProjection( matrix );
  1276. };
  1277. }(),
  1278. unproject: function () {
  1279. var matrix;
  1280. return function unproject( camera ) {
  1281. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1282. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1283. return this.applyProjection( matrix );
  1284. };
  1285. }(),
  1286. transformDirection: function ( m ) {
  1287. // input: THREE.Matrix4 affine matrix
  1288. // vector interpreted as a direction
  1289. var x = this.x, y = this.y, z = this.z;
  1290. var e = m.elements;
  1291. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1292. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1293. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1294. this.normalize();
  1295. return this;
  1296. },
  1297. divide: function ( v ) {
  1298. this.x /= v.x;
  1299. this.y /= v.y;
  1300. this.z /= v.z;
  1301. return this;
  1302. },
  1303. divideScalar: function ( scalar ) {
  1304. if ( scalar !== 0 ) {
  1305. var invScalar = 1 / scalar;
  1306. this.x *= invScalar;
  1307. this.y *= invScalar;
  1308. this.z *= invScalar;
  1309. } else {
  1310. this.x = 0;
  1311. this.y = 0;
  1312. this.z = 0;
  1313. }
  1314. return this;
  1315. },
  1316. min: function ( v ) {
  1317. if ( this.x > v.x ) {
  1318. this.x = v.x;
  1319. }
  1320. if ( this.y > v.y ) {
  1321. this.y = v.y;
  1322. }
  1323. if ( this.z > v.z ) {
  1324. this.z = v.z;
  1325. }
  1326. return this;
  1327. },
  1328. max: function ( v ) {
  1329. if ( this.x < v.x ) {
  1330. this.x = v.x;
  1331. }
  1332. if ( this.y < v.y ) {
  1333. this.y = v.y;
  1334. }
  1335. if ( this.z < v.z ) {
  1336. this.z = v.z;
  1337. }
  1338. return this;
  1339. },
  1340. clamp: function ( min, max ) {
  1341. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1342. if ( this.x < min.x ) {
  1343. this.x = min.x;
  1344. } else if ( this.x > max.x ) {
  1345. this.x = max.x;
  1346. }
  1347. if ( this.y < min.y ) {
  1348. this.y = min.y;
  1349. } else if ( this.y > max.y ) {
  1350. this.y = max.y;
  1351. }
  1352. if ( this.z < min.z ) {
  1353. this.z = min.z;
  1354. } else if ( this.z > max.z ) {
  1355. this.z = max.z;
  1356. }
  1357. return this;
  1358. },
  1359. clampScalar: function () {
  1360. var min, max;
  1361. return function clampScalar( minVal, maxVal ) {
  1362. if ( min === undefined ) {
  1363. min = new THREE.Vector3();
  1364. max = new THREE.Vector3();
  1365. }
  1366. min.set( minVal, minVal, minVal );
  1367. max.set( maxVal, maxVal, maxVal );
  1368. return this.clamp( min, max );
  1369. };
  1370. }(),
  1371. floor: function () {
  1372. this.x = Math.floor( this.x );
  1373. this.y = Math.floor( this.y );
  1374. this.z = Math.floor( this.z );
  1375. return this;
  1376. },
  1377. ceil: function () {
  1378. this.x = Math.ceil( this.x );
  1379. this.y = Math.ceil( this.y );
  1380. this.z = Math.ceil( this.z );
  1381. return this;
  1382. },
  1383. round: function () {
  1384. this.x = Math.round( this.x );
  1385. this.y = Math.round( this.y );
  1386. this.z = Math.round( this.z );
  1387. return this;
  1388. },
  1389. roundToZero: function () {
  1390. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1391. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1392. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1393. return this;
  1394. },
  1395. negate: function () {
  1396. this.x = - this.x;
  1397. this.y = - this.y;
  1398. this.z = - this.z;
  1399. return this;
  1400. },
  1401. dot: function ( v ) {
  1402. return this.x * v.x + this.y * v.y + this.z * v.z;
  1403. },
  1404. lengthSq: function () {
  1405. return this.x * this.x + this.y * this.y + this.z * this.z;
  1406. },
  1407. length: function () {
  1408. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1409. },
  1410. lengthManhattan: function () {
  1411. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1412. },
  1413. normalize: function () {
  1414. return this.divideScalar( this.length() );
  1415. },
  1416. setLength: function ( l ) {
  1417. var oldLength = this.length();
  1418. if ( oldLength !== 0 && l !== oldLength ) {
  1419. this.multiplyScalar( l / oldLength );
  1420. }
  1421. return this;
  1422. },
  1423. lerp: function ( v, alpha ) {
  1424. this.x += ( v.x - this.x ) * alpha;
  1425. this.y += ( v.y - this.y ) * alpha;
  1426. this.z += ( v.z - this.z ) * alpha;
  1427. return this;
  1428. },
  1429. lerpVectors: function ( v1, v2, alpha ) {
  1430. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1431. return this;
  1432. },
  1433. cross: function ( v, w ) {
  1434. if ( w !== undefined ) {
  1435. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1436. return this.crossVectors( v, w );
  1437. }
  1438. var x = this.x, y = this.y, z = this.z;
  1439. this.x = y * v.z - z * v.y;
  1440. this.y = z * v.x - x * v.z;
  1441. this.z = x * v.y - y * v.x;
  1442. return this;
  1443. },
  1444. crossVectors: function ( a, b ) {
  1445. var ax = a.x, ay = a.y, az = a.z;
  1446. var bx = b.x, by = b.y, bz = b.z;
  1447. this.x = ay * bz - az * by;
  1448. this.y = az * bx - ax * bz;
  1449. this.z = ax * by - ay * bx;
  1450. return this;
  1451. },
  1452. projectOnVector: function () {
  1453. var v1, dot;
  1454. return function projectOnVector( vector ) {
  1455. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1456. v1.copy( vector ).normalize();
  1457. dot = this.dot( v1 );
  1458. return this.copy( v1 ).multiplyScalar( dot );
  1459. };
  1460. }(),
  1461. projectOnPlane: function () {
  1462. var v1;
  1463. return function projectOnPlane( planeNormal ) {
  1464. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1465. v1.copy( this ).projectOnVector( planeNormal );
  1466. return this.sub( v1 );
  1467. }
  1468. }(),
  1469. reflect: function () {
  1470. // reflect incident vector off plane orthogonal to normal
  1471. // normal is assumed to have unit length
  1472. var v1;
  1473. return function reflect( normal ) {
  1474. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1475. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1476. }
  1477. }(),
  1478. angleTo: function ( v ) {
  1479. var theta = this.dot( v ) / ( this.length() * v.length() );
  1480. // clamp, to handle numerical problems
  1481. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1482. },
  1483. distanceTo: function ( v ) {
  1484. return Math.sqrt( this.distanceToSquared( v ) );
  1485. },
  1486. distanceToSquared: function ( v ) {
  1487. var dx = this.x - v.x;
  1488. var dy = this.y - v.y;
  1489. var dz = this.z - v.z;
  1490. return dx * dx + dy * dy + dz * dz;
  1491. },
  1492. setEulerFromRotationMatrix: function ( m, order ) {
  1493. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1494. },
  1495. setEulerFromQuaternion: function ( q, order ) {
  1496. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1497. },
  1498. getPositionFromMatrix: function ( m ) {
  1499. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1500. return this.setFromMatrixPosition( m );
  1501. },
  1502. getScaleFromMatrix: function ( m ) {
  1503. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1504. return this.setFromMatrixScale( m );
  1505. },
  1506. getColumnFromMatrix: function ( index, matrix ) {
  1507. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1508. return this.setFromMatrixColumn( index, matrix );
  1509. },
  1510. setFromMatrixPosition: function ( m ) {
  1511. this.x = m.elements[ 12 ];
  1512. this.y = m.elements[ 13 ];
  1513. this.z = m.elements[ 14 ];
  1514. return this;
  1515. },
  1516. setFromMatrixScale: function ( m ) {
  1517. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1518. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1519. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1520. this.x = sx;
  1521. this.y = sy;
  1522. this.z = sz;
  1523. return this;
  1524. },
  1525. setFromMatrixColumn: function ( index, matrix ) {
  1526. var offset = index * 4;
  1527. var me = matrix.elements;
  1528. this.x = me[ offset ];
  1529. this.y = me[ offset + 1 ];
  1530. this.z = me[ offset + 2 ];
  1531. return this;
  1532. },
  1533. equals: function ( v ) {
  1534. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1535. },
  1536. fromArray: function ( array, offset ) {
  1537. if ( offset === undefined ) offset = 0;
  1538. this.x = array[ offset ];
  1539. this.y = array[ offset + 1 ];
  1540. this.z = array[ offset + 2 ];
  1541. return this;
  1542. },
  1543. toArray: function ( array, offset ) {
  1544. if ( array === undefined ) array = [];
  1545. if ( offset === undefined ) offset = 0;
  1546. array[ offset ] = this.x;
  1547. array[ offset + 1 ] = this.y;
  1548. array[ offset + 2 ] = this.z;
  1549. return array;
  1550. },
  1551. fromAttribute: function ( attribute, index, offset ) {
  1552. if ( offset === undefined ) offset = 0;
  1553. index = index * attribute.itemSize + offset;
  1554. this.x = attribute.array[ index ];
  1555. this.y = attribute.array[ index + 1 ];
  1556. this.z = attribute.array[ index + 2 ];
  1557. return this;
  1558. },
  1559. clone: function () {
  1560. return new THREE.Vector3( this.x, this.y, this.z );
  1561. }
  1562. };
  1563. // File:src/math/Vector4.js
  1564. /**
  1565. * @author supereggbert / http://www.paulbrunt.co.uk/
  1566. * @author philogb / http://blog.thejit.org/
  1567. * @author mikael emtinger / http://gomo.se/
  1568. * @author egraether / http://egraether.com/
  1569. * @author WestLangley / http://github.com/WestLangley
  1570. */
  1571. THREE.Vector4 = function ( x, y, z, w ) {
  1572. this.x = x || 0;
  1573. this.y = y || 0;
  1574. this.z = z || 0;
  1575. this.w = ( w !== undefined ) ? w : 1;
  1576. };
  1577. THREE.Vector4.prototype = {
  1578. constructor: THREE.Vector4,
  1579. set: function ( x, y, z, w ) {
  1580. this.x = x;
  1581. this.y = y;
  1582. this.z = z;
  1583. this.w = w;
  1584. return this;
  1585. },
  1586. setX: function ( x ) {
  1587. this.x = x;
  1588. return this;
  1589. },
  1590. setY: function ( y ) {
  1591. this.y = y;
  1592. return this;
  1593. },
  1594. setZ: function ( z ) {
  1595. this.z = z;
  1596. return this;
  1597. },
  1598. setW: function ( w ) {
  1599. this.w = w;
  1600. return this;
  1601. },
  1602. setComponent: function ( index, value ) {
  1603. switch ( index ) {
  1604. case 0: this.x = value; break;
  1605. case 1: this.y = value; break;
  1606. case 2: this.z = value; break;
  1607. case 3: this.w = value; break;
  1608. default: throw new Error( 'index is out of range: ' + index );
  1609. }
  1610. },
  1611. getComponent: function ( index ) {
  1612. switch ( index ) {
  1613. case 0: return this.x;
  1614. case 1: return this.y;
  1615. case 2: return this.z;
  1616. case 3: return this.w;
  1617. default: throw new Error( 'index is out of range: ' + index );
  1618. }
  1619. },
  1620. copy: function ( v ) {
  1621. this.x = v.x;
  1622. this.y = v.y;
  1623. this.z = v.z;
  1624. this.w = ( v.w !== undefined ) ? v.w : 1;
  1625. return this;
  1626. },
  1627. add: function ( v, w ) {
  1628. if ( w !== undefined ) {
  1629. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1630. return this.addVectors( v, w );
  1631. }
  1632. this.x += v.x;
  1633. this.y += v.y;
  1634. this.z += v.z;
  1635. this.w += v.w;
  1636. return this;
  1637. },
  1638. addScalar: function ( s ) {
  1639. this.x += s;
  1640. this.y += s;
  1641. this.z += s;
  1642. this.w += s;
  1643. return this;
  1644. },
  1645. addVectors: function ( a, b ) {
  1646. this.x = a.x + b.x;
  1647. this.y = a.y + b.y;
  1648. this.z = a.z + b.z;
  1649. this.w = a.w + b.w;
  1650. return this;
  1651. },
  1652. addScaledVector: function ( v, s ) {
  1653. this.x += v.x * s;
  1654. this.y += v.y * s;
  1655. this.z += v.z * s;
  1656. this.w += v.w * s;
  1657. return this;
  1658. },
  1659. sub: function ( v, w ) {
  1660. if ( w !== undefined ) {
  1661. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1662. return this.subVectors( v, w );
  1663. }
  1664. this.x -= v.x;
  1665. this.y -= v.y;
  1666. this.z -= v.z;
  1667. this.w -= v.w;
  1668. return this;
  1669. },
  1670. subScalar: function ( s ) {
  1671. this.x -= s;
  1672. this.y -= s;
  1673. this.z -= s;
  1674. this.w -= s;
  1675. return this;
  1676. },
  1677. subVectors: function ( a, b ) {
  1678. this.x = a.x - b.x;
  1679. this.y = a.y - b.y;
  1680. this.z = a.z - b.z;
  1681. this.w = a.w - b.w;
  1682. return this;
  1683. },
  1684. multiplyScalar: function ( scalar ) {
  1685. this.x *= scalar;
  1686. this.y *= scalar;
  1687. this.z *= scalar;
  1688. this.w *= scalar;
  1689. return this;
  1690. },
  1691. applyMatrix4: function ( m ) {
  1692. var x = this.x;
  1693. var y = this.y;
  1694. var z = this.z;
  1695. var w = this.w;
  1696. var e = m.elements;
  1697. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1698. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1699. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1700. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1701. return this;
  1702. },
  1703. divideScalar: function ( scalar ) {
  1704. if ( scalar !== 0 ) {
  1705. var invScalar = 1 / scalar;
  1706. this.x *= invScalar;
  1707. this.y *= invScalar;
  1708. this.z *= invScalar;
  1709. this.w *= invScalar;
  1710. } else {
  1711. this.x = 0;
  1712. this.y = 0;
  1713. this.z = 0;
  1714. this.w = 1;
  1715. }
  1716. return this;
  1717. },
  1718. setAxisAngleFromQuaternion: function ( q ) {
  1719. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1720. // q is assumed to be normalized
  1721. this.w = 2 * Math.acos( q.w );
  1722. var s = Math.sqrt( 1 - q.w * q.w );
  1723. if ( s < 0.0001 ) {
  1724. this.x = 1;
  1725. this.y = 0;
  1726. this.z = 0;
  1727. } else {
  1728. this.x = q.x / s;
  1729. this.y = q.y / s;
  1730. this.z = q.z / s;
  1731. }
  1732. return this;
  1733. },
  1734. setAxisAngleFromRotationMatrix: function ( m ) {
  1735. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1736. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1737. var angle, x, y, z, // variables for result
  1738. epsilon = 0.01, // margin to allow for rounding errors
  1739. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1740. te = m.elements,
  1741. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1742. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1743. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1744. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1745. && ( Math.abs( m13 - m31 ) < epsilon )
  1746. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1747. // singularity found
  1748. // first check for identity matrix which must have +1 for all terms
  1749. // in leading diagonal and zero in other terms
  1750. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1751. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1752. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1753. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1754. // this singularity is identity matrix so angle = 0
  1755. this.set( 1, 0, 0, 0 );
  1756. return this; // zero angle, arbitrary axis
  1757. }
  1758. // otherwise this singularity is angle = 180
  1759. angle = Math.PI;
  1760. var xx = ( m11 + 1 ) / 2;
  1761. var yy = ( m22 + 1 ) / 2;
  1762. var zz = ( m33 + 1 ) / 2;
  1763. var xy = ( m12 + m21 ) / 4;
  1764. var xz = ( m13 + m31 ) / 4;
  1765. var yz = ( m23 + m32 ) / 4;
  1766. if ( ( xx > yy ) && ( xx > zz ) ) {
  1767. // m11 is the largest diagonal term
  1768. if ( xx < epsilon ) {
  1769. x = 0;
  1770. y = 0.707106781;
  1771. z = 0.707106781;
  1772. } else {
  1773. x = Math.sqrt( xx );
  1774. y = xy / x;
  1775. z = xz / x;
  1776. }
  1777. } else if ( yy > zz ) {
  1778. // m22 is the largest diagonal term
  1779. if ( yy < epsilon ) {
  1780. x = 0.707106781;
  1781. y = 0;
  1782. z = 0.707106781;
  1783. } else {
  1784. y = Math.sqrt( yy );
  1785. x = xy / y;
  1786. z = yz / y;
  1787. }
  1788. } else {
  1789. // m33 is the largest diagonal term so base result on this
  1790. if ( zz < epsilon ) {
  1791. x = 0.707106781;
  1792. y = 0.707106781;
  1793. z = 0;
  1794. } else {
  1795. z = Math.sqrt( zz );
  1796. x = xz / z;
  1797. y = yz / z;
  1798. }
  1799. }
  1800. this.set( x, y, z, angle );
  1801. return this; // return 180 deg rotation
  1802. }
  1803. // as we have reached here there are no singularities so we can handle normally
  1804. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1805. + ( m13 - m31 ) * ( m13 - m31 )
  1806. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1807. if ( Math.abs( s ) < 0.001 ) s = 1;
  1808. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1809. // caught by singularity test above, but I've left it in just in case
  1810. this.x = ( m32 - m23 ) / s;
  1811. this.y = ( m13 - m31 ) / s;
  1812. this.z = ( m21 - m12 ) / s;
  1813. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1814. return this;
  1815. },
  1816. min: function ( v ) {
  1817. if ( this.x > v.x ) {
  1818. this.x = v.x;
  1819. }
  1820. if ( this.y > v.y ) {
  1821. this.y = v.y;
  1822. }
  1823. if ( this.z > v.z ) {
  1824. this.z = v.z;
  1825. }
  1826. if ( this.w > v.w ) {
  1827. this.w = v.w;
  1828. }
  1829. return this;
  1830. },
  1831. max: function ( v ) {
  1832. if ( this.x < v.x ) {
  1833. this.x = v.x;
  1834. }
  1835. if ( this.y < v.y ) {
  1836. this.y = v.y;
  1837. }
  1838. if ( this.z < v.z ) {
  1839. this.z = v.z;
  1840. }
  1841. if ( this.w < v.w ) {
  1842. this.w = v.w;
  1843. }
  1844. return this;
  1845. },
  1846. clamp: function ( min, max ) {
  1847. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1848. if ( this.x < min.x ) {
  1849. this.x = min.x;
  1850. } else if ( this.x > max.x ) {
  1851. this.x = max.x;
  1852. }
  1853. if ( this.y < min.y ) {
  1854. this.y = min.y;
  1855. } else if ( this.y > max.y ) {
  1856. this.y = max.y;
  1857. }
  1858. if ( this.z < min.z ) {
  1859. this.z = min.z;
  1860. } else if ( this.z > max.z ) {
  1861. this.z = max.z;
  1862. }
  1863. if ( this.w < min.w ) {
  1864. this.w = min.w;
  1865. } else if ( this.w > max.w ) {
  1866. this.w = max.w;
  1867. }
  1868. return this;
  1869. },
  1870. clampScalar: function () {
  1871. var min, max;
  1872. return function clampScalar( minVal, maxVal ) {
  1873. if ( min === undefined ) {
  1874. min = new THREE.Vector4();
  1875. max = new THREE.Vector4();
  1876. }
  1877. min.set( minVal, minVal, minVal, minVal );
  1878. max.set( maxVal, maxVal, maxVal, maxVal );
  1879. return this.clamp( min, max );
  1880. };
  1881. }(),
  1882. floor: function () {
  1883. this.x = Math.floor( this.x );
  1884. this.y = Math.floor( this.y );
  1885. this.z = Math.floor( this.z );
  1886. this.w = Math.floor( this.w );
  1887. return this;
  1888. },
  1889. ceil: function () {
  1890. this.x = Math.ceil( this.x );
  1891. this.y = Math.ceil( this.y );
  1892. this.z = Math.ceil( this.z );
  1893. this.w = Math.ceil( this.w );
  1894. return this;
  1895. },
  1896. round: function () {
  1897. this.x = Math.round( this.x );
  1898. this.y = Math.round( this.y );
  1899. this.z = Math.round( this.z );
  1900. this.w = Math.round( this.w );
  1901. return this;
  1902. },
  1903. roundToZero: function () {
  1904. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1905. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1906. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1907. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1908. return this;
  1909. },
  1910. negate: function () {
  1911. this.x = - this.x;
  1912. this.y = - this.y;
  1913. this.z = - this.z;
  1914. this.w = - this.w;
  1915. return this;
  1916. },
  1917. dot: function ( v ) {
  1918. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1919. },
  1920. lengthSq: function () {
  1921. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1922. },
  1923. length: function () {
  1924. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1925. },
  1926. lengthManhattan: function () {
  1927. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1928. },
  1929. normalize: function () {
  1930. return this.divideScalar( this.length() );
  1931. },
  1932. setLength: function ( l ) {
  1933. var oldLength = this.length();
  1934. if ( oldLength !== 0 && l !== oldLength ) {
  1935. this.multiplyScalar( l / oldLength );
  1936. }
  1937. return this;
  1938. },
  1939. lerp: function ( v, alpha ) {
  1940. this.x += ( v.x - this.x ) * alpha;
  1941. this.y += ( v.y - this.y ) * alpha;
  1942. this.z += ( v.z - this.z ) * alpha;
  1943. this.w += ( v.w - this.w ) * alpha;
  1944. return this;
  1945. },
  1946. lerpVectors: function ( v1, v2, alpha ) {
  1947. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1948. return this;
  1949. },
  1950. equals: function ( v ) {
  1951. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1952. },
  1953. fromArray: function ( array, offset ) {
  1954. if ( offset === undefined ) offset = 0;
  1955. this.x = array[ offset ];
  1956. this.y = array[ offset + 1 ];
  1957. this.z = array[ offset + 2 ];
  1958. this.w = array[ offset + 3 ];
  1959. return this;
  1960. },
  1961. toArray: function ( array, offset ) {
  1962. if ( array === undefined ) array = [];
  1963. if ( offset === undefined ) offset = 0;
  1964. array[ offset ] = this.x;
  1965. array[ offset + 1 ] = this.y;
  1966. array[ offset + 2 ] = this.z;
  1967. array[ offset + 3 ] = this.w;
  1968. return array;
  1969. },
  1970. fromAttribute: function ( attribute, index, offset ) {
  1971. if ( offset === undefined ) offset = 0;
  1972. index = index * attribute.itemSize + offset;
  1973. this.x = attribute.array[ index ];
  1974. this.y = attribute.array[ index + 1 ];
  1975. this.z = attribute.array[ index + 2 ];
  1976. this.w = attribute.array[ index + 3 ];
  1977. return this;
  1978. },
  1979. clone: function () {
  1980. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  1981. }
  1982. };
  1983. // File:src/math/Euler.js
  1984. /**
  1985. * @author mrdoob / http://mrdoob.com/
  1986. * @author WestLangley / http://github.com/WestLangley
  1987. * @author bhouston / http://exocortex.com
  1988. */
  1989. THREE.Euler = function ( x, y, z, order ) {
  1990. this._x = x || 0;
  1991. this._y = y || 0;
  1992. this._z = z || 0;
  1993. this._order = order || THREE.Euler.DefaultOrder;
  1994. };
  1995. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1996. THREE.Euler.DefaultOrder = 'XYZ';
  1997. THREE.Euler.prototype = {
  1998. constructor: THREE.Euler,
  1999. get x () {
  2000. return this._x;
  2001. },
  2002. set x ( value ) {
  2003. this._x = value;
  2004. this.onChangeCallback();
  2005. },
  2006. get y () {
  2007. return this._y;
  2008. },
  2009. set y ( value ) {
  2010. this._y = value;
  2011. this.onChangeCallback();
  2012. },
  2013. get z () {
  2014. return this._z;
  2015. },
  2016. set z ( value ) {
  2017. this._z = value;
  2018. this.onChangeCallback();
  2019. },
  2020. get order () {
  2021. return this._order;
  2022. },
  2023. set order ( value ) {
  2024. this._order = value;
  2025. this.onChangeCallback();
  2026. },
  2027. set: function ( x, y, z, order ) {
  2028. this._x = x;
  2029. this._y = y;
  2030. this._z = z;
  2031. this._order = order || this._order;
  2032. this.onChangeCallback();
  2033. return this;
  2034. },
  2035. copy: function ( euler ) {
  2036. this._x = euler._x;
  2037. this._y = euler._y;
  2038. this._z = euler._z;
  2039. this._order = euler._order;
  2040. this.onChangeCallback();
  2041. return this;
  2042. },
  2043. setFromRotationMatrix: function ( m, order, update ) {
  2044. var clamp = THREE.Math.clamp;
  2045. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2046. var te = m.elements;
  2047. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2048. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2049. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2050. order = order || this._order;
  2051. if ( order === 'XYZ' ) {
  2052. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2053. if ( Math.abs( m13 ) < 0.99999 ) {
  2054. this._x = Math.atan2( - m23, m33 );
  2055. this._z = Math.atan2( - m12, m11 );
  2056. } else {
  2057. this._x = Math.atan2( m32, m22 );
  2058. this._z = 0;
  2059. }
  2060. } else if ( order === 'YXZ' ) {
  2061. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2062. if ( Math.abs( m23 ) < 0.99999 ) {
  2063. this._y = Math.atan2( m13, m33 );
  2064. this._z = Math.atan2( m21, m22 );
  2065. } else {
  2066. this._y = Math.atan2( - m31, m11 );
  2067. this._z = 0;
  2068. }
  2069. } else if ( order === 'ZXY' ) {
  2070. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2071. if ( Math.abs( m32 ) < 0.99999 ) {
  2072. this._y = Math.atan2( - m31, m33 );
  2073. this._z = Math.atan2( - m12, m22 );
  2074. } else {
  2075. this._y = 0;
  2076. this._z = Math.atan2( m21, m11 );
  2077. }
  2078. } else if ( order === 'ZYX' ) {
  2079. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2080. if ( Math.abs( m31 ) < 0.99999 ) {
  2081. this._x = Math.atan2( m32, m33 );
  2082. this._z = Math.atan2( m21, m11 );
  2083. } else {
  2084. this._x = 0;
  2085. this._z = Math.atan2( - m12, m22 );
  2086. }
  2087. } else if ( order === 'YZX' ) {
  2088. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2089. if ( Math.abs( m21 ) < 0.99999 ) {
  2090. this._x = Math.atan2( - m23, m22 );
  2091. this._y = Math.atan2( - m31, m11 );
  2092. } else {
  2093. this._x = 0;
  2094. this._y = Math.atan2( m13, m33 );
  2095. }
  2096. } else if ( order === 'XZY' ) {
  2097. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2098. if ( Math.abs( m12 ) < 0.99999 ) {
  2099. this._x = Math.atan2( m32, m22 );
  2100. this._y = Math.atan2( m13, m11 );
  2101. } else {
  2102. this._x = Math.atan2( - m23, m33 );
  2103. this._y = 0;
  2104. }
  2105. } else {
  2106. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2107. }
  2108. this._order = order;
  2109. if ( update !== false ) this.onChangeCallback();
  2110. return this;
  2111. },
  2112. setFromQuaternion: function () {
  2113. var matrix;
  2114. return function ( q, order, update ) {
  2115. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2116. matrix.makeRotationFromQuaternion( q );
  2117. this.setFromRotationMatrix( matrix, order, update );
  2118. return this;
  2119. };
  2120. }(),
  2121. setFromVector3: function ( v, order ) {
  2122. return this.set( v.x, v.y, v.z, order || this._order );
  2123. },
  2124. reorder: function () {
  2125. // WARNING: this discards revolution information -bhouston
  2126. var q = new THREE.Quaternion();
  2127. return function ( newOrder ) {
  2128. q.setFromEuler( this );
  2129. this.setFromQuaternion( q, newOrder );
  2130. };
  2131. }(),
  2132. equals: function ( euler ) {
  2133. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2134. },
  2135. fromArray: function ( array ) {
  2136. this._x = array[ 0 ];
  2137. this._y = array[ 1 ];
  2138. this._z = array[ 2 ];
  2139. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2140. this.onChangeCallback();
  2141. return this;
  2142. },
  2143. toArray: function ( array, offset ) {
  2144. if ( array === undefined ) array = [];
  2145. if ( offset === undefined ) offset = 0;
  2146. array[ offset ] = this._x;
  2147. array[ offset + 1 ] = this._y;
  2148. array[ offset + 2 ] = this._z;
  2149. array[ offset + 3 ] = this._order;
  2150. return array;
  2151. },
  2152. toVector3: function ( optionalResult ) {
  2153. if ( optionalResult ) {
  2154. return optionalResult.set( this._x, this._y, this._z );
  2155. } else {
  2156. return new THREE.Vector3( this._x, this._y, this._z );
  2157. }
  2158. },
  2159. onChange: function ( callback ) {
  2160. this.onChangeCallback = callback;
  2161. return this;
  2162. },
  2163. onChangeCallback: function () {},
  2164. clone: function () {
  2165. return new THREE.Euler( this._x, this._y, this._z, this._order );
  2166. }
  2167. };
  2168. // File:src/math/Line3.js
  2169. /**
  2170. * @author bhouston / http://exocortex.com
  2171. */
  2172. THREE.Line3 = function ( start, end ) {
  2173. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2174. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2175. };
  2176. THREE.Line3.prototype = {
  2177. constructor: THREE.Line3,
  2178. set: function ( start, end ) {
  2179. this.start.copy( start );
  2180. this.end.copy( end );
  2181. return this;
  2182. },
  2183. copy: function ( line ) {
  2184. this.start.copy( line.start );
  2185. this.end.copy( line.end );
  2186. return this;
  2187. },
  2188. center: function ( optionalTarget ) {
  2189. var result = optionalTarget || new THREE.Vector3();
  2190. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2191. },
  2192. delta: function ( optionalTarget ) {
  2193. var result = optionalTarget || new THREE.Vector3();
  2194. return result.subVectors( this.end, this.start );
  2195. },
  2196. distanceSq: function () {
  2197. return this.start.distanceToSquared( this.end );
  2198. },
  2199. distance: function () {
  2200. return this.start.distanceTo( this.end );
  2201. },
  2202. at: function ( t, optionalTarget ) {
  2203. var result = optionalTarget || new THREE.Vector3();
  2204. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2205. },
  2206. closestPointToPointParameter: function () {
  2207. var startP = new THREE.Vector3();
  2208. var startEnd = new THREE.Vector3();
  2209. return function ( point, clampToLine ) {
  2210. startP.subVectors( point, this.start );
  2211. startEnd.subVectors( this.end, this.start );
  2212. var startEnd2 = startEnd.dot( startEnd );
  2213. var startEnd_startP = startEnd.dot( startP );
  2214. var t = startEnd_startP / startEnd2;
  2215. if ( clampToLine ) {
  2216. t = THREE.Math.clamp( t, 0, 1 );
  2217. }
  2218. return t;
  2219. };
  2220. }(),
  2221. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2222. var t = this.closestPointToPointParameter( point, clampToLine );
  2223. var result = optionalTarget || new THREE.Vector3();
  2224. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2225. },
  2226. applyMatrix4: function ( matrix ) {
  2227. this.start.applyMatrix4( matrix );
  2228. this.end.applyMatrix4( matrix );
  2229. return this;
  2230. },
  2231. equals: function ( line ) {
  2232. return line.start.equals( this.start ) && line.end.equals( this.end );
  2233. },
  2234. clone: function () {
  2235. return new THREE.Line3().copy( this );
  2236. }
  2237. };
  2238. // File:src/math/Box2.js
  2239. /**
  2240. * @author bhouston / http://exocortex.com
  2241. */
  2242. THREE.Box2 = function ( min, max ) {
  2243. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2244. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2245. };
  2246. THREE.Box2.prototype = {
  2247. constructor: THREE.Box2,
  2248. set: function ( min, max ) {
  2249. this.min.copy( min );
  2250. this.max.copy( max );
  2251. return this;
  2252. },
  2253. setFromPoints: function ( points ) {
  2254. this.makeEmpty();
  2255. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2256. this.expandByPoint( points[ i ] )
  2257. }
  2258. return this;
  2259. },
  2260. setFromCenterAndSize: function () {
  2261. var v1 = new THREE.Vector2();
  2262. return function ( center, size ) {
  2263. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2264. this.min.copy( center ).sub( halfSize );
  2265. this.max.copy( center ).add( halfSize );
  2266. return this;
  2267. };
  2268. }(),
  2269. copy: function ( box ) {
  2270. this.min.copy( box.min );
  2271. this.max.copy( box.max );
  2272. return this;
  2273. },
  2274. makeEmpty: function () {
  2275. this.min.x = this.min.y = Infinity;
  2276. this.max.x = this.max.y = - Infinity;
  2277. return this;
  2278. },
  2279. empty: function () {
  2280. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2281. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2282. },
  2283. center: function ( optionalTarget ) {
  2284. var result = optionalTarget || new THREE.Vector2();
  2285. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2286. },
  2287. size: function ( optionalTarget ) {
  2288. var result = optionalTarget || new THREE.Vector2();
  2289. return result.subVectors( this.max, this.min );
  2290. },
  2291. expandByPoint: function ( point ) {
  2292. this.min.min( point );
  2293. this.max.max( point );
  2294. return this;
  2295. },
  2296. expandByVector: function ( vector ) {
  2297. this.min.sub( vector );
  2298. this.max.add( vector );
  2299. return this;
  2300. },
  2301. expandByScalar: function ( scalar ) {
  2302. this.min.addScalar( - scalar );
  2303. this.max.addScalar( scalar );
  2304. return this;
  2305. },
  2306. containsPoint: function ( point ) {
  2307. if ( point.x < this.min.x || point.x > this.max.x ||
  2308. point.y < this.min.y || point.y > this.max.y ) {
  2309. return false;
  2310. }
  2311. return true;
  2312. },
  2313. containsBox: function ( box ) {
  2314. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2315. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2316. return true;
  2317. }
  2318. return false;
  2319. },
  2320. getParameter: function ( point, optionalTarget ) {
  2321. // This can potentially have a divide by zero if the box
  2322. // has a size dimension of 0.
  2323. var result = optionalTarget || new THREE.Vector2();
  2324. return result.set(
  2325. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2326. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2327. );
  2328. },
  2329. isIntersectionBox: function ( box ) {
  2330. // using 6 splitting planes to rule out intersections.
  2331. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2332. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2333. return false;
  2334. }
  2335. return true;
  2336. },
  2337. clampPoint: function ( point, optionalTarget ) {
  2338. var result = optionalTarget || new THREE.Vector2();
  2339. return result.copy( point ).clamp( this.min, this.max );
  2340. },
  2341. distanceToPoint: function () {
  2342. var v1 = new THREE.Vector2();
  2343. return function ( point ) {
  2344. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2345. return clampedPoint.sub( point ).length();
  2346. };
  2347. }(),
  2348. intersect: function ( box ) {
  2349. this.min.max( box.min );
  2350. this.max.min( box.max );
  2351. return this;
  2352. },
  2353. union: function ( box ) {
  2354. this.min.min( box.min );
  2355. this.max.max( box.max );
  2356. return this;
  2357. },
  2358. translate: function ( offset ) {
  2359. this.min.add( offset );
  2360. this.max.add( offset );
  2361. return this;
  2362. },
  2363. equals: function ( box ) {
  2364. return box.min.equals( this.min ) && box.max.equals( this.max );
  2365. },
  2366. clone: function () {
  2367. return new THREE.Box2().copy( this );
  2368. }
  2369. };
  2370. // File:src/math/Box3.js
  2371. /**
  2372. * @author bhouston / http://exocortex.com
  2373. * @author WestLangley / http://github.com/WestLangley
  2374. */
  2375. THREE.Box3 = function ( min, max ) {
  2376. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2377. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2378. };
  2379. THREE.Box3.prototype = {
  2380. constructor: THREE.Box3,
  2381. set: function ( min, max ) {
  2382. this.min.copy( min );
  2383. this.max.copy( max );
  2384. return this;
  2385. },
  2386. setFromPoints: function ( points ) {
  2387. this.makeEmpty();
  2388. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2389. this.expandByPoint( points[ i ] );
  2390. }
  2391. return this;
  2392. },
  2393. setFromCenterAndSize: function () {
  2394. var v1 = new THREE.Vector3();
  2395. return function ( center, size ) {
  2396. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2397. this.min.copy( center ).sub( halfSize );
  2398. this.max.copy( center ).add( halfSize );
  2399. return this;
  2400. };
  2401. }(),
  2402. setFromObject: function () {
  2403. // Computes the world-axis-aligned bounding box of an object (including its children),
  2404. // accounting for both the object's, and children's, world transforms
  2405. var v1 = new THREE.Vector3();
  2406. return function ( object ) {
  2407. var scope = this;
  2408. object.updateMatrixWorld( true );
  2409. this.makeEmpty();
  2410. object.traverse( function ( node ) {
  2411. var geometry = node.geometry;
  2412. if ( geometry !== undefined ) {
  2413. if ( geometry instanceof THREE.Geometry ) {
  2414. var vertices = geometry.vertices;
  2415. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2416. v1.copy( vertices[ i ] );
  2417. v1.applyMatrix4( node.matrixWorld );
  2418. scope.expandByPoint( v1 );
  2419. }
  2420. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2421. var positions = geometry.attributes[ 'position' ].array;
  2422. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2423. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2424. v1.applyMatrix4( node.matrixWorld );
  2425. scope.expandByPoint( v1 );
  2426. }
  2427. }
  2428. }
  2429. } );
  2430. return this;
  2431. };
  2432. }(),
  2433. copy: function ( box ) {
  2434. this.min.copy( box.min );
  2435. this.max.copy( box.max );
  2436. return this;
  2437. },
  2438. makeEmpty: function () {
  2439. this.min.x = this.min.y = this.min.z = Infinity;
  2440. this.max.x = this.max.y = this.max.z = - Infinity;
  2441. return this;
  2442. },
  2443. empty: function () {
  2444. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2445. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2446. },
  2447. center: function ( optionalTarget ) {
  2448. var result = optionalTarget || new THREE.Vector3();
  2449. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2450. },
  2451. size: function ( optionalTarget ) {
  2452. var result = optionalTarget || new THREE.Vector3();
  2453. return result.subVectors( this.max, this.min );
  2454. },
  2455. expandByPoint: function ( point ) {
  2456. this.min.min( point );
  2457. this.max.max( point );
  2458. return this;
  2459. },
  2460. expandByVector: function ( vector ) {
  2461. this.min.sub( vector );
  2462. this.max.add( vector );
  2463. return this;
  2464. },
  2465. expandByScalar: function ( scalar ) {
  2466. this.min.addScalar( - scalar );
  2467. this.max.addScalar( scalar );
  2468. return this;
  2469. },
  2470. containsPoint: function ( point ) {
  2471. if ( point.x < this.min.x || point.x > this.max.x ||
  2472. point.y < this.min.y || point.y > this.max.y ||
  2473. point.z < this.min.z || point.z > this.max.z ) {
  2474. return false;
  2475. }
  2476. return true;
  2477. },
  2478. containsBox: function ( box ) {
  2479. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2480. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2481. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2482. return true;
  2483. }
  2484. return false;
  2485. },
  2486. getParameter: function ( point, optionalTarget ) {
  2487. // This can potentially have a divide by zero if the box
  2488. // has a size dimension of 0.
  2489. var result = optionalTarget || new THREE.Vector3();
  2490. return result.set(
  2491. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2492. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2493. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2494. );
  2495. },
  2496. isIntersectionBox: function ( box ) {
  2497. // using 6 splitting planes to rule out intersections.
  2498. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2499. box.max.y < this.min.y || box.min.y > this.max.y ||
  2500. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2501. return false;
  2502. }
  2503. return true;
  2504. },
  2505. clampPoint: function ( point, optionalTarget ) {
  2506. var result = optionalTarget || new THREE.Vector3();
  2507. return result.copy( point ).clamp( this.min, this.max );
  2508. },
  2509. distanceToPoint: function () {
  2510. var v1 = new THREE.Vector3();
  2511. return function ( point ) {
  2512. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2513. return clampedPoint.sub( point ).length();
  2514. };
  2515. }(),
  2516. getBoundingSphere: function () {
  2517. var v1 = new THREE.Vector3();
  2518. return function ( optionalTarget ) {
  2519. var result = optionalTarget || new THREE.Sphere();
  2520. result.center = this.center();
  2521. result.radius = this.size( v1 ).length() * 0.5;
  2522. return result;
  2523. };
  2524. }(),
  2525. intersect: function ( box ) {
  2526. this.min.max( box.min );
  2527. this.max.min( box.max );
  2528. return this;
  2529. },
  2530. union: function ( box ) {
  2531. this.min.min( box.min );
  2532. this.max.max( box.max );
  2533. return this;
  2534. },
  2535. applyMatrix4: function () {
  2536. var points = [
  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. new THREE.Vector3(),
  2544. new THREE.Vector3()
  2545. ];
  2546. return function ( matrix ) {
  2547. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2548. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2549. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2550. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2551. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2552. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2553. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2554. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2555. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2556. this.makeEmpty();
  2557. this.setFromPoints( points );
  2558. return this;
  2559. };
  2560. }(),
  2561. translate: function ( offset ) {
  2562. this.min.add( offset );
  2563. this.max.add( offset );
  2564. return this;
  2565. },
  2566. equals: function ( box ) {
  2567. return box.min.equals( this.min ) && box.max.equals( this.max );
  2568. },
  2569. clone: function () {
  2570. return new THREE.Box3().copy( this );
  2571. }
  2572. };
  2573. // File:src/math/Matrix3.js
  2574. /**
  2575. * @author alteredq / http://alteredqualia.com/
  2576. * @author WestLangley / http://github.com/WestLangley
  2577. * @author bhouston / http://exocortex.com
  2578. */
  2579. THREE.Matrix3 = function () {
  2580. this.elements = new Float32Array( [
  2581. 1, 0, 0,
  2582. 0, 1, 0,
  2583. 0, 0, 1
  2584. ] );
  2585. if ( arguments.length > 0 ) {
  2586. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2587. }
  2588. };
  2589. THREE.Matrix3.prototype = {
  2590. constructor: THREE.Matrix3,
  2591. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2592. var te = this.elements;
  2593. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2594. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2595. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2596. return this;
  2597. },
  2598. identity: function () {
  2599. this.set(
  2600. 1, 0, 0,
  2601. 0, 1, 0,
  2602. 0, 0, 1
  2603. );
  2604. return this;
  2605. },
  2606. copy: function ( m ) {
  2607. var me = m.elements;
  2608. this.set(
  2609. me[ 0 ], me[ 3 ], me[ 6 ],
  2610. me[ 1 ], me[ 4 ], me[ 7 ],
  2611. me[ 2 ], me[ 5 ], me[ 8 ]
  2612. );
  2613. return this;
  2614. },
  2615. multiplyVector3: function ( vector ) {
  2616. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2617. return vector.applyMatrix3( this );
  2618. },
  2619. multiplyVector3Array: function ( a ) {
  2620. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2621. return this.applyToVector3Array( a );
  2622. },
  2623. applyToVector3Array: function () {
  2624. var v1;
  2625. return function ( array, offset, length ) {
  2626. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2627. if ( offset === undefined ) offset = 0;
  2628. if ( length === undefined ) length = array.length;
  2629. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2630. v1.fromArray( array, j );
  2631. v1.applyMatrix3( this );
  2632. v1.toArray( array, j );
  2633. }
  2634. return array;
  2635. };
  2636. }(),
  2637. applyToBuffer: function () {
  2638. var v1;
  2639. return function applyToBuffer( buffer, offset, length ) {
  2640. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2641. if ( offset === undefined ) offset = 0;
  2642. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2643. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2644. v1.x = buffer.getX( j );
  2645. v1.y = buffer.getY( j );
  2646. v1.z = buffer.getZ( j );
  2647. v1.applyMatrix3( this );
  2648. buffer.setXYZ( v1.x, v1.y, v1.z );
  2649. }
  2650. return buffer;
  2651. };
  2652. }(),
  2653. multiplyScalar: function ( s ) {
  2654. var te = this.elements;
  2655. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2656. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2657. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2658. return this;
  2659. },
  2660. determinant: function () {
  2661. var te = this.elements;
  2662. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2663. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2664. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2665. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2666. },
  2667. getInverse: function ( matrix, throwOnInvertible ) {
  2668. // input: THREE.Matrix4
  2669. // ( based on http://code.google.com/p/webgl-mjs/ )
  2670. var me = matrix.elements;
  2671. var te = this.elements;
  2672. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2673. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2674. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2675. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2676. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2677. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2678. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2679. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2680. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2681. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2682. // no inverse
  2683. if ( det === 0 ) {
  2684. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2685. if ( throwOnInvertible || false ) {
  2686. throw new Error( msg );
  2687. } else {
  2688. console.warn( msg );
  2689. }
  2690. this.identity();
  2691. return this;
  2692. }
  2693. this.multiplyScalar( 1.0 / det );
  2694. return this;
  2695. },
  2696. transpose: function () {
  2697. var tmp, m = this.elements;
  2698. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2699. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2700. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2701. return this;
  2702. },
  2703. flattenToArrayOffset: function ( array, offset ) {
  2704. var te = this.elements;
  2705. array[ offset ] = te[ 0 ];
  2706. array[ offset + 1 ] = te[ 1 ];
  2707. array[ offset + 2 ] = te[ 2 ];
  2708. array[ offset + 3 ] = te[ 3 ];
  2709. array[ offset + 4 ] = te[ 4 ];
  2710. array[ offset + 5 ] = te[ 5 ];
  2711. array[ offset + 6 ] = te[ 6 ];
  2712. array[ offset + 7 ] = te[ 7 ];
  2713. array[ offset + 8 ] = te[ 8 ];
  2714. return array;
  2715. },
  2716. getNormalMatrix: function ( m ) {
  2717. // input: THREE.Matrix4
  2718. this.getInverse( m ).transpose();
  2719. return this;
  2720. },
  2721. transposeIntoArray: function ( r ) {
  2722. var m = this.elements;
  2723. r[ 0 ] = m[ 0 ];
  2724. r[ 1 ] = m[ 3 ];
  2725. r[ 2 ] = m[ 6 ];
  2726. r[ 3 ] = m[ 1 ];
  2727. r[ 4 ] = m[ 4 ];
  2728. r[ 5 ] = m[ 7 ];
  2729. r[ 6 ] = m[ 2 ];
  2730. r[ 7 ] = m[ 5 ];
  2731. r[ 8 ] = m[ 8 ];
  2732. return this;
  2733. },
  2734. fromArray: function ( array ) {
  2735. this.elements.set( array );
  2736. return this;
  2737. },
  2738. toArray: function () {
  2739. var te = this.elements;
  2740. return [
  2741. te[ 0 ], te[ 1 ], te[ 2 ],
  2742. te[ 3 ], te[ 4 ], te[ 5 ],
  2743. te[ 6 ], te[ 7 ], te[ 8 ]
  2744. ];
  2745. },
  2746. clone: function () {
  2747. return new THREE.Matrix3().fromArray( this.elements );
  2748. }
  2749. };
  2750. // File:src/math/Matrix4.js
  2751. /**
  2752. * @author mrdoob / http://mrdoob.com/
  2753. * @author supereggbert / http://www.paulbrunt.co.uk/
  2754. * @author philogb / http://blog.thejit.org/
  2755. * @author jordi_ros / http://plattsoft.com
  2756. * @author D1plo1d / http://github.com/D1plo1d
  2757. * @author alteredq / http://alteredqualia.com/
  2758. * @author mikael emtinger / http://gomo.se/
  2759. * @author timknip / http://www.floorplanner.com/
  2760. * @author bhouston / http://exocortex.com
  2761. * @author WestLangley / http://github.com/WestLangley
  2762. */
  2763. THREE.Matrix4 = function () {
  2764. this.elements = new Float32Array( [
  2765. 1, 0, 0, 0,
  2766. 0, 1, 0, 0,
  2767. 0, 0, 1, 0,
  2768. 0, 0, 0, 1
  2769. ] );
  2770. if ( arguments.length > 0 ) {
  2771. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2772. }
  2773. };
  2774. THREE.Matrix4.prototype = {
  2775. constructor: THREE.Matrix4,
  2776. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2777. var te = this.elements;
  2778. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2779. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2780. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2781. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2782. return this;
  2783. },
  2784. identity: function () {
  2785. this.set(
  2786. 1, 0, 0, 0,
  2787. 0, 1, 0, 0,
  2788. 0, 0, 1, 0,
  2789. 0, 0, 0, 1
  2790. );
  2791. return this;
  2792. },
  2793. copy: function ( m ) {
  2794. this.elements.set( m.elements );
  2795. return this;
  2796. },
  2797. extractPosition: function ( m ) {
  2798. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2799. return this.copyPosition( m );
  2800. },
  2801. copyPosition: function ( m ) {
  2802. var te = this.elements;
  2803. var me = m.elements;
  2804. te[ 12 ] = me[ 12 ];
  2805. te[ 13 ] = me[ 13 ];
  2806. te[ 14 ] = me[ 14 ];
  2807. return this;
  2808. },
  2809. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2810. var te = this.elements;
  2811. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2812. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2813. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2814. return this;
  2815. },
  2816. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2817. this.set(
  2818. xAxis.x, yAxis.x, zAxis.x, 0,
  2819. xAxis.y, yAxis.y, zAxis.y, 0,
  2820. xAxis.z, yAxis.z, zAxis.z, 0,
  2821. 0, 0, 0, 1
  2822. );
  2823. return this;
  2824. },
  2825. extractRotation: function () {
  2826. var v1;
  2827. return function ( m ) {
  2828. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2829. var te = this.elements;
  2830. var me = m.elements;
  2831. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2832. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2833. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2834. te[ 0 ] = me[ 0 ] * scaleX;
  2835. te[ 1 ] = me[ 1 ] * scaleX;
  2836. te[ 2 ] = me[ 2 ] * scaleX;
  2837. te[ 4 ] = me[ 4 ] * scaleY;
  2838. te[ 5 ] = me[ 5 ] * scaleY;
  2839. te[ 6 ] = me[ 6 ] * scaleY;
  2840. te[ 8 ] = me[ 8 ] * scaleZ;
  2841. te[ 9 ] = me[ 9 ] * scaleZ;
  2842. te[ 10 ] = me[ 10 ] * scaleZ;
  2843. return this;
  2844. };
  2845. }(),
  2846. makeRotationFromEuler: function ( euler ) {
  2847. if ( euler instanceof THREE.Euler === false ) {
  2848. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2849. }
  2850. var te = this.elements;
  2851. var x = euler.x, y = euler.y, z = euler.z;
  2852. var a = Math.cos( x ), b = Math.sin( x );
  2853. var c = Math.cos( y ), d = Math.sin( y );
  2854. var e = Math.cos( z ), f = Math.sin( z );
  2855. if ( euler.order === 'XYZ' ) {
  2856. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2857. te[ 0 ] = c * e;
  2858. te[ 4 ] = - c * f;
  2859. te[ 8 ] = d;
  2860. te[ 1 ] = af + be * d;
  2861. te[ 5 ] = ae - bf * d;
  2862. te[ 9 ] = - b * c;
  2863. te[ 2 ] = bf - ae * d;
  2864. te[ 6 ] = be + af * d;
  2865. te[ 10 ] = a * c;
  2866. } else if ( euler.order === 'YXZ' ) {
  2867. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2868. te[ 0 ] = ce + df * b;
  2869. te[ 4 ] = de * b - cf;
  2870. te[ 8 ] = a * d;
  2871. te[ 1 ] = a * f;
  2872. te[ 5 ] = a * e;
  2873. te[ 9 ] = - b;
  2874. te[ 2 ] = cf * b - de;
  2875. te[ 6 ] = df + ce * b;
  2876. te[ 10 ] = a * c;
  2877. } else if ( euler.order === 'ZXY' ) {
  2878. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2879. te[ 0 ] = ce - df * b;
  2880. te[ 4 ] = - a * f;
  2881. te[ 8 ] = de + cf * b;
  2882. te[ 1 ] = cf + de * b;
  2883. te[ 5 ] = a * e;
  2884. te[ 9 ] = df - ce * b;
  2885. te[ 2 ] = - a * d;
  2886. te[ 6 ] = b;
  2887. te[ 10 ] = a * c;
  2888. } else if ( euler.order === 'ZYX' ) {
  2889. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2890. te[ 0 ] = c * e;
  2891. te[ 4 ] = be * d - af;
  2892. te[ 8 ] = ae * d + bf;
  2893. te[ 1 ] = c * f;
  2894. te[ 5 ] = bf * d + ae;
  2895. te[ 9 ] = af * d - be;
  2896. te[ 2 ] = - d;
  2897. te[ 6 ] = b * c;
  2898. te[ 10 ] = a * c;
  2899. } else if ( euler.order === 'YZX' ) {
  2900. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2901. te[ 0 ] = c * e;
  2902. te[ 4 ] = bd - ac * f;
  2903. te[ 8 ] = bc * f + ad;
  2904. te[ 1 ] = f;
  2905. te[ 5 ] = a * e;
  2906. te[ 9 ] = - b * e;
  2907. te[ 2 ] = - d * e;
  2908. te[ 6 ] = ad * f + bc;
  2909. te[ 10 ] = ac - bd * f;
  2910. } else if ( euler.order === 'XZY' ) {
  2911. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2912. te[ 0 ] = c * e;
  2913. te[ 4 ] = - f;
  2914. te[ 8 ] = d * e;
  2915. te[ 1 ] = ac * f + bd;
  2916. te[ 5 ] = a * e;
  2917. te[ 9 ] = ad * f - bc;
  2918. te[ 2 ] = bc * f - ad;
  2919. te[ 6 ] = b * e;
  2920. te[ 10 ] = bd * f + ac;
  2921. }
  2922. // last column
  2923. te[ 3 ] = 0;
  2924. te[ 7 ] = 0;
  2925. te[ 11 ] = 0;
  2926. // bottom row
  2927. te[ 12 ] = 0;
  2928. te[ 13 ] = 0;
  2929. te[ 14 ] = 0;
  2930. te[ 15 ] = 1;
  2931. return this;
  2932. },
  2933. setRotationFromQuaternion: function ( q ) {
  2934. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2935. return this.makeRotationFromQuaternion( q );
  2936. },
  2937. makeRotationFromQuaternion: function ( q ) {
  2938. var te = this.elements;
  2939. var x = q.x, y = q.y, z = q.z, w = q.w;
  2940. var x2 = x + x, y2 = y + y, z2 = z + z;
  2941. var xx = x * x2, xy = x * y2, xz = x * z2;
  2942. var yy = y * y2, yz = y * z2, zz = z * z2;
  2943. var wx = w * x2, wy = w * y2, wz = w * z2;
  2944. te[ 0 ] = 1 - ( yy + zz );
  2945. te[ 4 ] = xy - wz;
  2946. te[ 8 ] = xz + wy;
  2947. te[ 1 ] = xy + wz;
  2948. te[ 5 ] = 1 - ( xx + zz );
  2949. te[ 9 ] = yz - wx;
  2950. te[ 2 ] = xz - wy;
  2951. te[ 6 ] = yz + wx;
  2952. te[ 10 ] = 1 - ( xx + yy );
  2953. // last column
  2954. te[ 3 ] = 0;
  2955. te[ 7 ] = 0;
  2956. te[ 11 ] = 0;
  2957. // bottom row
  2958. te[ 12 ] = 0;
  2959. te[ 13 ] = 0;
  2960. te[ 14 ] = 0;
  2961. te[ 15 ] = 1;
  2962. return this;
  2963. },
  2964. lookAt: function () {
  2965. var x, y, z;
  2966. return function ( eye, target, up ) {
  2967. if ( x === undefined ) x = new THREE.Vector3();
  2968. if ( y === undefined ) y = new THREE.Vector3();
  2969. if ( z === undefined ) z = new THREE.Vector3();
  2970. var te = this.elements;
  2971. z.subVectors( eye, target ).normalize();
  2972. if ( z.length() === 0 ) {
  2973. z.z = 1;
  2974. }
  2975. x.crossVectors( up, z ).normalize();
  2976. if ( x.length() === 0 ) {
  2977. z.x += 0.0001;
  2978. x.crossVectors( up, z ).normalize();
  2979. }
  2980. y.crossVectors( z, x );
  2981. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2982. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2983. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2984. return this;
  2985. };
  2986. }(),
  2987. multiply: function ( m, n ) {
  2988. if ( n !== undefined ) {
  2989. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2990. return this.multiplyMatrices( m, n );
  2991. }
  2992. return this.multiplyMatrices( this, m );
  2993. },
  2994. multiplyMatrices: function ( a, b ) {
  2995. var ae = a.elements;
  2996. var be = b.elements;
  2997. var te = this.elements;
  2998. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2999. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3000. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3001. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3002. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3003. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3004. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3005. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3006. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3007. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3008. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3009. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3010. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3011. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3012. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3013. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3014. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3015. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3016. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3017. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3018. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3019. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3020. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3021. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3022. return this;
  3023. },
  3024. multiplyToArray: function ( a, b, r ) {
  3025. var te = this.elements;
  3026. this.multiplyMatrices( a, b );
  3027. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3028. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3029. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3030. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3031. return this;
  3032. },
  3033. multiplyScalar: function ( s ) {
  3034. var te = this.elements;
  3035. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3036. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3037. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3038. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3039. return this;
  3040. },
  3041. multiplyVector3: function ( vector ) {
  3042. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  3043. return vector.applyProjection( this );
  3044. },
  3045. multiplyVector4: function ( vector ) {
  3046. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3047. return vector.applyMatrix4( this );
  3048. },
  3049. multiplyVector3Array: function ( a ) {
  3050. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  3051. return this.applyToVector3Array( a );
  3052. },
  3053. applyToVector3Array: function () {
  3054. var v1;
  3055. return function ( array, offset, length ) {
  3056. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3057. if ( offset === undefined ) offset = 0;
  3058. if ( length === undefined ) length = array.length;
  3059. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3060. v1.fromArray( array, j );
  3061. v1.applyMatrix4( this );
  3062. v1.toArray( array, j );
  3063. }
  3064. return array;
  3065. };
  3066. }(),
  3067. applyToBuffer: function () {
  3068. var v1;
  3069. return function applyToBuffer( buffer, offset, length ) {
  3070. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3071. if ( offset === undefined ) offset = 0;
  3072. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3073. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3074. v1.x = buffer.getX( j );
  3075. v1.y = buffer.getY( j );
  3076. v1.z = buffer.getZ( j );
  3077. v1.applyMatrix4( this );
  3078. buffer.setXYZ( v1.x, v1.y, v1.z );
  3079. }
  3080. return buffer;
  3081. };
  3082. }(),
  3083. rotateAxis: function ( v ) {
  3084. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  3085. v.transformDirection( this );
  3086. },
  3087. crossVector: function ( vector ) {
  3088. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3089. return vector.applyMatrix4( this );
  3090. },
  3091. determinant: function () {
  3092. var te = this.elements;
  3093. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3094. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3095. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3096. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3097. //TODO: make this more efficient
  3098. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3099. return (
  3100. n41 * (
  3101. + n14 * n23 * n32
  3102. - n13 * n24 * n32
  3103. - n14 * n22 * n33
  3104. + n12 * n24 * n33
  3105. + n13 * n22 * n34
  3106. - n12 * n23 * n34
  3107. ) +
  3108. n42 * (
  3109. + n11 * n23 * n34
  3110. - n11 * n24 * n33
  3111. + n14 * n21 * n33
  3112. - n13 * n21 * n34
  3113. + n13 * n24 * n31
  3114. - n14 * n23 * n31
  3115. ) +
  3116. n43 * (
  3117. + n11 * n24 * n32
  3118. - n11 * n22 * n34
  3119. - n14 * n21 * n32
  3120. + n12 * n21 * n34
  3121. + n14 * n22 * n31
  3122. - n12 * n24 * n31
  3123. ) +
  3124. n44 * (
  3125. - n13 * n22 * n31
  3126. - n11 * n23 * n32
  3127. + n11 * n22 * n33
  3128. + n13 * n21 * n32
  3129. - n12 * n21 * n33
  3130. + n12 * n23 * n31
  3131. )
  3132. );
  3133. },
  3134. transpose: function () {
  3135. var te = this.elements;
  3136. var tmp;
  3137. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3138. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3139. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3140. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3141. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3142. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3143. return this;
  3144. },
  3145. flattenToArrayOffset: function ( array, offset ) {
  3146. var te = this.elements;
  3147. array[ offset ] = te[ 0 ];
  3148. array[ offset + 1 ] = te[ 1 ];
  3149. array[ offset + 2 ] = te[ 2 ];
  3150. array[ offset + 3 ] = te[ 3 ];
  3151. array[ offset + 4 ] = te[ 4 ];
  3152. array[ offset + 5 ] = te[ 5 ];
  3153. array[ offset + 6 ] = te[ 6 ];
  3154. array[ offset + 7 ] = te[ 7 ];
  3155. array[ offset + 8 ] = te[ 8 ];
  3156. array[ offset + 9 ] = te[ 9 ];
  3157. array[ offset + 10 ] = te[ 10 ];
  3158. array[ offset + 11 ] = te[ 11 ];
  3159. array[ offset + 12 ] = te[ 12 ];
  3160. array[ offset + 13 ] = te[ 13 ];
  3161. array[ offset + 14 ] = te[ 14 ];
  3162. array[ offset + 15 ] = te[ 15 ];
  3163. return array;
  3164. },
  3165. getPosition: function () {
  3166. var v1;
  3167. return function () {
  3168. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3169. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3170. var te = this.elements;
  3171. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3172. };
  3173. }(),
  3174. setPosition: function ( v ) {
  3175. var te = this.elements;
  3176. te[ 12 ] = v.x;
  3177. te[ 13 ] = v.y;
  3178. te[ 14 ] = v.z;
  3179. return this;
  3180. },
  3181. getInverse: function ( m, throwOnInvertible ) {
  3182. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3183. var te = this.elements;
  3184. var me = m.elements;
  3185. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3186. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3187. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3188. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3189. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3190. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3191. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3192. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3193. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3194. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3195. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3196. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3197. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3198. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3199. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3200. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3201. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3202. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3203. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3204. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3205. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3206. if ( det === 0 ) {
  3207. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3208. if ( throwOnInvertible || false ) {
  3209. throw new Error( msg );
  3210. } else {
  3211. console.warn( msg );
  3212. }
  3213. this.identity();
  3214. return this;
  3215. }
  3216. this.multiplyScalar( 1 / det );
  3217. return this;
  3218. },
  3219. translate: function ( v ) {
  3220. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3221. },
  3222. rotateX: function ( angle ) {
  3223. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3224. },
  3225. rotateY: function ( angle ) {
  3226. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3227. },
  3228. rotateZ: function ( angle ) {
  3229. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3230. },
  3231. rotateByAxis: function ( axis, angle ) {
  3232. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3233. },
  3234. scale: function ( v ) {
  3235. var te = this.elements;
  3236. var x = v.x, y = v.y, z = v.z;
  3237. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3238. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3239. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3240. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3241. return this;
  3242. },
  3243. getMaxScaleOnAxis: function () {
  3244. var te = this.elements;
  3245. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3246. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3247. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3248. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  3249. },
  3250. makeTranslation: function ( x, y, z ) {
  3251. this.set(
  3252. 1, 0, 0, x,
  3253. 0, 1, 0, y,
  3254. 0, 0, 1, z,
  3255. 0, 0, 0, 1
  3256. );
  3257. return this;
  3258. },
  3259. makeRotationX: function ( theta ) {
  3260. var c = Math.cos( theta ), s = Math.sin( theta );
  3261. this.set(
  3262. 1, 0, 0, 0,
  3263. 0, c, - s, 0,
  3264. 0, s, c, 0,
  3265. 0, 0, 0, 1
  3266. );
  3267. return this;
  3268. },
  3269. makeRotationY: function ( theta ) {
  3270. var c = Math.cos( theta ), s = Math.sin( theta );
  3271. this.set(
  3272. c, 0, s, 0,
  3273. 0, 1, 0, 0,
  3274. - s, 0, c, 0,
  3275. 0, 0, 0, 1
  3276. );
  3277. return this;
  3278. },
  3279. makeRotationZ: function ( theta ) {
  3280. var c = Math.cos( theta ), s = Math.sin( theta );
  3281. this.set(
  3282. c, - s, 0, 0,
  3283. s, c, 0, 0,
  3284. 0, 0, 1, 0,
  3285. 0, 0, 0, 1
  3286. );
  3287. return this;
  3288. },
  3289. makeRotationAxis: function ( axis, angle ) {
  3290. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3291. var c = Math.cos( angle );
  3292. var s = Math.sin( angle );
  3293. var t = 1 - c;
  3294. var x = axis.x, y = axis.y, z = axis.z;
  3295. var tx = t * x, ty = t * y;
  3296. this.set(
  3297. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3298. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3299. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3300. 0, 0, 0, 1
  3301. );
  3302. return this;
  3303. },
  3304. makeScale: function ( x, y, z ) {
  3305. this.set(
  3306. x, 0, 0, 0,
  3307. 0, y, 0, 0,
  3308. 0, 0, z, 0,
  3309. 0, 0, 0, 1
  3310. );
  3311. return this;
  3312. },
  3313. compose: function ( position, quaternion, scale ) {
  3314. this.makeRotationFromQuaternion( quaternion );
  3315. this.scale( scale );
  3316. this.setPosition( position );
  3317. return this;
  3318. },
  3319. decompose: function () {
  3320. var vector, matrix;
  3321. return function ( position, quaternion, scale ) {
  3322. if ( vector === undefined ) vector = new THREE.Vector3();
  3323. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3324. var te = this.elements;
  3325. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3326. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3327. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3328. // if determine is negative, we need to invert one scale
  3329. var det = this.determinant();
  3330. if ( det < 0 ) {
  3331. sx = - sx;
  3332. }
  3333. position.x = te[ 12 ];
  3334. position.y = te[ 13 ];
  3335. position.z = te[ 14 ];
  3336. // scale the rotation part
  3337. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3338. var invSX = 1 / sx;
  3339. var invSY = 1 / sy;
  3340. var invSZ = 1 / sz;
  3341. matrix.elements[ 0 ] *= invSX;
  3342. matrix.elements[ 1 ] *= invSX;
  3343. matrix.elements[ 2 ] *= invSX;
  3344. matrix.elements[ 4 ] *= invSY;
  3345. matrix.elements[ 5 ] *= invSY;
  3346. matrix.elements[ 6 ] *= invSY;
  3347. matrix.elements[ 8 ] *= invSZ;
  3348. matrix.elements[ 9 ] *= invSZ;
  3349. matrix.elements[ 10 ] *= invSZ;
  3350. quaternion.setFromRotationMatrix( matrix );
  3351. scale.x = sx;
  3352. scale.y = sy;
  3353. scale.z = sz;
  3354. return this;
  3355. };
  3356. }(),
  3357. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3358. var te = this.elements;
  3359. var x = 2 * near / ( right - left );
  3360. var y = 2 * near / ( top - bottom );
  3361. var a = ( right + left ) / ( right - left );
  3362. var b = ( top + bottom ) / ( top - bottom );
  3363. var c = - ( far + near ) / ( far - near );
  3364. var d = - 2 * far * near / ( far - near );
  3365. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3366. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3367. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3368. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3369. return this;
  3370. },
  3371. makePerspective: function ( fov, aspect, near, far ) {
  3372. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3373. var ymin = - ymax;
  3374. var xmin = ymin * aspect;
  3375. var xmax = ymax * aspect;
  3376. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3377. },
  3378. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3379. var te = this.elements;
  3380. var w = right - left;
  3381. var h = top - bottom;
  3382. var p = far - near;
  3383. var x = ( right + left ) / w;
  3384. var y = ( top + bottom ) / h;
  3385. var z = ( far + near ) / p;
  3386. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3387. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3388. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3389. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3390. return this;
  3391. },
  3392. equals: function ( matrix ) {
  3393. var te = this.elements;
  3394. var me = matrix.elements;
  3395. for ( var i = 0; i < 16; i ++ ) {
  3396. if ( te[ i ] !== me[ i ] ) return false;
  3397. }
  3398. return true;
  3399. },
  3400. fromArray: function ( array ) {
  3401. this.elements.set( array );
  3402. return this;
  3403. },
  3404. toArray: function () {
  3405. var te = this.elements;
  3406. return [
  3407. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3408. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3409. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3410. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3411. ];
  3412. },
  3413. clone: function () {
  3414. return new THREE.Matrix4().fromArray( this.elements );
  3415. }
  3416. };
  3417. // File:src/math/Ray.js
  3418. /**
  3419. * @author bhouston / http://exocortex.com
  3420. */
  3421. THREE.Ray = function ( origin, direction ) {
  3422. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3423. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3424. };
  3425. THREE.Ray.prototype = {
  3426. constructor: THREE.Ray,
  3427. set: function ( origin, direction ) {
  3428. this.origin.copy( origin );
  3429. this.direction.copy( direction );
  3430. return this;
  3431. },
  3432. copy: function ( ray ) {
  3433. this.origin.copy( ray.origin );
  3434. this.direction.copy( ray.direction );
  3435. return this;
  3436. },
  3437. at: function ( t, optionalTarget ) {
  3438. var result = optionalTarget || new THREE.Vector3();
  3439. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3440. },
  3441. recast: function () {
  3442. var v1 = new THREE.Vector3();
  3443. return function ( t ) {
  3444. this.origin.copy( this.at( t, v1 ) );
  3445. return this;
  3446. };
  3447. }(),
  3448. closestPointToPoint: function ( point, optionalTarget ) {
  3449. var result = optionalTarget || new THREE.Vector3();
  3450. result.subVectors( point, this.origin );
  3451. var directionDistance = result.dot( this.direction );
  3452. if ( directionDistance < 0 ) {
  3453. return result.copy( this.origin );
  3454. }
  3455. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3456. },
  3457. distanceToPoint: function ( point ) {
  3458. return Math.sqrt( this.distanceSqToPoint( point ) );
  3459. },
  3460. distanceSqToPoint: function () {
  3461. var v1 = new THREE.Vector3();
  3462. return function ( point ) {
  3463. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3464. // point behind the ray
  3465. if ( directionDistance < 0 ) {
  3466. return this.origin.distanceToSquared( point );
  3467. }
  3468. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3469. return v1.distanceToSquared( point );
  3470. };
  3471. }(),
  3472. distanceSqToSegment: function () {
  3473. var segCenter = new THREE.Vector3();
  3474. var segDir = new THREE.Vector3();
  3475. var diff = new THREE.Vector3();
  3476. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3477. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3478. // It returns the min distance between the ray and the segment
  3479. // defined by v0 and v1
  3480. // It can also set two optional targets :
  3481. // - The closest point on the ray
  3482. // - The closest point on the segment
  3483. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3484. segDir.copy( v1 ).sub( v0 ).normalize();
  3485. diff.copy( this.origin ).sub( segCenter );
  3486. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3487. var a01 = - this.direction.dot( segDir );
  3488. var b0 = diff.dot( this.direction );
  3489. var b1 = - diff.dot( segDir );
  3490. var c = diff.lengthSq();
  3491. var det = Math.abs( 1 - a01 * a01 );
  3492. var s0, s1, sqrDist, extDet;
  3493. if ( det > 0 ) {
  3494. // The ray and segment are not parallel.
  3495. s0 = a01 * b1 - b0;
  3496. s1 = a01 * b0 - b1;
  3497. extDet = segExtent * det;
  3498. if ( s0 >= 0 ) {
  3499. if ( s1 >= - extDet ) {
  3500. if ( s1 <= extDet ) {
  3501. // region 0
  3502. // Minimum at interior points of ray and segment.
  3503. var invDet = 1 / det;
  3504. s0 *= invDet;
  3505. s1 *= invDet;
  3506. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3507. } else {
  3508. // region 1
  3509. s1 = segExtent;
  3510. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3511. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3512. }
  3513. } else {
  3514. // region 5
  3515. s1 = - segExtent;
  3516. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3517. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3518. }
  3519. } else {
  3520. if ( s1 <= - extDet ) {
  3521. // region 4
  3522. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3523. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3524. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3525. } else if ( s1 <= extDet ) {
  3526. // region 3
  3527. s0 = 0;
  3528. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3529. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3530. } else {
  3531. // region 2
  3532. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3533. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3534. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3535. }
  3536. }
  3537. } else {
  3538. // Ray and segment are parallel.
  3539. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3540. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3541. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3542. }
  3543. if ( optionalPointOnRay ) {
  3544. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3545. }
  3546. if ( optionalPointOnSegment ) {
  3547. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3548. }
  3549. return sqrDist;
  3550. };
  3551. }(),
  3552. isIntersectionSphere: function ( sphere ) {
  3553. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3554. },
  3555. intersectSphere: function () {
  3556. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3557. var v1 = new THREE.Vector3();
  3558. return function ( sphere, optionalTarget ) {
  3559. v1.subVectors( sphere.center, this.origin );
  3560. var tca = v1.dot( this.direction );
  3561. var d2 = v1.dot( v1 ) - tca * tca;
  3562. var radius2 = sphere.radius * sphere.radius;
  3563. if ( d2 > radius2 ) return null;
  3564. var thc = Math.sqrt( radius2 - d2 );
  3565. // t0 = first intersect point - entrance on front of sphere
  3566. var t0 = tca - thc;
  3567. // t1 = second intersect point - exit point on back of sphere
  3568. var t1 = tca + thc;
  3569. // test to see if both t0 and t1 are behind the ray - if so, return null
  3570. if ( t0 < 0 && t1 < 0 ) return null;
  3571. // test to see if t0 is behind the ray:
  3572. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3573. // in order to always return an intersect point that is in front of the ray.
  3574. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3575. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3576. return this.at( t0, optionalTarget );
  3577. }
  3578. }(),
  3579. isIntersectionPlane: function ( plane ) {
  3580. // check if the ray lies on the plane first
  3581. var distToPoint = plane.distanceToPoint( this.origin );
  3582. if ( distToPoint === 0 ) {
  3583. return true;
  3584. }
  3585. var denominator = plane.normal.dot( this.direction );
  3586. if ( denominator * distToPoint < 0 ) {
  3587. return true;
  3588. }
  3589. // ray origin is behind the plane (and is pointing behind it)
  3590. return false;
  3591. },
  3592. distanceToPlane: function ( plane ) {
  3593. var denominator = plane.normal.dot( this.direction );
  3594. if ( denominator === 0 ) {
  3595. // line is coplanar, return origin
  3596. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3597. return 0;
  3598. }
  3599. // Null is preferable to undefined since undefined means.... it is undefined
  3600. return null;
  3601. }
  3602. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3603. // Return if the ray never intersects the plane
  3604. return t >= 0 ? t : null;
  3605. },
  3606. intersectPlane: function ( plane, optionalTarget ) {
  3607. var t = this.distanceToPlane( plane );
  3608. if ( t === null ) {
  3609. return null;
  3610. }
  3611. return this.at( t, optionalTarget );
  3612. },
  3613. isIntersectionBox: function () {
  3614. var v = new THREE.Vector3();
  3615. return function ( box ) {
  3616. return this.intersectBox( box, v ) !== null;
  3617. };
  3618. }(),
  3619. intersectBox: function ( box, optionalTarget ) {
  3620. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3621. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3622. var invdirx = 1 / this.direction.x,
  3623. invdiry = 1 / this.direction.y,
  3624. invdirz = 1 / this.direction.z;
  3625. var origin = this.origin;
  3626. if ( invdirx >= 0 ) {
  3627. tmin = ( box.min.x - origin.x ) * invdirx;
  3628. tmax = ( box.max.x - origin.x ) * invdirx;
  3629. } else {
  3630. tmin = ( box.max.x - origin.x ) * invdirx;
  3631. tmax = ( box.min.x - origin.x ) * invdirx;
  3632. }
  3633. if ( invdiry >= 0 ) {
  3634. tymin = ( box.min.y - origin.y ) * invdiry;
  3635. tymax = ( box.max.y - origin.y ) * invdiry;
  3636. } else {
  3637. tymin = ( box.max.y - origin.y ) * invdiry;
  3638. tymax = ( box.min.y - origin.y ) * invdiry;
  3639. }
  3640. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3641. // These lines also handle the case where tmin or tmax is NaN
  3642. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3643. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3644. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3645. if ( invdirz >= 0 ) {
  3646. tzmin = ( box.min.z - origin.z ) * invdirz;
  3647. tzmax = ( box.max.z - origin.z ) * invdirz;
  3648. } else {
  3649. tzmin = ( box.max.z - origin.z ) * invdirz;
  3650. tzmax = ( box.min.z - origin.z ) * invdirz;
  3651. }
  3652. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3653. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3654. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3655. //return point closest to the ray (positive side)
  3656. if ( tmax < 0 ) return null;
  3657. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3658. },
  3659. intersectTriangle: function () {
  3660. // Compute the offset origin, edges, and normal.
  3661. var diff = new THREE.Vector3();
  3662. var edge1 = new THREE.Vector3();
  3663. var edge2 = new THREE.Vector3();
  3664. var normal = new THREE.Vector3();
  3665. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3666. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3667. edge1.subVectors( b, a );
  3668. edge2.subVectors( c, a );
  3669. normal.crossVectors( edge1, edge2 );
  3670. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3671. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3672. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3673. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3674. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3675. var DdN = this.direction.dot( normal );
  3676. var sign;
  3677. if ( DdN > 0 ) {
  3678. if ( backfaceCulling ) return null;
  3679. sign = 1;
  3680. } else if ( DdN < 0 ) {
  3681. sign = - 1;
  3682. DdN = - DdN;
  3683. } else {
  3684. return null;
  3685. }
  3686. diff.subVectors( this.origin, a );
  3687. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3688. // b1 < 0, no intersection
  3689. if ( DdQxE2 < 0 ) {
  3690. return null;
  3691. }
  3692. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3693. // b2 < 0, no intersection
  3694. if ( DdE1xQ < 0 ) {
  3695. return null;
  3696. }
  3697. // b1+b2 > 1, no intersection
  3698. if ( DdQxE2 + DdE1xQ > DdN ) {
  3699. return null;
  3700. }
  3701. // Line intersects triangle, check if ray does.
  3702. var QdN = - sign * diff.dot( normal );
  3703. // t < 0, no intersection
  3704. if ( QdN < 0 ) {
  3705. return null;
  3706. }
  3707. // Ray intersects triangle.
  3708. return this.at( QdN / DdN, optionalTarget );
  3709. };
  3710. }(),
  3711. applyMatrix4: function ( matrix4 ) {
  3712. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3713. this.origin.applyMatrix4( matrix4 );
  3714. this.direction.sub( this.origin );
  3715. this.direction.normalize();
  3716. return this;
  3717. },
  3718. equals: function ( ray ) {
  3719. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3720. },
  3721. clone: function () {
  3722. return new THREE.Ray().copy( this );
  3723. }
  3724. };
  3725. // File:src/math/Sphere.js
  3726. /**
  3727. * @author bhouston / http://exocortex.com
  3728. * @author mrdoob / http://mrdoob.com/
  3729. */
  3730. THREE.Sphere = function ( center, radius ) {
  3731. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3732. this.radius = ( radius !== undefined ) ? radius : 0;
  3733. };
  3734. THREE.Sphere.prototype = {
  3735. constructor: THREE.Sphere,
  3736. set: function ( center, radius ) {
  3737. this.center.copy( center );
  3738. this.radius = radius;
  3739. return this;
  3740. },
  3741. setFromPoints: function () {
  3742. var box = new THREE.Box3();
  3743. return function ( points, optionalCenter ) {
  3744. var center = this.center;
  3745. if ( optionalCenter !== undefined ) {
  3746. center.copy( optionalCenter );
  3747. } else {
  3748. box.setFromPoints( points ).center( center );
  3749. }
  3750. var maxRadiusSq = 0;
  3751. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3752. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3753. }
  3754. this.radius = Math.sqrt( maxRadiusSq );
  3755. return this;
  3756. };
  3757. }(),
  3758. copy: function ( sphere ) {
  3759. this.center.copy( sphere.center );
  3760. this.radius = sphere.radius;
  3761. return this;
  3762. },
  3763. empty: function () {
  3764. return ( this.radius <= 0 );
  3765. },
  3766. containsPoint: function ( point ) {
  3767. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3768. },
  3769. distanceToPoint: function ( point ) {
  3770. return ( point.distanceTo( this.center ) - this.radius );
  3771. },
  3772. intersectsSphere: function ( sphere ) {
  3773. var radiusSum = this.radius + sphere.radius;
  3774. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3775. },
  3776. clampPoint: function ( point, optionalTarget ) {
  3777. var deltaLengthSq = this.center.distanceToSquared( point );
  3778. var result = optionalTarget || new THREE.Vector3();
  3779. result.copy( point );
  3780. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3781. result.sub( this.center ).normalize();
  3782. result.multiplyScalar( this.radius ).add( this.center );
  3783. }
  3784. return result;
  3785. },
  3786. getBoundingBox: function ( optionalTarget ) {
  3787. var box = optionalTarget || new THREE.Box3();
  3788. box.set( this.center, this.center );
  3789. box.expandByScalar( this.radius );
  3790. return box;
  3791. },
  3792. applyMatrix4: function ( matrix ) {
  3793. this.center.applyMatrix4( matrix );
  3794. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3795. return this;
  3796. },
  3797. translate: function ( offset ) {
  3798. this.center.add( offset );
  3799. return this;
  3800. },
  3801. equals: function ( sphere ) {
  3802. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3803. },
  3804. clone: function () {
  3805. return new THREE.Sphere().copy( this );
  3806. }
  3807. };
  3808. // File:src/math/Frustum.js
  3809. /**
  3810. * @author mrdoob / http://mrdoob.com/
  3811. * @author alteredq / http://alteredqualia.com/
  3812. * @author bhouston / http://exocortex.com
  3813. */
  3814. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3815. this.planes = [
  3816. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3817. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3818. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3819. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3820. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3821. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3822. ];
  3823. };
  3824. THREE.Frustum.prototype = {
  3825. constructor: THREE.Frustum,
  3826. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3827. var planes = this.planes;
  3828. planes[ 0 ].copy( p0 );
  3829. planes[ 1 ].copy( p1 );
  3830. planes[ 2 ].copy( p2 );
  3831. planes[ 3 ].copy( p3 );
  3832. planes[ 4 ].copy( p4 );
  3833. planes[ 5 ].copy( p5 );
  3834. return this;
  3835. },
  3836. copy: function ( frustum ) {
  3837. var planes = this.planes;
  3838. for ( var i = 0; i < 6; i ++ ) {
  3839. planes[ i ].copy( frustum.planes[ i ] );
  3840. }
  3841. return this;
  3842. },
  3843. setFromMatrix: function ( m ) {
  3844. var planes = this.planes;
  3845. var me = m.elements;
  3846. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3847. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3848. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3849. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3850. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3851. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3852. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3853. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3854. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3855. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3856. return this;
  3857. },
  3858. intersectsObject: function () {
  3859. var sphere = new THREE.Sphere();
  3860. return function ( object ) {
  3861. var geometry = object.geometry;
  3862. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3863. sphere.copy( geometry.boundingSphere );
  3864. sphere.applyMatrix4( object.matrixWorld );
  3865. return this.intersectsSphere( sphere );
  3866. };
  3867. }(),
  3868. intersectsSphere: function ( sphere ) {
  3869. var planes = this.planes;
  3870. var center = sphere.center;
  3871. var negRadius = - sphere.radius;
  3872. for ( var i = 0; i < 6; i ++ ) {
  3873. var distance = planes[ i ].distanceToPoint( center );
  3874. if ( distance < negRadius ) {
  3875. return false;
  3876. }
  3877. }
  3878. return true;
  3879. },
  3880. intersectsBox: function () {
  3881. var p1 = new THREE.Vector3(),
  3882. p2 = new THREE.Vector3();
  3883. return function ( box ) {
  3884. var planes = this.planes;
  3885. for ( var i = 0; i < 6 ; i ++ ) {
  3886. var plane = planes[ i ];
  3887. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3888. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3889. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3890. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3891. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3892. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3893. var d1 = plane.distanceToPoint( p1 );
  3894. var d2 = plane.distanceToPoint( p2 );
  3895. // if both outside plane, no intersection
  3896. if ( d1 < 0 && d2 < 0 ) {
  3897. return false;
  3898. }
  3899. }
  3900. return true;
  3901. };
  3902. }(),
  3903. containsPoint: function ( point ) {
  3904. var planes = this.planes;
  3905. for ( var i = 0; i < 6; i ++ ) {
  3906. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3907. return false;
  3908. }
  3909. }
  3910. return true;
  3911. },
  3912. clone: function () {
  3913. return new THREE.Frustum().copy( this );
  3914. }
  3915. };
  3916. // File:src/math/Plane.js
  3917. /**
  3918. * @author bhouston / http://exocortex.com
  3919. */
  3920. THREE.Plane = function ( normal, constant ) {
  3921. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3922. this.constant = ( constant !== undefined ) ? constant : 0;
  3923. };
  3924. THREE.Plane.prototype = {
  3925. constructor: THREE.Plane,
  3926. set: function ( normal, constant ) {
  3927. this.normal.copy( normal );
  3928. this.constant = constant;
  3929. return this;
  3930. },
  3931. setComponents: function ( x, y, z, w ) {
  3932. this.normal.set( x, y, z );
  3933. this.constant = w;
  3934. return this;
  3935. },
  3936. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3937. this.normal.copy( normal );
  3938. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3939. return this;
  3940. },
  3941. setFromCoplanarPoints: function () {
  3942. var v1 = new THREE.Vector3();
  3943. var v2 = new THREE.Vector3();
  3944. return function ( a, b, c ) {
  3945. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3946. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3947. this.setFromNormalAndCoplanarPoint( normal, a );
  3948. return this;
  3949. };
  3950. }(),
  3951. copy: function ( plane ) {
  3952. this.normal.copy( plane.normal );
  3953. this.constant = plane.constant;
  3954. return this;
  3955. },
  3956. normalize: function () {
  3957. // Note: will lead to a divide by zero if the plane is invalid.
  3958. var inverseNormalLength = 1.0 / this.normal.length();
  3959. this.normal.multiplyScalar( inverseNormalLength );
  3960. this.constant *= inverseNormalLength;
  3961. return this;
  3962. },
  3963. negate: function () {
  3964. this.constant *= - 1;
  3965. this.normal.negate();
  3966. return this;
  3967. },
  3968. distanceToPoint: function ( point ) {
  3969. return this.normal.dot( point ) + this.constant;
  3970. },
  3971. distanceToSphere: function ( sphere ) {
  3972. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3973. },
  3974. projectPoint: function ( point, optionalTarget ) {
  3975. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3976. },
  3977. orthoPoint: function ( point, optionalTarget ) {
  3978. var perpendicularMagnitude = this.distanceToPoint( point );
  3979. var result = optionalTarget || new THREE.Vector3();
  3980. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3981. },
  3982. isIntersectionLine: function ( line ) {
  3983. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3984. var startSign = this.distanceToPoint( line.start );
  3985. var endSign = this.distanceToPoint( line.end );
  3986. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3987. },
  3988. intersectLine: function () {
  3989. var v1 = new THREE.Vector3();
  3990. return function ( line, optionalTarget ) {
  3991. var result = optionalTarget || new THREE.Vector3();
  3992. var direction = line.delta( v1 );
  3993. var denominator = this.normal.dot( direction );
  3994. if ( denominator === 0 ) {
  3995. // line is coplanar, return origin
  3996. if ( this.distanceToPoint( line.start ) === 0 ) {
  3997. return result.copy( line.start );
  3998. }
  3999. // Unsure if this is the correct method to handle this case.
  4000. return undefined;
  4001. }
  4002. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4003. if ( t < 0 || t > 1 ) {
  4004. return undefined;
  4005. }
  4006. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4007. };
  4008. }(),
  4009. coplanarPoint: function ( optionalTarget ) {
  4010. var result = optionalTarget || new THREE.Vector3();
  4011. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4012. },
  4013. applyMatrix4: function () {
  4014. var v1 = new THREE.Vector3();
  4015. var v2 = new THREE.Vector3();
  4016. var m1 = new THREE.Matrix3();
  4017. return function ( matrix, optionalNormalMatrix ) {
  4018. // compute new normal based on theory here:
  4019. // http://www.songho.ca/opengl/gl_normaltransform.html
  4020. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4021. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4022. var newCoplanarPoint = this.coplanarPoint( v2 );
  4023. newCoplanarPoint.applyMatrix4( matrix );
  4024. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4025. return this;
  4026. };
  4027. }(),
  4028. translate: function ( offset ) {
  4029. this.constant = this.constant - offset.dot( this.normal );
  4030. return this;
  4031. },
  4032. equals: function ( plane ) {
  4033. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4034. },
  4035. clone: function () {
  4036. return new THREE.Plane().copy( this );
  4037. }
  4038. };
  4039. // File:src/math/Math.js
  4040. /**
  4041. * @author alteredq / http://alteredqualia.com/
  4042. * @author mrdoob / http://mrdoob.com/
  4043. */
  4044. THREE.Math = {
  4045. generateUUID: function () {
  4046. // http://www.broofa.com/Tools/Math.uuid.htm
  4047. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4048. var uuid = new Array( 36 );
  4049. var rnd = 0, r;
  4050. return function () {
  4051. for ( var i = 0; i < 36; i ++ ) {
  4052. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4053. uuid[ i ] = '-';
  4054. } else if ( i === 14 ) {
  4055. uuid[ i ] = '4';
  4056. } else {
  4057. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4058. r = rnd & 0xf;
  4059. rnd = rnd >> 4;
  4060. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4061. }
  4062. }
  4063. return uuid.join( '' );
  4064. };
  4065. }(),
  4066. // Clamp value to range <a, b>
  4067. clamp: function ( x, a, b ) {
  4068. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  4069. },
  4070. // Clamp value to range <a, inf)
  4071. clampBottom: function ( x, a ) {
  4072. return x < a ? a : x;
  4073. },
  4074. // compute euclidian modulo of m % n
  4075. // https://en.wikipedia.org/wiki/Modulo_operation
  4076. euclideanModulo: function ( n, m ) {
  4077. return ( ( n % m ) + m ) % m;
  4078. },
  4079. // Linear mapping from range <a1, a2> to range <b1, b2>
  4080. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4081. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4082. },
  4083. // http://en.wikipedia.org/wiki/Smoothstep
  4084. smoothstep: function ( x, min, max ) {
  4085. if ( x <= min ) return 0;
  4086. if ( x >= max ) return 1;
  4087. x = ( x - min ) / ( max - min );
  4088. return x * x * ( 3 - 2 * x );
  4089. },
  4090. smootherstep: function ( x, min, max ) {
  4091. if ( x <= min ) return 0;
  4092. if ( x >= max ) return 1;
  4093. x = ( x - min ) / ( max - min );
  4094. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4095. },
  4096. // Random float from <0, 1> with 16 bits of randomness
  4097. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4098. random16: function () {
  4099. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4100. },
  4101. // Random integer from <low, high> interval
  4102. randInt: function ( low, high ) {
  4103. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4104. },
  4105. // Random float from <low, high> interval
  4106. randFloat: function ( low, high ) {
  4107. return low + Math.random() * ( high - low );
  4108. },
  4109. // Random float from <-range/2, range/2> interval
  4110. randFloatSpread: function ( range ) {
  4111. return range * ( 0.5 - Math.random() );
  4112. },
  4113. degToRad: function () {
  4114. var degreeToRadiansFactor = Math.PI / 180;
  4115. return function ( degrees ) {
  4116. return degrees * degreeToRadiansFactor;
  4117. };
  4118. }(),
  4119. radToDeg: function () {
  4120. var radianToDegreesFactor = 180 / Math.PI;
  4121. return function ( radians ) {
  4122. return radians * radianToDegreesFactor;
  4123. };
  4124. }(),
  4125. isPowerOfTwo: function ( value ) {
  4126. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4127. },
  4128. nextPowerOfTwo: function ( value ) {
  4129. value --;
  4130. value |= value >> 1;
  4131. value |= value >> 2;
  4132. value |= value >> 4;
  4133. value |= value >> 8;
  4134. value |= value >> 16;
  4135. value ++;
  4136. return value;
  4137. }
  4138. };
  4139. // File:src/math/Spline.js
  4140. /**
  4141. * Spline from Tween.js, slightly optimized (and trashed)
  4142. * http://sole.github.com/tween.js/examples/05_spline.html
  4143. *
  4144. * @author mrdoob / http://mrdoob.com/
  4145. * @author alteredq / http://alteredqualia.com/
  4146. */
  4147. THREE.Spline = function ( points ) {
  4148. this.points = points;
  4149. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4150. point, intPoint, weight, w2, w3,
  4151. pa, pb, pc, pd;
  4152. this.initFromArray = function ( a ) {
  4153. this.points = [];
  4154. for ( var i = 0; i < a.length; i ++ ) {
  4155. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4156. }
  4157. };
  4158. this.getPoint = function ( k ) {
  4159. point = ( this.points.length - 1 ) * k;
  4160. intPoint = Math.floor( point );
  4161. weight = point - intPoint;
  4162. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4163. c[ 1 ] = intPoint;
  4164. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4165. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4166. pa = this.points[ c[ 0 ] ];
  4167. pb = this.points[ c[ 1 ] ];
  4168. pc = this.points[ c[ 2 ] ];
  4169. pd = this.points[ c[ 3 ] ];
  4170. w2 = weight * weight;
  4171. w3 = weight * w2;
  4172. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4173. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4174. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4175. return v3;
  4176. };
  4177. this.getControlPointsArray = function () {
  4178. var i, p, l = this.points.length,
  4179. coords = [];
  4180. for ( i = 0; i < l; i ++ ) {
  4181. p = this.points[ i ];
  4182. coords[ i ] = [ p.x, p.y, p.z ];
  4183. }
  4184. return coords;
  4185. };
  4186. // approximate length by summing linear segments
  4187. this.getLength = function ( nSubDivisions ) {
  4188. var i, index, nSamples, position,
  4189. point = 0, intPoint = 0, oldIntPoint = 0,
  4190. oldPosition = new THREE.Vector3(),
  4191. tmpVec = new THREE.Vector3(),
  4192. chunkLengths = [],
  4193. totalLength = 0;
  4194. // first point has 0 length
  4195. chunkLengths[ 0 ] = 0;
  4196. if ( ! nSubDivisions ) nSubDivisions = 100;
  4197. nSamples = this.points.length * nSubDivisions;
  4198. oldPosition.copy( this.points[ 0 ] );
  4199. for ( i = 1; i < nSamples; i ++ ) {
  4200. index = i / nSamples;
  4201. position = this.getPoint( index );
  4202. tmpVec.copy( position );
  4203. totalLength += tmpVec.distanceTo( oldPosition );
  4204. oldPosition.copy( position );
  4205. point = ( this.points.length - 1 ) * index;
  4206. intPoint = Math.floor( point );
  4207. if ( intPoint !== oldIntPoint ) {
  4208. chunkLengths[ intPoint ] = totalLength;
  4209. oldIntPoint = intPoint;
  4210. }
  4211. }
  4212. // last point ends with total length
  4213. chunkLengths[ chunkLengths.length ] = totalLength;
  4214. return { chunks: chunkLengths, total: totalLength };
  4215. };
  4216. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4217. var i, j,
  4218. index, indexCurrent, indexNext,
  4219. realDistance,
  4220. sampling, position,
  4221. newpoints = [],
  4222. tmpVec = new THREE.Vector3(),
  4223. sl = this.getLength();
  4224. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4225. for ( i = 1; i < this.points.length; i ++ ) {
  4226. //tmpVec.copy( this.points[ i - 1 ] );
  4227. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4228. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4229. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4230. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4231. indexNext = i / ( this.points.length - 1 );
  4232. for ( j = 1; j < sampling - 1; j ++ ) {
  4233. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4234. position = this.getPoint( index );
  4235. newpoints.push( tmpVec.copy( position ).clone() );
  4236. }
  4237. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4238. }
  4239. this.points = newpoints;
  4240. };
  4241. // Catmull-Rom
  4242. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4243. var v0 = ( p2 - p0 ) * 0.5,
  4244. v1 = ( p3 - p1 ) * 0.5;
  4245. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4246. }
  4247. };
  4248. // File:src/math/Triangle.js
  4249. /**
  4250. * @author bhouston / http://exocortex.com
  4251. * @author mrdoob / http://mrdoob.com/
  4252. */
  4253. THREE.Triangle = function ( a, b, c ) {
  4254. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4255. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4256. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4257. };
  4258. THREE.Triangle.normal = function () {
  4259. var v0 = new THREE.Vector3();
  4260. return function ( a, b, c, optionalTarget ) {
  4261. var result = optionalTarget || new THREE.Vector3();
  4262. result.subVectors( c, b );
  4263. v0.subVectors( a, b );
  4264. result.cross( v0 );
  4265. var resultLengthSq = result.lengthSq();
  4266. if ( resultLengthSq > 0 ) {
  4267. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4268. }
  4269. return result.set( 0, 0, 0 );
  4270. };
  4271. }();
  4272. // static/instance method to calculate barycentric coordinates
  4273. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4274. THREE.Triangle.barycoordFromPoint = function () {
  4275. var v0 = new THREE.Vector3();
  4276. var v1 = new THREE.Vector3();
  4277. var v2 = new THREE.Vector3();
  4278. return function ( point, a, b, c, optionalTarget ) {
  4279. v0.subVectors( c, a );
  4280. v1.subVectors( b, a );
  4281. v2.subVectors( point, a );
  4282. var dot00 = v0.dot( v0 );
  4283. var dot01 = v0.dot( v1 );
  4284. var dot02 = v0.dot( v2 );
  4285. var dot11 = v1.dot( v1 );
  4286. var dot12 = v1.dot( v2 );
  4287. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4288. var result = optionalTarget || new THREE.Vector3();
  4289. // collinear or singular triangle
  4290. if ( denom === 0 ) {
  4291. // arbitrary location outside of triangle?
  4292. // not sure if this is the best idea, maybe should be returning undefined
  4293. return result.set( - 2, - 1, - 1 );
  4294. }
  4295. var invDenom = 1 / denom;
  4296. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4297. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4298. // barycentric coordinates must always sum to 1
  4299. return result.set( 1 - u - v, v, u );
  4300. };
  4301. }();
  4302. THREE.Triangle.containsPoint = function () {
  4303. var v1 = new THREE.Vector3();
  4304. return function ( point, a, b, c ) {
  4305. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4306. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4307. };
  4308. }();
  4309. THREE.Triangle.prototype = {
  4310. constructor: THREE.Triangle,
  4311. set: function ( a, b, c ) {
  4312. this.a.copy( a );
  4313. this.b.copy( b );
  4314. this.c.copy( c );
  4315. return this;
  4316. },
  4317. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4318. this.a.copy( points[ i0 ] );
  4319. this.b.copy( points[ i1 ] );
  4320. this.c.copy( points[ i2 ] );
  4321. return this;
  4322. },
  4323. copy: function ( triangle ) {
  4324. this.a.copy( triangle.a );
  4325. this.b.copy( triangle.b );
  4326. this.c.copy( triangle.c );
  4327. return this;
  4328. },
  4329. area: function () {
  4330. var v0 = new THREE.Vector3();
  4331. var v1 = new THREE.Vector3();
  4332. return function () {
  4333. v0.subVectors( this.c, this.b );
  4334. v1.subVectors( this.a, this.b );
  4335. return v0.cross( v1 ).length() * 0.5;
  4336. };
  4337. }(),
  4338. midpoint: function ( optionalTarget ) {
  4339. var result = optionalTarget || new THREE.Vector3();
  4340. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4341. },
  4342. normal: function ( optionalTarget ) {
  4343. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4344. },
  4345. plane: function ( optionalTarget ) {
  4346. var result = optionalTarget || new THREE.Plane();
  4347. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4348. },
  4349. barycoordFromPoint: function ( point, optionalTarget ) {
  4350. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4351. },
  4352. containsPoint: function ( point ) {
  4353. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4354. },
  4355. equals: function ( triangle ) {
  4356. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4357. },
  4358. clone: function () {
  4359. return new THREE.Triangle().copy( this );
  4360. }
  4361. };
  4362. // File:src/core/Clock.js
  4363. /**
  4364. * @author alteredq / http://alteredqualia.com/
  4365. */
  4366. THREE.Clock = function ( autoStart ) {
  4367. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4368. this.startTime = 0;
  4369. this.oldTime = 0;
  4370. this.elapsedTime = 0;
  4371. this.running = false;
  4372. };
  4373. THREE.Clock.prototype = {
  4374. constructor: THREE.Clock,
  4375. start: function () {
  4376. this.startTime = self.performance !== undefined && self.performance.now !== undefined
  4377. ? self.performance.now()
  4378. : Date.now();
  4379. this.oldTime = this.startTime;
  4380. this.running = true;
  4381. },
  4382. stop: function () {
  4383. this.getElapsedTime();
  4384. this.running = false;
  4385. },
  4386. getElapsedTime: function () {
  4387. this.getDelta();
  4388. return this.elapsedTime;
  4389. },
  4390. getDelta: function () {
  4391. var diff = 0;
  4392. if ( this.autoStart && ! this.running ) {
  4393. this.start();
  4394. }
  4395. if ( this.running ) {
  4396. var newTime = self.performance !== undefined && self.performance.now !== undefined
  4397. ? self.performance.now()
  4398. : Date.now();
  4399. diff = 0.001 * ( newTime - this.oldTime );
  4400. this.oldTime = newTime;
  4401. this.elapsedTime += diff;
  4402. }
  4403. return diff;
  4404. }
  4405. };
  4406. // File:src/core/EventDispatcher.js
  4407. /**
  4408. * https://github.com/mrdoob/eventdispatcher.js/
  4409. */
  4410. THREE.EventDispatcher = function () {};
  4411. THREE.EventDispatcher.prototype = {
  4412. constructor: THREE.EventDispatcher,
  4413. apply: function ( object ) {
  4414. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4415. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4416. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4417. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4418. },
  4419. addEventListener: function ( type, listener ) {
  4420. if ( this._listeners === undefined ) this._listeners = {};
  4421. var listeners = this._listeners;
  4422. if ( listeners[ type ] === undefined ) {
  4423. listeners[ type ] = [];
  4424. }
  4425. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4426. listeners[ type ].push( listener );
  4427. }
  4428. },
  4429. hasEventListener: function ( type, listener ) {
  4430. if ( this._listeners === undefined ) return false;
  4431. var listeners = this._listeners;
  4432. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4433. return true;
  4434. }
  4435. return false;
  4436. },
  4437. removeEventListener: function ( type, listener ) {
  4438. if ( this._listeners === undefined ) return;
  4439. var listeners = this._listeners;
  4440. var listenerArray = listeners[ type ];
  4441. if ( listenerArray !== undefined ) {
  4442. var index = listenerArray.indexOf( listener );
  4443. if ( index !== - 1 ) {
  4444. listenerArray.splice( index, 1 );
  4445. }
  4446. }
  4447. },
  4448. dispatchEvent: function ( event ) {
  4449. if ( this._listeners === undefined ) return;
  4450. var listeners = this._listeners;
  4451. var listenerArray = listeners[ event.type ];
  4452. if ( listenerArray !== undefined ) {
  4453. event.target = this;
  4454. var array = [];
  4455. var length = listenerArray.length;
  4456. for ( var i = 0; i < length; i ++ ) {
  4457. array[ i ] = listenerArray[ i ];
  4458. }
  4459. for ( var i = 0; i < length; i ++ ) {
  4460. array[ i ].call( this, event );
  4461. }
  4462. }
  4463. }
  4464. };
  4465. // File:src/core/Raycaster.js
  4466. /**
  4467. * @author mrdoob / http://mrdoob.com/
  4468. * @author bhouston / http://exocortex.com/
  4469. * @author stephomi / http://stephaneginier.com/
  4470. */
  4471. ( function ( THREE ) {
  4472. THREE.Raycaster = function ( origin, direction, near, far ) {
  4473. this.ray = new THREE.Ray( origin, direction );
  4474. // direction is assumed to be normalized (for accurate distance calculations)
  4475. this.near = near || 0;
  4476. this.far = far || Infinity;
  4477. this.params = {
  4478. Sprite: {},
  4479. Mesh: {},
  4480. PointCloud: { threshold: 1 },
  4481. LOD: {},
  4482. Line: {}
  4483. };
  4484. };
  4485. var descSort = function ( a, b ) {
  4486. return a.distance - b.distance;
  4487. };
  4488. var intersectObject = function ( object, raycaster, intersects, recursive ) {
  4489. if ( object.visible === false ) return;
  4490. object.raycast( raycaster, intersects );
  4491. if ( recursive === true ) {
  4492. var children = object.children;
  4493. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4494. intersectObject( children[ i ], raycaster, intersects, true );
  4495. }
  4496. }
  4497. };
  4498. //
  4499. THREE.Raycaster.prototype = {
  4500. constructor: THREE.Raycaster,
  4501. linePrecision: 1,
  4502. set: function ( origin, direction ) {
  4503. // direction is assumed to be normalized (for accurate distance calculations)
  4504. this.ray.set( origin, direction );
  4505. },
  4506. setFromCamera: function ( coords, camera ) {
  4507. if ( camera instanceof THREE.PerspectiveCamera ) {
  4508. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4509. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4510. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4511. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4512. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4513. } else {
  4514. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4515. }
  4516. },
  4517. intersectObject: function ( object, recursive ) {
  4518. var intersects = [];
  4519. intersectObject( object, this, intersects, recursive );
  4520. intersects.sort( descSort );
  4521. return intersects;
  4522. },
  4523. intersectObjects: function ( objects, recursive ) {
  4524. var intersects = [];
  4525. if ( Array.isArray( objects ) === false ) {
  4526. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4527. return intersects;
  4528. }
  4529. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4530. intersectObject( objects[ i ], this, intersects, recursive );
  4531. }
  4532. intersects.sort( descSort );
  4533. return intersects;
  4534. }
  4535. };
  4536. }( THREE ) );
  4537. // File:src/core/Object3D.js
  4538. /**
  4539. * @author mrdoob / http://mrdoob.com/
  4540. * @author mikael emtinger / http://gomo.se/
  4541. * @author alteredq / http://alteredqualia.com/
  4542. * @author WestLangley / http://github.com/WestLangley
  4543. * @author elephantatwork / www.elephantatwork.ch
  4544. */
  4545. THREE.Object3D = function () {
  4546. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4547. this.uuid = THREE.Math.generateUUID();
  4548. this.name = '';
  4549. this.type = 'Object3D';
  4550. this.parent = null;
  4551. this.children = [];
  4552. this.up = THREE.Object3D.DefaultUp.clone();
  4553. var position = new THREE.Vector3();
  4554. var rotation = new THREE.Euler();
  4555. var quaternion = new THREE.Quaternion();
  4556. var scale = new THREE.Vector3( 1, 1, 1 );
  4557. var onRotationChange = function () {
  4558. quaternion.setFromEuler( rotation, false );
  4559. };
  4560. var onQuaternionChange = function () {
  4561. rotation.setFromQuaternion( quaternion, undefined, false );
  4562. };
  4563. rotation.onChange( onRotationChange );
  4564. quaternion.onChange( onQuaternionChange );
  4565. Object.defineProperties( this, {
  4566. position: {
  4567. enumerable: true,
  4568. value: position
  4569. },
  4570. rotation: {
  4571. enumerable: true,
  4572. value: rotation
  4573. },
  4574. quaternion: {
  4575. enumerable: true,
  4576. value: quaternion
  4577. },
  4578. scale: {
  4579. enumerable: true,
  4580. value: scale
  4581. }
  4582. } );
  4583. this.rotationAutoUpdate = true;
  4584. this.matrix = new THREE.Matrix4();
  4585. this.matrixWorld = new THREE.Matrix4();
  4586. this.matrixAutoUpdate = true;
  4587. this.matrixWorldNeedsUpdate = false;
  4588. this.visible = true;
  4589. this.castShadow = false;
  4590. this.receiveShadow = false;
  4591. this.frustumCulled = true;
  4592. this.renderOrder = 0;
  4593. this.userData = {};
  4594. };
  4595. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4596. THREE.Object3D.prototype = {
  4597. constructor: THREE.Object3D,
  4598. get eulerOrder () {
  4599. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4600. return this.rotation.order;
  4601. },
  4602. set eulerOrder ( value ) {
  4603. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4604. this.rotation.order = value;
  4605. },
  4606. get useQuaternion () {
  4607. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4608. },
  4609. set useQuaternion ( value ) {
  4610. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4611. },
  4612. set renderDepth ( value ) {
  4613. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  4614. },
  4615. applyMatrix: function ( matrix ) {
  4616. this.matrix.multiplyMatrices( matrix, this.matrix );
  4617. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4618. },
  4619. setRotationFromAxisAngle: function ( axis, angle ) {
  4620. // assumes axis is normalized
  4621. this.quaternion.setFromAxisAngle( axis, angle );
  4622. },
  4623. setRotationFromEuler: function ( euler ) {
  4624. this.quaternion.setFromEuler( euler, true );
  4625. },
  4626. setRotationFromMatrix: function ( m ) {
  4627. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4628. this.quaternion.setFromRotationMatrix( m );
  4629. },
  4630. setRotationFromQuaternion: function ( q ) {
  4631. // assumes q is normalized
  4632. this.quaternion.copy( q );
  4633. },
  4634. rotateOnAxis: function () {
  4635. // rotate object on axis in object space
  4636. // axis is assumed to be normalized
  4637. var q1 = new THREE.Quaternion();
  4638. return function ( axis, angle ) {
  4639. q1.setFromAxisAngle( axis, angle );
  4640. this.quaternion.multiply( q1 );
  4641. return this;
  4642. };
  4643. }(),
  4644. rotateX: function () {
  4645. var v1 = new THREE.Vector3( 1, 0, 0 );
  4646. return function ( angle ) {
  4647. return this.rotateOnAxis( v1, angle );
  4648. };
  4649. }(),
  4650. rotateY: function () {
  4651. var v1 = new THREE.Vector3( 0, 1, 0 );
  4652. return function ( angle ) {
  4653. return this.rotateOnAxis( v1, angle );
  4654. };
  4655. }(),
  4656. rotateZ: function () {
  4657. var v1 = new THREE.Vector3( 0, 0, 1 );
  4658. return function ( angle ) {
  4659. return this.rotateOnAxis( v1, angle );
  4660. };
  4661. }(),
  4662. translateOnAxis: function () {
  4663. // translate object by distance along axis in object space
  4664. // axis is assumed to be normalized
  4665. var v1 = new THREE.Vector3();
  4666. return function ( axis, distance ) {
  4667. v1.copy( axis ).applyQuaternion( this.quaternion );
  4668. this.position.add( v1.multiplyScalar( distance ) );
  4669. return this;
  4670. };
  4671. }(),
  4672. translate: function ( distance, axis ) {
  4673. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4674. return this.translateOnAxis( axis, distance );
  4675. },
  4676. translateX: function () {
  4677. var v1 = new THREE.Vector3( 1, 0, 0 );
  4678. return function ( distance ) {
  4679. return this.translateOnAxis( v1, distance );
  4680. };
  4681. }(),
  4682. translateY: function () {
  4683. var v1 = new THREE.Vector3( 0, 1, 0 );
  4684. return function ( distance ) {
  4685. return this.translateOnAxis( v1, distance );
  4686. };
  4687. }(),
  4688. translateZ: function () {
  4689. var v1 = new THREE.Vector3( 0, 0, 1 );
  4690. return function ( distance ) {
  4691. return this.translateOnAxis( v1, distance );
  4692. };
  4693. }(),
  4694. localToWorld: function ( vector ) {
  4695. return vector.applyMatrix4( this.matrixWorld );
  4696. },
  4697. worldToLocal: function () {
  4698. var m1 = new THREE.Matrix4();
  4699. return function ( vector ) {
  4700. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4701. };
  4702. }(),
  4703. lookAt: function () {
  4704. // This routine does not support objects with rotated and/or translated parent(s)
  4705. var m1 = new THREE.Matrix4();
  4706. return function ( vector ) {
  4707. m1.lookAt( vector, this.position, this.up );
  4708. this.quaternion.setFromRotationMatrix( m1 );
  4709. };
  4710. }(),
  4711. add: function ( object ) {
  4712. if ( arguments.length > 1 ) {
  4713. for ( var i = 0; i < arguments.length; i ++ ) {
  4714. this.add( arguments[ i ] );
  4715. }
  4716. return this;
  4717. }
  4718. if ( object === this ) {
  4719. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4720. return this;
  4721. }
  4722. if ( object instanceof THREE.Object3D ) {
  4723. if ( object.parent !== null ) {
  4724. object.parent.remove( object );
  4725. }
  4726. object.parent = this;
  4727. object.dispatchEvent( { type: 'added' } );
  4728. this.children.push( object );
  4729. } else {
  4730. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4731. }
  4732. return this;
  4733. },
  4734. remove: function ( object ) {
  4735. if ( arguments.length > 1 ) {
  4736. for ( var i = 0; i < arguments.length; i ++ ) {
  4737. this.remove( arguments[ i ] );
  4738. }
  4739. }
  4740. var index = this.children.indexOf( object );
  4741. if ( index !== - 1 ) {
  4742. object.parent = null;
  4743. object.dispatchEvent( { type: 'removed' } );
  4744. this.children.splice( index, 1 );
  4745. }
  4746. },
  4747. getChildByName: function ( name ) {
  4748. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4749. return this.getObjectByName( name );
  4750. },
  4751. getObjectById: function ( id ) {
  4752. return this.getObjectByProperty( 'id', id );
  4753. },
  4754. getObjectByName: function ( name ) {
  4755. return this.getObjectByProperty( 'name', name );
  4756. },
  4757. getObjectByProperty: function ( name, value ) {
  4758. if ( this[ name ] === value ) return this;
  4759. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4760. var child = this.children[ i ];
  4761. var object = child.getObjectByProperty( name, value );
  4762. if ( object !== undefined ) {
  4763. return object;
  4764. }
  4765. }
  4766. return undefined;
  4767. },
  4768. getWorldPosition: function ( optionalTarget ) {
  4769. var result = optionalTarget || new THREE.Vector3();
  4770. this.updateMatrixWorld( true );
  4771. return result.setFromMatrixPosition( this.matrixWorld );
  4772. },
  4773. getWorldQuaternion: function () {
  4774. var position = new THREE.Vector3();
  4775. var scale = new THREE.Vector3();
  4776. return function ( optionalTarget ) {
  4777. var result = optionalTarget || new THREE.Quaternion();
  4778. this.updateMatrixWorld( true );
  4779. this.matrixWorld.decompose( position, result, scale );
  4780. return result;
  4781. };
  4782. }(),
  4783. getWorldRotation: function () {
  4784. var quaternion = new THREE.Quaternion();
  4785. return function ( optionalTarget ) {
  4786. var result = optionalTarget || new THREE.Euler();
  4787. this.getWorldQuaternion( quaternion );
  4788. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4789. };
  4790. }(),
  4791. getWorldScale: function () {
  4792. var position = new THREE.Vector3();
  4793. var quaternion = new THREE.Quaternion();
  4794. return function ( optionalTarget ) {
  4795. var result = optionalTarget || new THREE.Vector3();
  4796. this.updateMatrixWorld( true );
  4797. this.matrixWorld.decompose( position, quaternion, result );
  4798. return result;
  4799. };
  4800. }(),
  4801. getWorldDirection: function () {
  4802. var quaternion = new THREE.Quaternion();
  4803. return function ( optionalTarget ) {
  4804. var result = optionalTarget || new THREE.Vector3();
  4805. this.getWorldQuaternion( quaternion );
  4806. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4807. };
  4808. }(),
  4809. raycast: function () {},
  4810. traverse: function ( callback ) {
  4811. callback( this );
  4812. var children = this.children;
  4813. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4814. children[ i ].traverse( callback );
  4815. }
  4816. },
  4817. traverseVisible: function ( callback ) {
  4818. if ( this.visible === false ) return;
  4819. callback( this );
  4820. var children = this.children;
  4821. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4822. children[ i ].traverseVisible( callback );
  4823. }
  4824. },
  4825. traverseAncestors: function ( callback ) {
  4826. var parent = this.parent;
  4827. if ( parent !== null ) {
  4828. callback( parent );
  4829. parent.traverseAncestors( callback );
  4830. }
  4831. },
  4832. updateMatrix: function () {
  4833. this.matrix.compose( this.position, this.quaternion, this.scale );
  4834. this.matrixWorldNeedsUpdate = true;
  4835. },
  4836. updateMatrixWorld: function ( force ) {
  4837. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4838. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4839. if ( this.parent === null ) {
  4840. this.matrixWorld.copy( this.matrix );
  4841. } else {
  4842. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4843. }
  4844. this.matrixWorldNeedsUpdate = false;
  4845. force = true;
  4846. }
  4847. // update children
  4848. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4849. this.children[ i ].updateMatrixWorld( force );
  4850. }
  4851. },
  4852. toJSON: function ( meta ) {
  4853. var isRootObject = ( meta === undefined );
  4854. var data = {};
  4855. // meta is a hash used to collect geometries, materials.
  4856. // not providing it implies that this is the root object
  4857. // being serialized.
  4858. if ( isRootObject ) {
  4859. // initialize meta obj
  4860. meta = {
  4861. geometries: {},
  4862. materials: {},
  4863. textures: {},
  4864. images: {}
  4865. };
  4866. data.metadata = {
  4867. version: 4.4,
  4868. type: 'Object',
  4869. generator: 'Object3D.toJSON'
  4870. };
  4871. }
  4872. // standard Object3D serialization
  4873. data.uuid = this.uuid;
  4874. data.type = this.type;
  4875. if ( this.name !== '' ) data.name = this.name;
  4876. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4877. if ( this.visible !== true ) data.visible = this.visible;
  4878. data.matrix = this.matrix.toArray();
  4879. if ( this.children.length > 0 ) {
  4880. data.children = [];
  4881. for ( var i = 0; i < this.children.length; i ++ ) {
  4882. data.children.push( this.children[ i ].toJSON( meta ).object );
  4883. }
  4884. }
  4885. var output = {};
  4886. if ( isRootObject ) {
  4887. var geometries = extractFromCache( meta.geometries );
  4888. var materials = extractFromCache( meta.materials );
  4889. var textures = extractFromCache( meta.textures );
  4890. var images = extractFromCache( meta.images );
  4891. if ( geometries.length > 0 ) output.geometries = geometries;
  4892. if ( materials.length > 0 ) output.materials = materials;
  4893. if ( textures.length > 0 ) output.textures = textures;
  4894. if ( images.length > 0 ) output.images = images;
  4895. }
  4896. output.object = data;
  4897. return output;
  4898. // extract data from the cache hash
  4899. // remove metadata on each item
  4900. // and return as array
  4901. function extractFromCache ( cache ) {
  4902. var values = [];
  4903. for ( var key in cache ) {
  4904. var data = cache[ key ];
  4905. delete data.metadata;
  4906. values.push( data );
  4907. }
  4908. return values;
  4909. }
  4910. },
  4911. clone: function ( recursive ) {
  4912. return new THREE.Object3D().copy( this, recursive );
  4913. },
  4914. copy: function ( source, recursive ) {
  4915. if ( recursive === undefined ) recursive = true;
  4916. this.name = source.name;
  4917. this.up.copy( source.up );
  4918. this.position.copy( source.position );
  4919. this.quaternion.copy( source.quaternion );
  4920. this.scale.copy( source.scale );
  4921. this.rotationAutoUpdate = source.rotationAutoUpdate;
  4922. this.matrix.copy( source.matrix );
  4923. this.matrixWorld.copy( source.matrixWorld );
  4924. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4925. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4926. this.visible = source.visible;
  4927. this.castShadow = source.castShadow;
  4928. this.receiveShadow = source.receiveShadow;
  4929. this.frustumCulled = source.frustumCulled;
  4930. this.renderOrder = source.renderOrder;
  4931. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4932. if ( recursive === true ) {
  4933. for ( var i = 0; i < source.children.length; i ++ ) {
  4934. var child = source.children[ i ];
  4935. this.add( child.clone() );
  4936. }
  4937. }
  4938. return this;
  4939. }
  4940. };
  4941. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4942. THREE.Object3DIdCount = 0;
  4943. // File:src/core/Face3.js
  4944. /**
  4945. * @author mrdoob / http://mrdoob.com/
  4946. * @author alteredq / http://alteredqualia.com/
  4947. */
  4948. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  4949. this.a = a;
  4950. this.b = b;
  4951. this.c = c;
  4952. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  4953. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4954. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  4955. this.vertexColors = Array.isArray( color ) ? color : [];
  4956. this.vertexTangents = [];
  4957. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4958. };
  4959. THREE.Face3.prototype = {
  4960. constructor: THREE.Face3,
  4961. copy: function ( source ) {
  4962. this.a = source.a;
  4963. this.b = source.b;
  4964. this.c = source.c;
  4965. this.normal.copy( source.normal );
  4966. this.color.copy( source.color );
  4967. this.materialIndex = source.materialIndex;
  4968. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4969. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4970. }
  4971. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4972. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4973. }
  4974. for ( var i = 0, il = source.vertexTangents.length; i < il; i ++ ) {
  4975. this.vertexTangents[ i ] = source.vertexTangents[ i ].clone();
  4976. }
  4977. return this;
  4978. },
  4979. clone: function () {
  4980. return new THREE.Face3().copy( this );
  4981. }
  4982. };
  4983. // File:src/core/Face4.js
  4984. /**
  4985. * @author mrdoob / http://mrdoob.com/
  4986. */
  4987. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  4988. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  4989. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  4990. };
  4991. // File:src/core/BufferAttribute.js
  4992. /**
  4993. * @author mrdoob / http://mrdoob.com/
  4994. */
  4995. THREE.BufferAttribute = function ( array, itemSize ) {
  4996. this.uuid = THREE.Math.generateUUID();
  4997. this.array = array;
  4998. this.itemSize = itemSize;
  4999. this.version = 0;
  5000. };
  5001. THREE.BufferAttribute.prototype = {
  5002. constructor: THREE.BufferAttribute,
  5003. get length () {
  5004. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5005. return this.array.length;
  5006. },
  5007. get count() {
  5008. return this.array.length / this.itemSize;
  5009. },
  5010. set needsUpdate( value ) {
  5011. if ( value === true ) this.version ++;
  5012. },
  5013. copyAt: function ( index1, attribute, index2 ) {
  5014. index1 *= this.itemSize;
  5015. index2 *= attribute.itemSize;
  5016. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5017. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5018. }
  5019. return this;
  5020. },
  5021. copyArray: function ( array ) {
  5022. this.array.set( array );
  5023. return this;
  5024. },
  5025. copyColorsArray: function ( colors ) {
  5026. var array = this.array, offset = 0;
  5027. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5028. var color = colors[ i ];
  5029. if ( color === undefined ) {
  5030. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5031. color = new THREE.Color();
  5032. }
  5033. array[ offset ++ ] = color.r;
  5034. array[ offset ++ ] = color.g;
  5035. array[ offset ++ ] = color.b;
  5036. }
  5037. return this;
  5038. },
  5039. copyIndicesArray: function ( indices ) {
  5040. var array = this.array, offset = 0;
  5041. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5042. var index = indices[ i ];
  5043. array[ offset ++ ] = index.a;
  5044. array[ offset ++ ] = index.b;
  5045. array[ offset ++ ] = index.c;
  5046. }
  5047. return this;
  5048. },
  5049. copyVector2sArray: function ( vectors ) {
  5050. var array = this.array, offset = 0;
  5051. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5052. var vector = vectors[ i ];
  5053. if ( vector === undefined ) {
  5054. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5055. vector = new THREE.Vector2();
  5056. }
  5057. array[ offset ++ ] = vector.x;
  5058. array[ offset ++ ] = vector.y;
  5059. }
  5060. return this;
  5061. },
  5062. copyVector3sArray: function ( vectors ) {
  5063. var array = this.array, offset = 0;
  5064. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5065. var vector = vectors[ i ];
  5066. if ( vector === undefined ) {
  5067. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5068. vector = new THREE.Vector3();
  5069. }
  5070. array[ offset ++ ] = vector.x;
  5071. array[ offset ++ ] = vector.y;
  5072. array[ offset ++ ] = vector.z;
  5073. }
  5074. return this;
  5075. },
  5076. copyVector4sArray: function ( vectors ) {
  5077. var array = this.array, offset = 0;
  5078. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5079. var vector = vectors[ i ];
  5080. if ( vector === undefined ) {
  5081. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5082. vector = new THREE.Vector4();
  5083. }
  5084. array[ offset ++ ] = vector.x;
  5085. array[ offset ++ ] = vector.y;
  5086. array[ offset ++ ] = vector.z;
  5087. array[ offset ++ ] = vector.w;
  5088. }
  5089. return this;
  5090. },
  5091. set: function ( value, offset ) {
  5092. if ( offset === undefined ) offset = 0;
  5093. this.array.set( value, offset );
  5094. return this;
  5095. },
  5096. getX: function ( index ) {
  5097. return this.array[ index * this.itemSize ];
  5098. },
  5099. setX: function ( index, x ) {
  5100. this.array[ index * this.itemSize ] = x;
  5101. return this;
  5102. },
  5103. getY: function ( index ) {
  5104. return this.array[ index * this.itemSize + 1 ];
  5105. },
  5106. setY: function ( index, y ) {
  5107. this.array[ index * this.itemSize + 1 ] = y;
  5108. return this;
  5109. },
  5110. getZ: function ( index ) {
  5111. return this.array[ index * this.itemSize + 2 ];
  5112. },
  5113. setZ: function ( index, z ) {
  5114. this.array[ index * this.itemSize + 2 ] = z;
  5115. return this;
  5116. },
  5117. getW: function ( index ) {
  5118. return this.array[ index * this.itemSize + 3 ];
  5119. },
  5120. setW: function ( index, w ) {
  5121. this.array[ index * this.itemSize + 3 ] = w;
  5122. return this;
  5123. },
  5124. setXY: function ( index, x, y ) {
  5125. index *= this.itemSize;
  5126. this.array[ index + 0 ] = x;
  5127. this.array[ index + 1 ] = y;
  5128. return this;
  5129. },
  5130. setXYZ: function ( index, x, y, z ) {
  5131. index *= this.itemSize;
  5132. this.array[ index + 0 ] = x;
  5133. this.array[ index + 1 ] = y;
  5134. this.array[ index + 2 ] = z;
  5135. return this;
  5136. },
  5137. setXYZW: function ( index, x, y, z, w ) {
  5138. index *= this.itemSize;
  5139. this.array[ index + 0 ] = x;
  5140. this.array[ index + 1 ] = y;
  5141. this.array[ index + 2 ] = z;
  5142. this.array[ index + 3 ] = w;
  5143. return this;
  5144. },
  5145. clone: function () {
  5146. return new THREE.BufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5147. }
  5148. };
  5149. //
  5150. THREE.Int8Attribute = function ( array, itemSize ) {
  5151. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5152. };
  5153. THREE.Uint8Attribute = function ( array, itemSize ) {
  5154. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5155. };
  5156. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5157. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5158. };
  5159. THREE.Int16Attribute = function ( array, itemSize ) {
  5160. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5161. };
  5162. THREE.Uint16Attribute = function ( array, itemSize ) {
  5163. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5164. };
  5165. THREE.Int32Attribute = function ( array, itemSize ) {
  5166. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5167. };
  5168. THREE.Uint32Attribute = function ( array, itemSize ) {
  5169. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5170. };
  5171. THREE.Float32Attribute = function ( array, itemSize ) {
  5172. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5173. };
  5174. THREE.Float64Attribute = function ( array, itemSize ) {
  5175. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5176. };
  5177. // File:src/core/DynamicBufferAttribute.js
  5178. /**
  5179. * @author benaadams / https://twitter.com/ben_a_adams
  5180. * @author mrdoob / http://mrdoob.com/
  5181. */
  5182. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5183. THREE.BufferAttribute.call( this, array, itemSize );
  5184. this.updateRange = { offset: 0, count: - 1 };
  5185. };
  5186. THREE.DynamicBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5187. THREE.DynamicBufferAttribute.prototype.constructor = THREE.DynamicBufferAttribute;
  5188. THREE.DynamicBufferAttribute.prototype.clone = function () {
  5189. return new THREE.DynamicBufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5190. };
  5191. // File:src/core/InstancedBufferAttribute.js
  5192. /**
  5193. * @author benaadams / https://twitter.com/ben_a_adams
  5194. */
  5195. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute, dynamic ) {
  5196. THREE.DynamicBufferAttribute.call( this, array, itemSize );
  5197. this.dynamic = dynamic || false;
  5198. this.meshPerAttribute = meshPerAttribute || 1;
  5199. };
  5200. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.DynamicBufferAttribute.prototype );
  5201. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5202. THREE.InstancedBufferAttribute.prototype.clone = function () {
  5203. return new THREE.InstancedBufferAttribute( new this.array.constructor( this.array ), this.itemSize, this.meshPerAttribute, this.dynamic );
  5204. };
  5205. // File:src/core/InterleavedBuffer.js
  5206. /**
  5207. * @author benaadams / https://twitter.com/ben_a_adams
  5208. */
  5209. THREE.InterleavedBuffer = function ( array, stride, dynamic ) {
  5210. this.uuid = THREE.Math.generateUUID();
  5211. this.array = array;
  5212. this.stride = stride;
  5213. this.version = 0;
  5214. this.dynamic = dynamic || false;
  5215. this.updateRange = { offset: 0, count: - 1 };
  5216. };
  5217. THREE.InterleavedBuffer.prototype = {
  5218. constructor: THREE.InterleavedBuffer,
  5219. get length () {
  5220. return this.array.length;
  5221. },
  5222. get count () {
  5223. return this.array.length / this.stride;
  5224. },
  5225. set needsUpdate( value ) {
  5226. if ( value === true ) this.version ++;
  5227. },
  5228. copyAt: function ( index1, attribute, index2 ) {
  5229. index1 *= this.stride;
  5230. index2 *= attribute.stride;
  5231. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5232. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5233. }
  5234. return this;
  5235. },
  5236. set: function ( value, offset ) {
  5237. if ( offset === undefined ) offset = 0;
  5238. this.array.set( value, offset );
  5239. return this;
  5240. },
  5241. clone: function () {
  5242. return new THREE.InterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic );
  5243. }
  5244. };
  5245. // File:src/core/InstancedInterleavedBuffer.js
  5246. /**
  5247. * @author benaadams / https://twitter.com/ben_a_adams
  5248. */
  5249. THREE.InstancedInterleavedBuffer = function ( array, stride, dynamic, meshPerAttribute ) {
  5250. THREE.InterleavedBuffer.call( this, array, stride, dynamic );
  5251. this.meshPerAttribute = meshPerAttribute || 1;
  5252. };
  5253. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5254. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5255. THREE.InstancedInterleavedBuffer.prototype.clone = function () {
  5256. return new THREE.InstancedInterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic, this.meshPerAttribute );
  5257. };
  5258. // File:src/core/InterleavedBufferAttribute.js
  5259. /**
  5260. * @author benaadams / https://twitter.com/ben_a_adams
  5261. */
  5262. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5263. this.uuid = THREE.Math.generateUUID();
  5264. this.data = interleavedBuffer;
  5265. this.itemSize = itemSize;
  5266. this.offset = offset;
  5267. };
  5268. THREE.InterleavedBufferAttribute.prototype = {
  5269. constructor: THREE.InterleavedBufferAttribute,
  5270. get length() {
  5271. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5272. return this.array.length;
  5273. },
  5274. get count() {
  5275. return this.data.array.length / this.data.stride;
  5276. },
  5277. setX: function ( index, x ) {
  5278. this.data.array[ index * this.data.stride + this.offset ] = x;
  5279. return this;
  5280. },
  5281. setY: function ( index, y ) {
  5282. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5283. return this;
  5284. },
  5285. setZ: function ( index, z ) {
  5286. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5287. return this;
  5288. },
  5289. setW: function ( index, w ) {
  5290. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5291. return this;
  5292. },
  5293. getX: function ( index ) {
  5294. return this.data.array[ index * this.data.stride + this.offset ];
  5295. },
  5296. getY: function ( index ) {
  5297. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5298. },
  5299. getZ: function ( index ) {
  5300. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5301. },
  5302. getW: function ( index ) {
  5303. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5304. },
  5305. setXY: function ( index, x, y ) {
  5306. index = index * this.data.stride + this.offset;
  5307. this.data.array[ index + 0 ] = x;
  5308. this.data.array[ index + 1 ] = y;
  5309. return this;
  5310. },
  5311. setXYZ: function ( index, x, y, z ) {
  5312. index = index * this.data.stride + this.offset;
  5313. this.data.array[ index + 0 ] = x;
  5314. this.data.array[ index + 1 ] = y;
  5315. this.data.array[ index + 2 ] = z;
  5316. return this;
  5317. },
  5318. setXYZW: function ( index, x, y, z, w ) {
  5319. index = index * this.data.stride + this.offset;
  5320. this.data.array[ index + 0 ] = x;
  5321. this.data.array[ index + 1 ] = y;
  5322. this.data.array[ index + 2 ] = z;
  5323. this.data.array[ index + 3 ] = w;
  5324. return this;
  5325. }
  5326. };
  5327. // File:src/core/Geometry.js
  5328. /**
  5329. * @author mrdoob / http://mrdoob.com/
  5330. * @author kile / http://kile.stravaganza.org/
  5331. * @author alteredq / http://alteredqualia.com/
  5332. * @author mikael emtinger / http://gomo.se/
  5333. * @author zz85 / http://www.lab4games.net/zz85/blog
  5334. * @author bhouston / http://exocortex.com
  5335. */
  5336. THREE.Geometry = function () {
  5337. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5338. this.uuid = THREE.Math.generateUUID();
  5339. this.name = '';
  5340. this.type = 'Geometry';
  5341. this.vertices = [];
  5342. this.colors = [];
  5343. this.faces = [];
  5344. this.faceVertexUvs = [ [] ];
  5345. this.morphTargets = [];
  5346. this.morphColors = [];
  5347. this.morphNormals = [];
  5348. this.skinWeights = [];
  5349. this.skinIndices = [];
  5350. this.lineDistances = [];
  5351. this.boundingBox = null;
  5352. this.boundingSphere = null;
  5353. this.hasTangents = false;
  5354. // update flags
  5355. this.verticesNeedUpdate = false;
  5356. this.elementsNeedUpdate = false;
  5357. this.uvsNeedUpdate = false;
  5358. this.normalsNeedUpdate = false;
  5359. this.tangentsNeedUpdate = false;
  5360. this.colorsNeedUpdate = false;
  5361. this.lineDistancesNeedUpdate = false;
  5362. };
  5363. THREE.Geometry.prototype = {
  5364. constructor: THREE.Geometry,
  5365. applyMatrix: function ( matrix ) {
  5366. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5367. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5368. var vertex = this.vertices[ i ];
  5369. vertex.applyMatrix4( matrix );
  5370. }
  5371. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5372. var face = this.faces[ i ];
  5373. face.normal.applyMatrix3( normalMatrix ).normalize();
  5374. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5375. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5376. }
  5377. }
  5378. if ( this.boundingBox !== null ) {
  5379. this.computeBoundingBox();
  5380. }
  5381. if ( this.boundingSphere !== null ) {
  5382. this.computeBoundingSphere();
  5383. }
  5384. this.verticesNeedUpdate = true;
  5385. this.normalsNeedUpdate = true;
  5386. },
  5387. rotateX: function () {
  5388. // rotate geometry around world x-axis
  5389. var m1;
  5390. return function rotateX( angle ) {
  5391. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5392. m1.makeRotationX( angle );
  5393. this.applyMatrix( m1 );
  5394. return this;
  5395. };
  5396. }(),
  5397. rotateY: function () {
  5398. // rotate geometry around world y-axis
  5399. var m1;
  5400. return function rotateY( angle ) {
  5401. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5402. m1.makeRotationY( angle );
  5403. this.applyMatrix( m1 );
  5404. return this;
  5405. };
  5406. }(),
  5407. rotateZ: function () {
  5408. // rotate geometry around world z-axis
  5409. var m1;
  5410. return function rotateZ( angle ) {
  5411. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5412. m1.makeRotationZ( angle );
  5413. this.applyMatrix( m1 );
  5414. return this;
  5415. };
  5416. }(),
  5417. translate: function () {
  5418. // translate geometry
  5419. var m1;
  5420. return function translate( x, y, z ) {
  5421. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5422. m1.makeTranslation( x, y, z );
  5423. this.applyMatrix( m1 );
  5424. return this;
  5425. };
  5426. }(),
  5427. scale: function () {
  5428. // scale geometry
  5429. var m1;
  5430. return function scale( x, y, z ) {
  5431. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5432. m1.makeScale( x, y, z );
  5433. this.applyMatrix( m1 );
  5434. return this;
  5435. };
  5436. }(),
  5437. lookAt: function () {
  5438. var obj;
  5439. return function lookAt( vector ) {
  5440. if ( obj === undefined ) obj = new THREE.Object3D();
  5441. obj.lookAt( vector );
  5442. obj.updateMatrix();
  5443. this.applyMatrix( obj.matrix );
  5444. };
  5445. }(),
  5446. fromBufferGeometry: function ( geometry ) {
  5447. var scope = this;
  5448. var attributes = geometry.attributes;
  5449. var vertices = attributes.position.array;
  5450. var indices = attributes.index !== undefined ? attributes.index.array : undefined;
  5451. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5452. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5453. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5454. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5455. var tangents = attributes.tangent !== undefined ? attributes.tangent.array : undefined;
  5456. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5457. if ( tangents !== undefined ) this.hasTangents = true;
  5458. var tempNormals = [];
  5459. var tempUVs = [];
  5460. var tempUVs2 = [];
  5461. var tempTangents = [];
  5462. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5463. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5464. if ( normals !== undefined ) {
  5465. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5466. }
  5467. if ( colors !== undefined ) {
  5468. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5469. }
  5470. if ( uvs !== undefined ) {
  5471. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5472. }
  5473. if ( uvs2 !== undefined ) {
  5474. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5475. }
  5476. if ( tangents !== undefined ) {
  5477. tempTangents.push( new THREE.Vector4( tangents[ k ], tangents[ k + 1 ], tangents[ k + 2 ], tangents[ k + 3 ] ) );
  5478. }
  5479. }
  5480. var addFace = function ( a, b, c ) {
  5481. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5482. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5483. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5484. scope.faces.push( face );
  5485. if ( uvs !== undefined ) {
  5486. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5487. }
  5488. if ( uvs2 !== undefined ) {
  5489. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5490. }
  5491. if ( tangents !== undefined ) {
  5492. face.vertexTangents.push( tempTangents[ a ].clone(), tempTangents[ b ].clone(), tempTangents[ c ].clone() );
  5493. }
  5494. };
  5495. if ( indices !== undefined ) {
  5496. var drawcalls = geometry.drawcalls;
  5497. if ( drawcalls.length > 0 ) {
  5498. for ( var i = 0; i < drawcalls.length; i ++ ) {
  5499. var drawcall = drawcalls[ i ];
  5500. var start = drawcall.start;
  5501. var count = drawcall.count;
  5502. var index = drawcall.index;
  5503. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5504. addFace( index + indices[ j ], index + indices[ j + 1 ], index + indices[ j + 2 ] );
  5505. }
  5506. }
  5507. } else {
  5508. for ( var i = 0; i < indices.length; i += 3 ) {
  5509. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5510. }
  5511. }
  5512. } else {
  5513. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5514. addFace( i, i + 1, i + 2 );
  5515. }
  5516. }
  5517. this.computeFaceNormals();
  5518. if ( geometry.boundingBox !== null ) {
  5519. this.boundingBox = geometry.boundingBox.clone();
  5520. }
  5521. if ( geometry.boundingSphere !== null ) {
  5522. this.boundingSphere = geometry.boundingSphere.clone();
  5523. }
  5524. return this;
  5525. },
  5526. center: function () {
  5527. this.computeBoundingBox();
  5528. var offset = this.boundingBox.center().negate();
  5529. this.translate( offset.x, offset.y, offset.z );
  5530. return offset;
  5531. },
  5532. normalize: function () {
  5533. this.computeBoundingSphere();
  5534. var center = this.boundingSphere.center;
  5535. var radius = this.boundingSphere.radius;
  5536. var s = radius === 0 ? 1 : 1.0 / radius;
  5537. var matrix = new THREE.Matrix4();
  5538. matrix.set(
  5539. s, 0, 0, - s * center.x,
  5540. 0, s, 0, - s * center.y,
  5541. 0, 0, s, - s * center.z,
  5542. 0, 0, 0, 1
  5543. );
  5544. this.applyMatrix( matrix );
  5545. return this;
  5546. },
  5547. computeFaceNormals: function () {
  5548. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5549. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5550. var face = this.faces[ f ];
  5551. var vA = this.vertices[ face.a ];
  5552. var vB = this.vertices[ face.b ];
  5553. var vC = this.vertices[ face.c ];
  5554. cb.subVectors( vC, vB );
  5555. ab.subVectors( vA, vB );
  5556. cb.cross( ab );
  5557. cb.normalize();
  5558. face.normal.copy( cb );
  5559. }
  5560. },
  5561. computeVertexNormals: function ( areaWeighted ) {
  5562. var v, vl, f, fl, face, vertices;
  5563. vertices = new Array( this.vertices.length );
  5564. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5565. vertices[ v ] = new THREE.Vector3();
  5566. }
  5567. if ( areaWeighted ) {
  5568. // vertex normals weighted by triangle areas
  5569. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5570. var vA, vB, vC;
  5571. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5572. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5573. face = this.faces[ f ];
  5574. vA = this.vertices[ face.a ];
  5575. vB = this.vertices[ face.b ];
  5576. vC = this.vertices[ face.c ];
  5577. cb.subVectors( vC, vB );
  5578. ab.subVectors( vA, vB );
  5579. cb.cross( ab );
  5580. vertices[ face.a ].add( cb );
  5581. vertices[ face.b ].add( cb );
  5582. vertices[ face.c ].add( cb );
  5583. }
  5584. } else {
  5585. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5586. face = this.faces[ f ];
  5587. vertices[ face.a ].add( face.normal );
  5588. vertices[ face.b ].add( face.normal );
  5589. vertices[ face.c ].add( face.normal );
  5590. }
  5591. }
  5592. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5593. vertices[ v ].normalize();
  5594. }
  5595. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5596. face = this.faces[ f ];
  5597. var vertexNormals = face.vertexNormals;
  5598. if ( vertexNormals.length === 3 ) {
  5599. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5600. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5601. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5602. } else {
  5603. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5604. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5605. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5606. }
  5607. }
  5608. },
  5609. computeMorphNormals: function () {
  5610. var i, il, f, fl, face;
  5611. // save original normals
  5612. // - create temp variables on first access
  5613. // otherwise just copy (for faster repeated calls)
  5614. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5615. face = this.faces[ f ];
  5616. if ( ! face.__originalFaceNormal ) {
  5617. face.__originalFaceNormal = face.normal.clone();
  5618. } else {
  5619. face.__originalFaceNormal.copy( face.normal );
  5620. }
  5621. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5622. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5623. if ( ! face.__originalVertexNormals[ i ] ) {
  5624. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5625. } else {
  5626. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5627. }
  5628. }
  5629. }
  5630. // use temp geometry to compute face and vertex normals for each morph
  5631. var tmpGeo = new THREE.Geometry();
  5632. tmpGeo.faces = this.faces;
  5633. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5634. // create on first access
  5635. if ( ! this.morphNormals[ i ] ) {
  5636. this.morphNormals[ i ] = {};
  5637. this.morphNormals[ i ].faceNormals = [];
  5638. this.morphNormals[ i ].vertexNormals = [];
  5639. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5640. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5641. var faceNormal, vertexNormals;
  5642. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5643. faceNormal = new THREE.Vector3();
  5644. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5645. dstNormalsFace.push( faceNormal );
  5646. dstNormalsVertex.push( vertexNormals );
  5647. }
  5648. }
  5649. var morphNormals = this.morphNormals[ i ];
  5650. // set vertices to morph target
  5651. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5652. // compute morph normals
  5653. tmpGeo.computeFaceNormals();
  5654. tmpGeo.computeVertexNormals();
  5655. // store morph normals
  5656. var faceNormal, vertexNormals;
  5657. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5658. face = this.faces[ f ];
  5659. faceNormal = morphNormals.faceNormals[ f ];
  5660. vertexNormals = morphNormals.vertexNormals[ f ];
  5661. faceNormal.copy( face.normal );
  5662. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5663. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5664. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5665. }
  5666. }
  5667. // restore original normals
  5668. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5669. face = this.faces[ f ];
  5670. face.normal = face.__originalFaceNormal;
  5671. face.vertexNormals = face.__originalVertexNormals;
  5672. }
  5673. },
  5674. computeTangents: function () {
  5675. // based on http://www.terathon.com/code/tangent.html
  5676. // tangents go to vertices
  5677. var f, fl, v, vl, i, vertexIndex,
  5678. face, uv, vA, vB, vC, uvA, uvB, uvC,
  5679. x1, x2, y1, y2, z1, z2,
  5680. s1, s2, t1, t2, r, t, test,
  5681. tan1 = [], tan2 = [],
  5682. sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
  5683. tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
  5684. n = new THREE.Vector3(), w;
  5685. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5686. tan1[ v ] = new THREE.Vector3();
  5687. tan2[ v ] = new THREE.Vector3();
  5688. }
  5689. function handleTriangle( context, a, b, c, ua, ub, uc ) {
  5690. vA = context.vertices[ a ];
  5691. vB = context.vertices[ b ];
  5692. vC = context.vertices[ c ];
  5693. uvA = uv[ ua ];
  5694. uvB = uv[ ub ];
  5695. uvC = uv[ uc ];
  5696. x1 = vB.x - vA.x;
  5697. x2 = vC.x - vA.x;
  5698. y1 = vB.y - vA.y;
  5699. y2 = vC.y - vA.y;
  5700. z1 = vB.z - vA.z;
  5701. z2 = vC.z - vA.z;
  5702. s1 = uvB.x - uvA.x;
  5703. s2 = uvC.x - uvA.x;
  5704. t1 = uvB.y - uvA.y;
  5705. t2 = uvC.y - uvA.y;
  5706. r = 1.0 / ( s1 * t2 - s2 * t1 );
  5707. sdir.set( ( t2 * x1 - t1 * x2 ) * r,
  5708. ( t2 * y1 - t1 * y2 ) * r,
  5709. ( t2 * z1 - t1 * z2 ) * r );
  5710. tdir.set( ( s1 * x2 - s2 * x1 ) * r,
  5711. ( s1 * y2 - s2 * y1 ) * r,
  5712. ( s1 * z2 - s2 * z1 ) * r );
  5713. tan1[ a ].add( sdir );
  5714. tan1[ b ].add( sdir );
  5715. tan1[ c ].add( sdir );
  5716. tan2[ a ].add( tdir );
  5717. tan2[ b ].add( tdir );
  5718. tan2[ c ].add( tdir );
  5719. }
  5720. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5721. face = this.faces[ f ];
  5722. uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
  5723. handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
  5724. }
  5725. var faceIndex = [ 'a', 'b', 'c', 'd' ];
  5726. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5727. face = this.faces[ f ];
  5728. for ( i = 0; i < Math.min( face.vertexNormals.length, 3 ); i ++ ) {
  5729. n.copy( face.vertexNormals[ i ] );
  5730. vertexIndex = face[ faceIndex[ i ] ];
  5731. t = tan1[ vertexIndex ];
  5732. // Gram-Schmidt orthogonalize
  5733. tmp.copy( t );
  5734. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  5735. // Calculate handedness
  5736. tmp2.crossVectors( face.vertexNormals[ i ], t );
  5737. test = tmp2.dot( tan2[ vertexIndex ] );
  5738. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  5739. face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
  5740. }
  5741. }
  5742. this.hasTangents = true;
  5743. },
  5744. computeLineDistances: function () {
  5745. var d = 0;
  5746. var vertices = this.vertices;
  5747. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5748. if ( i > 0 ) {
  5749. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5750. }
  5751. this.lineDistances[ i ] = d;
  5752. }
  5753. },
  5754. computeBoundingBox: function () {
  5755. if ( this.boundingBox === null ) {
  5756. this.boundingBox = new THREE.Box3();
  5757. }
  5758. this.boundingBox.setFromPoints( this.vertices );
  5759. },
  5760. computeBoundingSphere: function () {
  5761. if ( this.boundingSphere === null ) {
  5762. this.boundingSphere = new THREE.Sphere();
  5763. }
  5764. this.boundingSphere.setFromPoints( this.vertices );
  5765. },
  5766. merge: function ( geometry, matrix, materialIndexOffset ) {
  5767. if ( geometry instanceof THREE.Geometry === false ) {
  5768. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5769. return;
  5770. }
  5771. var normalMatrix,
  5772. vertexOffset = this.vertices.length,
  5773. vertices1 = this.vertices,
  5774. vertices2 = geometry.vertices,
  5775. faces1 = this.faces,
  5776. faces2 = geometry.faces,
  5777. uvs1 = this.faceVertexUvs[ 0 ],
  5778. uvs2 = geometry.faceVertexUvs[ 0 ];
  5779. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5780. if ( matrix !== undefined ) {
  5781. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5782. }
  5783. // vertices
  5784. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5785. var vertex = vertices2[ i ];
  5786. var vertexCopy = vertex.clone();
  5787. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5788. vertices1.push( vertexCopy );
  5789. }
  5790. // faces
  5791. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5792. var face = faces2[ i ], faceCopy, normal, color,
  5793. faceVertexNormals = face.vertexNormals,
  5794. faceVertexColors = face.vertexColors;
  5795. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5796. faceCopy.normal.copy( face.normal );
  5797. if ( normalMatrix !== undefined ) {
  5798. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5799. }
  5800. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5801. normal = faceVertexNormals[ j ].clone();
  5802. if ( normalMatrix !== undefined ) {
  5803. normal.applyMatrix3( normalMatrix ).normalize();
  5804. }
  5805. faceCopy.vertexNormals.push( normal );
  5806. }
  5807. faceCopy.color.copy( face.color );
  5808. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5809. color = faceVertexColors[ j ];
  5810. faceCopy.vertexColors.push( color.clone() );
  5811. }
  5812. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5813. faces1.push( faceCopy );
  5814. }
  5815. // uvs
  5816. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5817. var uv = uvs2[ i ], uvCopy = [];
  5818. if ( uv === undefined ) {
  5819. continue;
  5820. }
  5821. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5822. uvCopy.push( uv[ j ].clone() );
  5823. }
  5824. uvs1.push( uvCopy );
  5825. }
  5826. },
  5827. mergeMesh: function ( mesh ) {
  5828. if ( mesh instanceof THREE.Mesh === false ) {
  5829. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5830. return;
  5831. }
  5832. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5833. this.merge( mesh.geometry, mesh.matrix );
  5834. },
  5835. /*
  5836. * Checks for duplicate vertices with hashmap.
  5837. * Duplicated vertices are removed
  5838. * and faces' vertices are updated.
  5839. */
  5840. mergeVertices: function () {
  5841. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5842. var unique = [], changes = [];
  5843. var v, key;
  5844. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5845. var precision = Math.pow( 10, precisionPoints );
  5846. var i, il, face;
  5847. var indices, j, jl;
  5848. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5849. v = this.vertices[ i ];
  5850. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5851. if ( verticesMap[ key ] === undefined ) {
  5852. verticesMap[ key ] = i;
  5853. unique.push( this.vertices[ i ] );
  5854. changes[ i ] = unique.length - 1;
  5855. } else {
  5856. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5857. changes[ i ] = changes[ verticesMap[ key ] ];
  5858. }
  5859. }
  5860. // if faces are completely degenerate after merging vertices, we
  5861. // have to remove them from the geometry.
  5862. var faceIndicesToRemove = [];
  5863. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5864. face = this.faces[ i ];
  5865. face.a = changes[ face.a ];
  5866. face.b = changes[ face.b ];
  5867. face.c = changes[ face.c ];
  5868. indices = [ face.a, face.b, face.c ];
  5869. var dupIndex = - 1;
  5870. // if any duplicate vertices are found in a Face3
  5871. // we have to remove the face as nothing can be saved
  5872. for ( var n = 0; n < 3; n ++ ) {
  5873. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5874. dupIndex = n;
  5875. faceIndicesToRemove.push( i );
  5876. break;
  5877. }
  5878. }
  5879. }
  5880. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5881. var idx = faceIndicesToRemove[ i ];
  5882. this.faces.splice( idx, 1 );
  5883. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5884. this.faceVertexUvs[ j ].splice( idx, 1 );
  5885. }
  5886. }
  5887. // Use unique set of vertices
  5888. var diff = this.vertices.length - unique.length;
  5889. this.vertices = unique;
  5890. return diff;
  5891. },
  5892. toJSON: function () {
  5893. var data = {
  5894. metadata: {
  5895. version: 4.4,
  5896. type: 'Geometry',
  5897. generator: 'Geometry.toJSON'
  5898. }
  5899. };
  5900. // standard Geometry serialization
  5901. data.uuid = this.uuid;
  5902. data.type = this.type;
  5903. if ( this.name !== '' ) data.name = this.name;
  5904. if ( this.parameters !== undefined ) {
  5905. var parameters = this.parameters;
  5906. for ( var key in parameters ) {
  5907. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5908. }
  5909. return data;
  5910. }
  5911. var vertices = [];
  5912. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5913. var vertex = this.vertices[ i ];
  5914. vertices.push( vertex.x, vertex.y, vertex.z );
  5915. }
  5916. var faces = [];
  5917. var normals = [];
  5918. var normalsHash = {};
  5919. var colors = [];
  5920. var colorsHash = {};
  5921. var uvs = [];
  5922. var uvsHash = {};
  5923. for ( var i = 0; i < this.faces.length; i ++ ) {
  5924. var face = this.faces[ i ];
  5925. var hasMaterial = false; // face.materialIndex !== undefined;
  5926. var hasFaceUv = false; // deprecated
  5927. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5928. var hasFaceNormal = face.normal.length() > 0;
  5929. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5930. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5931. var hasFaceVertexColor = face.vertexColors.length > 0;
  5932. var faceType = 0;
  5933. faceType = setBit( faceType, 0, 0 );
  5934. faceType = setBit( faceType, 1, hasMaterial );
  5935. faceType = setBit( faceType, 2, hasFaceUv );
  5936. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5937. faceType = setBit( faceType, 4, hasFaceNormal );
  5938. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5939. faceType = setBit( faceType, 6, hasFaceColor );
  5940. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5941. faces.push( faceType );
  5942. faces.push( face.a, face.b, face.c );
  5943. if ( hasFaceVertexUv ) {
  5944. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5945. faces.push(
  5946. getUvIndex( faceVertexUvs[ 0 ] ),
  5947. getUvIndex( faceVertexUvs[ 1 ] ),
  5948. getUvIndex( faceVertexUvs[ 2 ] )
  5949. );
  5950. }
  5951. if ( hasFaceNormal ) {
  5952. faces.push( getNormalIndex( face.normal ) );
  5953. }
  5954. if ( hasFaceVertexNormal ) {
  5955. var vertexNormals = face.vertexNormals;
  5956. faces.push(
  5957. getNormalIndex( vertexNormals[ 0 ] ),
  5958. getNormalIndex( vertexNormals[ 1 ] ),
  5959. getNormalIndex( vertexNormals[ 2 ] )
  5960. );
  5961. }
  5962. if ( hasFaceColor ) {
  5963. faces.push( getColorIndex( face.color ) );
  5964. }
  5965. if ( hasFaceVertexColor ) {
  5966. var vertexColors = face.vertexColors;
  5967. faces.push(
  5968. getColorIndex( vertexColors[ 0 ] ),
  5969. getColorIndex( vertexColors[ 1 ] ),
  5970. getColorIndex( vertexColors[ 2 ] )
  5971. );
  5972. }
  5973. }
  5974. function setBit( value, position, enabled ) {
  5975. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  5976. }
  5977. function getNormalIndex( normal ) {
  5978. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5979. if ( normalsHash[ hash ] !== undefined ) {
  5980. return normalsHash[ hash ];
  5981. }
  5982. normalsHash[ hash ] = normals.length / 3;
  5983. normals.push( normal.x, normal.y, normal.z );
  5984. return normalsHash[ hash ];
  5985. }
  5986. function getColorIndex( color ) {
  5987. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5988. if ( colorsHash[ hash ] !== undefined ) {
  5989. return colorsHash[ hash ];
  5990. }
  5991. colorsHash[ hash ] = colors.length;
  5992. colors.push( color.getHex() );
  5993. return colorsHash[ hash ];
  5994. }
  5995. function getUvIndex( uv ) {
  5996. var hash = uv.x.toString() + uv.y.toString();
  5997. if ( uvsHash[ hash ] !== undefined ) {
  5998. return uvsHash[ hash ];
  5999. }
  6000. uvsHash[ hash ] = uvs.length / 2;
  6001. uvs.push( uv.x, uv.y );
  6002. return uvsHash[ hash ];
  6003. }
  6004. data.data = {};
  6005. data.data.vertices = vertices;
  6006. data.data.normals = normals;
  6007. if ( colors.length > 0 ) data.data.colors = colors;
  6008. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6009. data.data.faces = faces;
  6010. return data;
  6011. },
  6012. clone: function () {
  6013. return new THREE.Geometry().copy( this );
  6014. },
  6015. copy: function ( source ) {
  6016. this.vertices = [];
  6017. this.faces = [];
  6018. this.faceVertexUvs = [ [] ];
  6019. var vertices = source.vertices;
  6020. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6021. this.vertices.push( vertices[ i ].clone() );
  6022. }
  6023. var faces = source.faces;
  6024. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6025. this.faces.push( faces[ i ].clone() );
  6026. }
  6027. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6028. var faceVertexUvs = source.faceVertexUvs[ i ];
  6029. if ( this.faceVertexUvs[ i ] === undefined ) {
  6030. this.faceVertexUvs[ i ] = [];
  6031. }
  6032. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6033. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6034. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6035. var uv = uvs[ k ];
  6036. uvsCopy.push( uv.clone() );
  6037. }
  6038. this.faceVertexUvs[ i ].push( uvsCopy );
  6039. }
  6040. }
  6041. return this;
  6042. },
  6043. dispose: function () {
  6044. this.dispatchEvent( { type: 'dispose' } );
  6045. },
  6046. // Backwards compatibility
  6047. set groupsNeedUpdate ( value ) {
  6048. if ( value === true ) this.dispose();
  6049. }
  6050. };
  6051. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6052. THREE.GeometryIdCount = 0;
  6053. // File:src/core/DirectGeometry.js
  6054. /**
  6055. * @author mrdoob / http://mrdoob.com/
  6056. */
  6057. THREE.DirectGeometry = function () {
  6058. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6059. this.uuid = THREE.Math.generateUUID();
  6060. this.name = '';
  6061. this.type = 'DirectGeometry';
  6062. this.indices = [];
  6063. this.vertices = [];
  6064. this.normals = [];
  6065. this.colors = [];
  6066. this.uvs = [];
  6067. this.uvs2 = [];
  6068. this.tangents = [];
  6069. this.morphTargets = {};
  6070. this.skinWeights = [];
  6071. this.skinIndices = [];
  6072. // this.lineDistances = [];
  6073. this.boundingBox = null;
  6074. this.boundingSphere = null;
  6075. // update flags
  6076. this.verticesNeedUpdate = false;
  6077. this.normalsNeedUpdate = false;
  6078. this.colorsNeedUpdate = false;
  6079. this.uvsNeedUpdate = false;
  6080. this.tangentsNeedUpdate = false;
  6081. };
  6082. THREE.DirectGeometry.prototype = {
  6083. constructor: THREE.DirectGeometry,
  6084. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6085. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6086. computeFaceNormals: function () {
  6087. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6088. return this;
  6089. },
  6090. computeVertexNormals: function () {
  6091. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6092. return this;
  6093. },
  6094. computeTangents: function () {
  6095. console.warn( 'THREE.DirectGeometry: computeTangents() is not a method of this type of geometry.' );
  6096. return this;
  6097. },
  6098. fromGeometry: function ( geometry ) {
  6099. var faces = geometry.faces;
  6100. var vertices = geometry.vertices;
  6101. var faceVertexUvs = geometry.faceVertexUvs;
  6102. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6103. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6104. var hasTangents = geometry.hasTangents;
  6105. // morphs
  6106. var morphTargets = geometry.morphTargets;
  6107. var morphTargetsLength = morphTargets.length;
  6108. if ( morphTargetsLength > 0 ) {
  6109. var morphTargetsPosition = [];
  6110. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6111. morphTargetsPosition[ i ] = [];
  6112. }
  6113. this.morphTargets.position = morphTargetsPosition;
  6114. }
  6115. var morphNormals = geometry.morphNormals;
  6116. var morphNormalsLength = morphNormals.length;
  6117. if ( morphNormalsLength > 0 ) {
  6118. var morphTargetsNormal = [];
  6119. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6120. morphTargetsNormal[ i ] = [];
  6121. }
  6122. this.morphTargets.normal = morphTargetsNormal;
  6123. }
  6124. // skins
  6125. var skinIndices = geometry.skinIndices;
  6126. var skinWeights = geometry.skinWeights;
  6127. var hasSkinIndices = skinIndices.length === vertices.length;
  6128. var hasSkinWeights = skinWeights.length === vertices.length;
  6129. //
  6130. for ( var i = 0; i < faces.length; i ++ ) {
  6131. var face = faces[ i ];
  6132. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6133. var vertexNormals = face.vertexNormals;
  6134. if ( vertexNormals.length === 3 ) {
  6135. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6136. } else {
  6137. var normal = face.normal;
  6138. this.normals.push( normal, normal, normal );
  6139. }
  6140. var vertexColors = face.vertexColors;
  6141. if ( vertexColors.length === 3 ) {
  6142. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6143. } else {
  6144. var color = face.color;
  6145. this.colors.push( color, color, color );
  6146. }
  6147. if ( hasFaceVertexUv === true ) {
  6148. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6149. if ( vertexUvs !== undefined ) {
  6150. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6151. } else {
  6152. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6153. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6154. }
  6155. }
  6156. if ( hasFaceVertexUv2 === true ) {
  6157. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6158. if ( vertexUvs !== undefined ) {
  6159. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6160. } else {
  6161. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6162. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6163. }
  6164. }
  6165. if ( hasTangents === true ) {
  6166. var vertexTangents = face.vertexTangents;
  6167. if ( vertexTangents.length === 3 ) {
  6168. this.tangents.push( vertexTangents[ 0 ], vertexTangents[ 1 ], vertexTangents[ 2 ] );
  6169. } else {
  6170. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined tangents ', i );
  6171. this.tangents.push( new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4() );
  6172. }
  6173. }
  6174. // morphs
  6175. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6176. var morphTarget = morphTargets[ j ].vertices;
  6177. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6178. }
  6179. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6180. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6181. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6182. }
  6183. // skins
  6184. if ( hasSkinIndices ) {
  6185. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6186. }
  6187. if ( hasSkinWeights ) {
  6188. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6189. }
  6190. }
  6191. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6192. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6193. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6194. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6195. this.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  6196. return this;
  6197. },
  6198. dispose: function () {
  6199. this.dispatchEvent( { type: 'dispose' } );
  6200. }
  6201. };
  6202. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6203. // File:src/core/BufferGeometry.js
  6204. /**
  6205. * @author alteredq / http://alteredqualia.com/
  6206. * @author mrdoob / http://mrdoob.com/
  6207. */
  6208. THREE.BufferGeometry = function () {
  6209. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6210. this.uuid = THREE.Math.generateUUID();
  6211. this.name = '';
  6212. this.type = 'BufferGeometry';
  6213. this.attributes = {};
  6214. this.morphAttributes = {};
  6215. this.drawcalls = [];
  6216. this.boundingBox = null;
  6217. this.boundingSphere = null;
  6218. };
  6219. THREE.BufferGeometry.prototype = {
  6220. constructor: THREE.BufferGeometry,
  6221. addAttribute: function ( name, attribute ) {
  6222. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6223. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6224. this.attributes[ name ] = { array: arguments[ 1 ], itemSize: arguments[ 2 ] };
  6225. return;
  6226. }
  6227. this.attributes[ name ] = attribute;
  6228. },
  6229. getAttribute: function ( name ) {
  6230. return this.attributes[ name ];
  6231. },
  6232. removeAttribute: function ( name ) {
  6233. delete this.attributes[ name ];
  6234. },
  6235. get offsets() {
  6236. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .drawcalls.' );
  6237. return this.drawcalls;
  6238. },
  6239. addDrawCall: function ( start, count, indexOffset ) {
  6240. this.drawcalls.push( {
  6241. start: start,
  6242. count: count,
  6243. index: indexOffset !== undefined ? indexOffset : 0
  6244. } );
  6245. },
  6246. clearDrawCalls: function () {
  6247. this.drawcalls = [];
  6248. },
  6249. applyMatrix: function ( matrix ) {
  6250. var position = this.attributes.position;
  6251. if ( position !== undefined ) {
  6252. matrix.applyToVector3Array( position.array );
  6253. position.needsUpdate = true;
  6254. }
  6255. var normal = this.attributes.normal;
  6256. if ( normal !== undefined ) {
  6257. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6258. normalMatrix.applyToVector3Array( normal.array );
  6259. normal.needsUpdate = true;
  6260. }
  6261. if ( this.boundingBox !== null ) {
  6262. this.computeBoundingBox();
  6263. }
  6264. if ( this.boundingSphere !== null ) {
  6265. this.computeBoundingSphere();
  6266. }
  6267. },
  6268. rotateX: function () {
  6269. // rotate geometry around world x-axis
  6270. var m1;
  6271. return function rotateX( angle ) {
  6272. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6273. m1.makeRotationX( angle );
  6274. this.applyMatrix( m1 );
  6275. return this;
  6276. };
  6277. }(),
  6278. rotateY: function () {
  6279. // rotate geometry around world y-axis
  6280. var m1;
  6281. return function rotateY( angle ) {
  6282. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6283. m1.makeRotationY( angle );
  6284. this.applyMatrix( m1 );
  6285. return this;
  6286. };
  6287. }(),
  6288. rotateZ: function () {
  6289. // rotate geometry around world z-axis
  6290. var m1;
  6291. return function rotateZ( angle ) {
  6292. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6293. m1.makeRotationZ( angle );
  6294. this.applyMatrix( m1 );
  6295. return this;
  6296. };
  6297. }(),
  6298. translate: function () {
  6299. // translate geometry
  6300. var m1;
  6301. return function translate( x, y, z ) {
  6302. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6303. m1.makeTranslation( x, y, z );
  6304. this.applyMatrix( m1 );
  6305. return this;
  6306. };
  6307. }(),
  6308. scale: function () {
  6309. // scale geometry
  6310. var m1;
  6311. return function scale( x, y, z ) {
  6312. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6313. m1.makeScale( x, y, z );
  6314. this.applyMatrix( m1 );
  6315. return this;
  6316. };
  6317. }(),
  6318. lookAt: function () {
  6319. var obj;
  6320. return function lookAt( vector ) {
  6321. if ( obj === undefined ) obj = new THREE.Object3D();
  6322. obj.lookAt( vector );
  6323. obj.updateMatrix();
  6324. this.applyMatrix( obj.matrix );
  6325. };
  6326. }(),
  6327. center: function () {
  6328. this.computeBoundingBox();
  6329. var offset = this.boundingBox.center().negate();
  6330. this.translate( offset.x, offset.y, offset.z );
  6331. return offset;
  6332. },
  6333. setFromObject: function ( object ) {
  6334. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6335. var geometry = object.geometry;
  6336. if ( object instanceof THREE.PointCloud || object instanceof THREE.Line ) {
  6337. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6338. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6339. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6340. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6341. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6342. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6343. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6344. }
  6345. if ( geometry.boundingSphere !== null ) {
  6346. this.boundingSphere = geometry.boundingSphere.clone();
  6347. }
  6348. if ( geometry.boundingBox !== null ) {
  6349. this.boundingBox = geometry.boundingBox.clone();
  6350. }
  6351. } else if ( object instanceof THREE.Mesh ) {
  6352. if ( geometry instanceof THREE.Geometry ) {
  6353. this.fromGeometry( geometry );
  6354. }
  6355. }
  6356. return this;
  6357. },
  6358. updateFromObject: function ( object ) {
  6359. var geometry = object.geometry;
  6360. if ( object instanceof THREE.Mesh ) {
  6361. var direct = geometry.__directGeometry;
  6362. if ( direct === undefined ) {
  6363. return this.fromGeometry( geometry );
  6364. }
  6365. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6366. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6367. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6368. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6369. direct.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  6370. geometry.verticesNeedUpdate = false;
  6371. geometry.normalsNeedUpdate = false;
  6372. geometry.colorsNeedUpdate = false;
  6373. geometry.uvsNeedUpdate = false;
  6374. geometry.tangentsNeedUpdate = false;
  6375. geometry = direct;
  6376. }
  6377. if ( geometry.verticesNeedUpdate === true ) {
  6378. var attribute = this.attributes.position;
  6379. if ( attribute !== undefined ) {
  6380. attribute.copyVector3sArray( geometry.vertices );
  6381. attribute.needsUpdate = true;
  6382. }
  6383. geometry.verticesNeedUpdate = false;
  6384. }
  6385. if ( geometry.normalsNeedUpdate === true ) {
  6386. var attribute = this.attributes.normal;
  6387. if ( attribute !== undefined ) {
  6388. attribute.copyVector3sArray( geometry.normals );
  6389. attribute.needsUpdate = true;
  6390. }
  6391. geometry.normalsNeedUpdate = false;
  6392. }
  6393. if ( geometry.colorsNeedUpdate === true ) {
  6394. var attribute = this.attributes.color;
  6395. if ( attribute !== undefined ) {
  6396. attribute.copyColorsArray( geometry.colors );
  6397. attribute.needsUpdate = true;
  6398. }
  6399. geometry.colorsNeedUpdate = false;
  6400. }
  6401. if ( geometry.tangentsNeedUpdate === true ) {
  6402. var attribute = this.attributes.tangent;
  6403. if ( attribute !== undefined ) {
  6404. attribute.copyVector4sArray( geometry.tangents );
  6405. attribute.needsUpdate = true;
  6406. }
  6407. geometry.tangentsNeedUpdate = false;
  6408. }
  6409. if ( geometry.lineDistancesNeedUpdate ) {
  6410. var attribute = this.attributes.lineDistance;
  6411. if ( attribute !== undefined ) {
  6412. attribute.copyArray( geometry.lineDistances );
  6413. attribute.needsUpdate = true;
  6414. }
  6415. geometry.lineDistancesNeedUpdate = false;
  6416. }
  6417. return this;
  6418. },
  6419. fromGeometry: function ( geometry ) {
  6420. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6421. return this.fromDirectGeometry( geometry.__directGeometry );
  6422. },
  6423. fromDirectGeometry: function ( geometry ) {
  6424. var positions = new Float32Array( geometry.vertices.length * 3 );
  6425. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6426. if ( geometry.normals.length > 0 ) {
  6427. var normals = new Float32Array( geometry.normals.length * 3 );
  6428. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6429. }
  6430. if ( geometry.colors.length > 0 ) {
  6431. var colors = new Float32Array( geometry.colors.length * 3 );
  6432. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6433. }
  6434. if ( geometry.uvs.length > 0 ) {
  6435. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6436. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6437. }
  6438. if ( geometry.uvs2.length > 0 ) {
  6439. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6440. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6441. }
  6442. if ( geometry.tangents.length > 0 ) {
  6443. var tangents = new Float32Array( geometry.tangents.length * 4 );
  6444. this.addAttribute( 'tangent', new THREE.BufferAttribute( tangents, 4 ).copyVector4sArray( geometry.tangents ) );
  6445. }
  6446. if ( geometry.indices.length > 0 ) {
  6447. var indices = new Uint16Array( geometry.indices.length * 3 );
  6448. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6449. }
  6450. // morphs
  6451. for ( var name in geometry.morphTargets ) {
  6452. var array = [];
  6453. var morphTargets = geometry.morphTargets[ name ];
  6454. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6455. var morphTarget = morphTargets[ i ];
  6456. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6457. array.push( attribute.copyVector3sArray( morphTarget ) );
  6458. }
  6459. this.morphAttributes[ name ] = array;
  6460. }
  6461. // skinning
  6462. if ( geometry.skinIndices.length > 0 ) {
  6463. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6464. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6465. }
  6466. if ( geometry.skinWeights.length > 0 ) {
  6467. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6468. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6469. }
  6470. //
  6471. if ( geometry.boundingSphere !== null ) {
  6472. this.boundingSphere = geometry.boundingSphere.clone();
  6473. }
  6474. if ( geometry.boundingBox !== null ) {
  6475. this.boundingBox = geometry.boundingBox.clone();
  6476. }
  6477. return this;
  6478. },
  6479. computeBoundingBox: function () {
  6480. var vector = new THREE.Vector3();
  6481. return function () {
  6482. if ( this.boundingBox === null ) {
  6483. this.boundingBox = new THREE.Box3();
  6484. }
  6485. var positions = this.attributes.position.array;
  6486. if ( positions ) {
  6487. var bb = this.boundingBox;
  6488. bb.makeEmpty();
  6489. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6490. vector.fromArray( positions, i );
  6491. bb.expandByPoint( vector );
  6492. }
  6493. }
  6494. if ( positions === undefined || positions.length === 0 ) {
  6495. this.boundingBox.min.set( 0, 0, 0 );
  6496. this.boundingBox.max.set( 0, 0, 0 );
  6497. }
  6498. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6499. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6500. }
  6501. };
  6502. }(),
  6503. computeBoundingSphere: function () {
  6504. var box = new THREE.Box3();
  6505. var vector = new THREE.Vector3();
  6506. return function () {
  6507. if ( this.boundingSphere === null ) {
  6508. this.boundingSphere = new THREE.Sphere();
  6509. }
  6510. var positions = this.attributes.position.array;
  6511. if ( positions ) {
  6512. box.makeEmpty();
  6513. var center = this.boundingSphere.center;
  6514. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6515. vector.fromArray( positions, i );
  6516. box.expandByPoint( vector );
  6517. }
  6518. box.center( center );
  6519. // hoping to find a boundingSphere with a radius smaller than the
  6520. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6521. var maxRadiusSq = 0;
  6522. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6523. vector.fromArray( positions, i );
  6524. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6525. }
  6526. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6527. if ( isNaN( this.boundingSphere.radius ) ) {
  6528. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6529. }
  6530. }
  6531. };
  6532. }(),
  6533. computeFaceNormals: function () {
  6534. // backwards compatibility
  6535. },
  6536. computeVertexNormals: function () {
  6537. var attributes = this.attributes;
  6538. if ( attributes.position ) {
  6539. var positions = attributes.position.array;
  6540. if ( attributes.normal === undefined ) {
  6541. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6542. } else {
  6543. // reset existing normals to zero
  6544. var normals = attributes.normal.array;
  6545. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6546. normals[ i ] = 0;
  6547. }
  6548. }
  6549. var normals = attributes.normal.array;
  6550. var vA, vB, vC,
  6551. pA = new THREE.Vector3(),
  6552. pB = new THREE.Vector3(),
  6553. pC = new THREE.Vector3(),
  6554. cb = new THREE.Vector3(),
  6555. ab = new THREE.Vector3();
  6556. // indexed elements
  6557. if ( attributes.index ) {
  6558. var indices = attributes.index.array;
  6559. if ( this.drawcalls.length === 0 ) {
  6560. this.addDrawCall( 0, indices.length );
  6561. }
  6562. for ( var j = 0, jl = this.drawcalls.length; j < jl; ++ j ) {
  6563. var start = this.drawcalls[ j ].start;
  6564. var count = this.drawcalls[ j ].count;
  6565. var index = this.drawcalls[ j ].index;
  6566. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6567. vA = ( index + indices[ i ] ) * 3;
  6568. vB = ( index + indices[ i + 1 ] ) * 3;
  6569. vC = ( index + indices[ i + 2 ] ) * 3;
  6570. pA.fromArray( positions, vA );
  6571. pB.fromArray( positions, vB );
  6572. pC.fromArray( positions, vC );
  6573. cb.subVectors( pC, pB );
  6574. ab.subVectors( pA, pB );
  6575. cb.cross( ab );
  6576. normals[ vA ] += cb.x;
  6577. normals[ vA + 1 ] += cb.y;
  6578. normals[ vA + 2 ] += cb.z;
  6579. normals[ vB ] += cb.x;
  6580. normals[ vB + 1 ] += cb.y;
  6581. normals[ vB + 2 ] += cb.z;
  6582. normals[ vC ] += cb.x;
  6583. normals[ vC + 1 ] += cb.y;
  6584. normals[ vC + 2 ] += cb.z;
  6585. }
  6586. }
  6587. } else {
  6588. // non-indexed elements (unconnected triangle soup)
  6589. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6590. pA.fromArray( positions, i );
  6591. pB.fromArray( positions, i + 3 );
  6592. pC.fromArray( positions, i + 6 );
  6593. cb.subVectors( pC, pB );
  6594. ab.subVectors( pA, pB );
  6595. cb.cross( ab );
  6596. normals[ i ] = cb.x;
  6597. normals[ i + 1 ] = cb.y;
  6598. normals[ i + 2 ] = cb.z;
  6599. normals[ i + 3 ] = cb.x;
  6600. normals[ i + 4 ] = cb.y;
  6601. normals[ i + 5 ] = cb.z;
  6602. normals[ i + 6 ] = cb.x;
  6603. normals[ i + 7 ] = cb.y;
  6604. normals[ i + 8 ] = cb.z;
  6605. }
  6606. }
  6607. this.normalizeNormals();
  6608. attributes.normal.needsUpdate = true;
  6609. }
  6610. },
  6611. computeTangents: function () {
  6612. // based on http://www.terathon.com/code/tangent.html
  6613. // (per vertex tangents)
  6614. if ( this.attributes.index === undefined ||
  6615. this.attributes.position === undefined ||
  6616. this.attributes.normal === undefined ||
  6617. this.attributes.uv === undefined ) {
  6618. console.warn( 'THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()' );
  6619. return;
  6620. }
  6621. var indices = this.attributes.index.array;
  6622. var positions = this.attributes.position.array;
  6623. var normals = this.attributes.normal.array;
  6624. var uvs = this.attributes.uv.array;
  6625. var nVertices = positions.length / 3;
  6626. if ( this.attributes.tangent === undefined ) {
  6627. this.addAttribute( 'tangent', new THREE.BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
  6628. }
  6629. var tangents = this.attributes.tangent.array;
  6630. var tan1 = [], tan2 = [];
  6631. for ( var k = 0; k < nVertices; k ++ ) {
  6632. tan1[ k ] = new THREE.Vector3();
  6633. tan2[ k ] = new THREE.Vector3();
  6634. }
  6635. var vA = new THREE.Vector3(),
  6636. vB = new THREE.Vector3(),
  6637. vC = new THREE.Vector3(),
  6638. uvA = new THREE.Vector2(),
  6639. uvB = new THREE.Vector2(),
  6640. uvC = new THREE.Vector2(),
  6641. x1, x2, y1, y2, z1, z2,
  6642. s1, s2, t1, t2, r;
  6643. var sdir = new THREE.Vector3(), tdir = new THREE.Vector3();
  6644. function handleTriangle( a, b, c ) {
  6645. vA.fromArray( positions, a * 3 );
  6646. vB.fromArray( positions, b * 3 );
  6647. vC.fromArray( positions, c * 3 );
  6648. uvA.fromArray( uvs, a * 2 );
  6649. uvB.fromArray( uvs, b * 2 );
  6650. uvC.fromArray( uvs, c * 2 );
  6651. x1 = vB.x - vA.x;
  6652. x2 = vC.x - vA.x;
  6653. y1 = vB.y - vA.y;
  6654. y2 = vC.y - vA.y;
  6655. z1 = vB.z - vA.z;
  6656. z2 = vC.z - vA.z;
  6657. s1 = uvB.x - uvA.x;
  6658. s2 = uvC.x - uvA.x;
  6659. t1 = uvB.y - uvA.y;
  6660. t2 = uvC.y - uvA.y;
  6661. r = 1.0 / ( s1 * t2 - s2 * t1 );
  6662. sdir.set(
  6663. ( t2 * x1 - t1 * x2 ) * r,
  6664. ( t2 * y1 - t1 * y2 ) * r,
  6665. ( t2 * z1 - t1 * z2 ) * r
  6666. );
  6667. tdir.set(
  6668. ( s1 * x2 - s2 * x1 ) * r,
  6669. ( s1 * y2 - s2 * y1 ) * r,
  6670. ( s1 * z2 - s2 * z1 ) * r
  6671. );
  6672. tan1[ a ].add( sdir );
  6673. tan1[ b ].add( sdir );
  6674. tan1[ c ].add( sdir );
  6675. tan2[ a ].add( tdir );
  6676. tan2[ b ].add( tdir );
  6677. tan2[ c ].add( tdir );
  6678. }
  6679. var i, il;
  6680. var j, jl;
  6681. var iA, iB, iC;
  6682. if ( this.drawcalls.length === 0 ) {
  6683. this.addDrawCall( 0, indices.length );
  6684. }
  6685. var drawcalls = this.drawcalls;
  6686. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6687. var start = drawcalls[ j ].start;
  6688. var count = drawcalls[ j ].count;
  6689. var index = drawcalls[ j ].index;
  6690. for ( i = start, il = start + count; i < il; i += 3 ) {
  6691. iA = index + indices[ i ];
  6692. iB = index + indices[ i + 1 ];
  6693. iC = index + indices[ i + 2 ];
  6694. handleTriangle( iA, iB, iC );
  6695. }
  6696. }
  6697. var tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3();
  6698. var n = new THREE.Vector3(), n2 = new THREE.Vector3();
  6699. var w, t, test;
  6700. function handleVertex( v ) {
  6701. n.fromArray( normals, v * 3 );
  6702. n2.copy( n );
  6703. t = tan1[ v ];
  6704. // Gram-Schmidt orthogonalize
  6705. tmp.copy( t );
  6706. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6707. // Calculate handedness
  6708. tmp2.crossVectors( n2, t );
  6709. test = tmp2.dot( tan2[ v ] );
  6710. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6711. tangents[ v * 4 ] = tmp.x;
  6712. tangents[ v * 4 + 1 ] = tmp.y;
  6713. tangents[ v * 4 + 2 ] = tmp.z;
  6714. tangents[ v * 4 + 3 ] = w;
  6715. }
  6716. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6717. var start = drawcalls[ j ].start;
  6718. var count = drawcalls[ j ].count;
  6719. var index = drawcalls[ j ].index;
  6720. for ( i = start, il = start + count; i < il; i += 3 ) {
  6721. iA = index + indices[ i ];
  6722. iB = index + indices[ i + 1 ];
  6723. iC = index + indices[ i + 2 ];
  6724. handleVertex( iA );
  6725. handleVertex( iB );
  6726. handleVertex( iC );
  6727. }
  6728. }
  6729. },
  6730. /*
  6731. Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices.
  6732. This method will effectively rewrite the index buffer and remap all attributes to match the new indices.
  6733. WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets.
  6734. size - Defaults to 65535 or 4294967296 if extension OES_element_index_uint supported, but allows for larger or smaller chunks.
  6735. */
  6736. computeOffsets: function ( size ) {
  6737. if ( size === undefined ) size = THREE.BufferGeometry.MaxIndex;
  6738. var indices = this.attributes.index.array;
  6739. var vertices = this.attributes.position.array;
  6740. var facesCount = ( indices.length / 3 );
  6741. var UintArray = ( ( vertices.length / 3 ) > 65535 && THREE.BufferGeometry.MaxIndex > 65535 ) ? Uint32Array : Uint16Array;
  6742. /*
  6743. console.log("Computing buffers in offsets of "+size+" -> indices:"+indices.length+" vertices:"+vertices.length);
  6744. console.log("Faces to process: "+(indices.length/3));
  6745. console.log("Reordering "+verticesCount+" vertices.");
  6746. */
  6747. var sortedIndices = new UintArray( indices.length );
  6748. var indexPtr = 0;
  6749. var vertexPtr = 0;
  6750. var tmpOffsets = [ { start: 0, count: 0, index: 0 } ];
  6751. var offset = tmpOffsets[ 0 ];
  6752. var duplicatedVertices = 0;
  6753. var newVerticeMaps = 0;
  6754. var faceVertices = new Int32Array( 6 );
  6755. var vertexMap = new Int32Array( vertices.length );
  6756. var revVertexMap = new Int32Array( vertices.length );
  6757. for ( var j = 0; j < vertices.length; j ++ ) {
  6758. vertexMap[ j ] = - 1; revVertexMap[ j ] = - 1;
  6759. }
  6760. /*
  6761. Traverse every face and reorder vertices in the proper offsets of 65k.
  6762. We can have more than 'size' entries in the index buffer per offset, but only reference 'size' values.
  6763. */
  6764. for ( var findex = 0; findex < facesCount; findex ++ ) {
  6765. newVerticeMaps = 0;
  6766. for ( var vo = 0; vo < 3; vo ++ ) {
  6767. var vid = indices[ findex * 3 + vo ];
  6768. if ( vertexMap[ vid ] === - 1 ) {
  6769. //Unmapped vertex
  6770. faceVertices[ vo * 2 ] = vid;
  6771. faceVertices[ vo * 2 + 1 ] = - 1;
  6772. newVerticeMaps ++;
  6773. } else if ( vertexMap[ vid ] < offset.index ) {
  6774. //Reused vertices from previous block (duplicate)
  6775. faceVertices[ vo * 2 ] = vid;
  6776. faceVertices[ vo * 2 + 1 ] = - 1;
  6777. duplicatedVertices ++;
  6778. } else {
  6779. //Reused vertex in the current block
  6780. faceVertices[ vo * 2 ] = vid;
  6781. faceVertices[ vo * 2 + 1 ] = vertexMap[ vid ];
  6782. }
  6783. }
  6784. var faceMax = vertexPtr + newVerticeMaps;
  6785. if ( faceMax > ( offset.index + size ) ) {
  6786. var new_offset = { start: indexPtr, count: 0, index: vertexPtr };
  6787. tmpOffsets.push( new_offset );
  6788. offset = new_offset;
  6789. //Re-evaluate reused vertices in light of new offset.
  6790. for ( var v = 0; v < 6; v += 2 ) {
  6791. var new_vid = faceVertices[ v + 1 ];
  6792. if ( new_vid > - 1 && new_vid < offset.index )
  6793. faceVertices[ v + 1 ] = - 1;
  6794. }
  6795. }
  6796. //Reindex the face.
  6797. for ( var v = 0; v < 6; v += 2 ) {
  6798. var vid = faceVertices[ v ];
  6799. var new_vid = faceVertices[ v + 1 ];
  6800. if ( new_vid === - 1 )
  6801. new_vid = vertexPtr ++;
  6802. vertexMap[ vid ] = new_vid;
  6803. revVertexMap[ new_vid ] = vid;
  6804. sortedIndices[ indexPtr ++ ] = new_vid - offset.index; //XXX overflows at 16bit
  6805. offset.count ++;
  6806. }
  6807. }
  6808. /* Move all attribute values to map to the new computed indices , also expand the vertex stack to match our new vertexPtr. */
  6809. this.reorderBuffers( sortedIndices, revVertexMap, vertexPtr );
  6810. this.clearDrawCalls();
  6811. for ( var i = 0; i < tmpOffsets.length; i ++ ) {
  6812. var tmpOffset = tmpOffsets[ i ];
  6813. this.addDrawCall( tmpOffset.start, tmpOffset.count, tmpOffset.index );
  6814. }
  6815. /*
  6816. var orderTime = Date.now();
  6817. console.log("Reorder time: "+(orderTime-s)+"ms");
  6818. console.log("Duplicated "+duplicatedVertices+" vertices.");
  6819. console.log("Compute Buffers time: "+(Date.now()-s)+"ms");
  6820. console.log("Draw tmpOffsets: "+tmpOffsets.length);
  6821. */
  6822. },
  6823. merge: function ( geometry, offset ) {
  6824. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6825. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6826. return;
  6827. }
  6828. if ( offset === undefined ) offset = 0;
  6829. var attributes = this.attributes;
  6830. for ( var key in attributes ) {
  6831. if ( geometry.attributes[ key ] === undefined ) continue;
  6832. var attribute1 = attributes[ key ];
  6833. var attributeArray1 = attribute1.array;
  6834. var attribute2 = geometry.attributes[ key ];
  6835. var attributeArray2 = attribute2.array;
  6836. var attributeSize = attribute2.itemSize;
  6837. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6838. attributeArray1[ j ] = attributeArray2[ i ];
  6839. }
  6840. }
  6841. return this;
  6842. },
  6843. normalizeNormals: function () {
  6844. var normals = this.attributes.normal.array;
  6845. var x, y, z, n;
  6846. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6847. x = normals[ i ];
  6848. y = normals[ i + 1 ];
  6849. z = normals[ i + 2 ];
  6850. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6851. normals[ i ] *= n;
  6852. normals[ i + 1 ] *= n;
  6853. normals[ i + 2 ] *= n;
  6854. }
  6855. },
  6856. /*
  6857. reoderBuffers:
  6858. Reorder attributes based on a new indexBuffer and indexMap.
  6859. indexBuffer - Uint16Array of the new ordered indices.
  6860. indexMap - Int32Array where the position is the new vertex ID and the value the old vertex ID for each vertex.
  6861. vertexCount - Amount of total vertices considered in this reordering (in case you want to grow the vertex stack).
  6862. */
  6863. reorderBuffers: function ( indexBuffer, indexMap, vertexCount ) {
  6864. /* Create a copy of all attributes for reordering. */
  6865. var sortedAttributes = {};
  6866. for ( var attr in this.attributes ) {
  6867. if ( attr === 'index' )
  6868. continue;
  6869. var sourceArray = this.attributes[ attr ].array;
  6870. sortedAttributes[ attr ] = new sourceArray.constructor( this.attributes[ attr ].itemSize * vertexCount );
  6871. }
  6872. /* Move attribute positions based on the new index map */
  6873. for ( var new_vid = 0; new_vid < vertexCount; new_vid ++ ) {
  6874. var vid = indexMap[ new_vid ];
  6875. for ( var attr in this.attributes ) {
  6876. if ( attr === 'index' )
  6877. continue;
  6878. var attrArray = this.attributes[ attr ].array;
  6879. var attrSize = this.attributes[ attr ].itemSize;
  6880. var sortedAttr = sortedAttributes[ attr ];
  6881. for ( var k = 0; k < attrSize; k ++ )
  6882. sortedAttr[ new_vid * attrSize + k ] = attrArray[ vid * attrSize + k ];
  6883. }
  6884. }
  6885. /* Carry the new sorted buffers locally */
  6886. this.attributes[ 'index' ].array = indexBuffer;
  6887. for ( var attr in this.attributes ) {
  6888. if ( attr === 'index' )
  6889. continue;
  6890. this.attributes[ attr ].array = sortedAttributes[ attr ];
  6891. this.attributes[ attr ].numItems = this.attributes[ attr ].itemSize * vertexCount;
  6892. }
  6893. },
  6894. toJSON: function () {
  6895. var data = {
  6896. metadata: {
  6897. version: 4.4,
  6898. type: 'BufferGeometry',
  6899. generator: 'BufferGeometry.toJSON'
  6900. }
  6901. };
  6902. // standard BufferGeometry serialization
  6903. data.uuid = this.uuid;
  6904. data.type = this.type;
  6905. if ( this.name !== '' ) data.name = this.name;
  6906. if ( this.parameters !== undefined ) {
  6907. var parameters = this.parameters;
  6908. for ( var key in parameters ) {
  6909. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6910. }
  6911. return data;
  6912. }
  6913. data.data = { attributes: {} };
  6914. var attributes = this.attributes;
  6915. var drawcalls = this.drawcalls;
  6916. var boundingSphere = this.boundingSphere;
  6917. for ( var key in attributes ) {
  6918. var attribute = attributes[ key ];
  6919. var array = Array.prototype.slice.call( attribute.array );
  6920. data.data.attributes[ key ] = {
  6921. itemSize: attribute.itemSize,
  6922. type: attribute.array.constructor.name,
  6923. array: array
  6924. };
  6925. }
  6926. if ( drawcalls.length > 0 ) {
  6927. data.data.drawcalls = JSON.parse( JSON.stringify( drawcalls ) );
  6928. }
  6929. if ( boundingSphere !== null ) {
  6930. data.data.boundingSphere = {
  6931. center: boundingSphere.center.toArray(),
  6932. radius: boundingSphere.radius
  6933. };
  6934. }
  6935. return data;
  6936. },
  6937. clone: function () {
  6938. return new THREE.BufferGeometry().copy( this );
  6939. },
  6940. copy: function ( source ) {
  6941. for ( var attr in source.attributes ) {
  6942. var sourceAttr = source.attributes[ attr ];
  6943. this.addAttribute( attr, sourceAttr.clone() );
  6944. }
  6945. for ( var i = 0, il = source.drawcalls.length; i < il; i ++ ) {
  6946. var offset = source.drawcalls[ i ];
  6947. this.addDrawCall( offset.start, offset.count, offset.index );
  6948. }
  6949. return this;
  6950. },
  6951. dispose: function () {
  6952. this.dispatchEvent( { type: 'dispose' } );
  6953. }
  6954. };
  6955. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6956. THREE.BufferGeometry.MaxIndex = 65535;
  6957. // File:src/core/InstancedBufferGeometry.js
  6958. /**
  6959. * @author benaadams / https://twitter.com/ben_a_adams
  6960. */
  6961. THREE.InstancedBufferGeometry = function () {
  6962. THREE.BufferGeometry.call( this );
  6963. this.type = 'InstancedBufferGeometry';
  6964. this.maxInstancedCount = undefined;
  6965. };
  6966. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6967. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6968. THREE.InstancedBufferGeometry.prototype.addDrawCall = function ( start, count, indexOffset, instances ) {
  6969. this.drawcalls.push( {
  6970. start: start,
  6971. count: count,
  6972. index: indexOffset !== undefined ? indexOffset : 0,
  6973. instances: instances
  6974. } );
  6975. },
  6976. THREE.InstancedBufferGeometry.prototype.clone = function () {
  6977. var geometry = new THREE.InstancedBufferGeometry();
  6978. for ( var attr in this.attributes ) {
  6979. var sourceAttr = this.attributes[ attr ];
  6980. geometry.addAttribute( attr, sourceAttr.clone() );
  6981. }
  6982. for ( var i = 0, il = this.drawcalls.length; i < il; i ++ ) {
  6983. var offset = this.drawcalls[ i ];
  6984. geometry.addDrawCall( offset.start, offset.count, offset.index, offset.instances );
  6985. }
  6986. return geometry;
  6987. };
  6988. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6989. // File:src/cameras/Camera.js
  6990. /**
  6991. * @author mrdoob / http://mrdoob.com/
  6992. * @author mikael emtinger / http://gomo.se/
  6993. * @author WestLangley / http://github.com/WestLangley
  6994. */
  6995. THREE.Camera = function () {
  6996. THREE.Object3D.call( this );
  6997. this.type = 'Camera';
  6998. this.matrixWorldInverse = new THREE.Matrix4();
  6999. this.projectionMatrix = new THREE.Matrix4();
  7000. };
  7001. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  7002. THREE.Camera.prototype.constructor = THREE.Camera;
  7003. THREE.Camera.prototype.getWorldDirection = function () {
  7004. var quaternion = new THREE.Quaternion();
  7005. return function ( optionalTarget ) {
  7006. var result = optionalTarget || new THREE.Vector3();
  7007. this.getWorldQuaternion( quaternion );
  7008. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  7009. };
  7010. }();
  7011. THREE.Camera.prototype.lookAt = function () {
  7012. // This routine does not support cameras with rotated and/or translated parent(s)
  7013. var m1 = new THREE.Matrix4();
  7014. return function ( vector ) {
  7015. m1.lookAt( this.position, vector, this.up );
  7016. this.quaternion.setFromRotationMatrix( m1 );
  7017. };
  7018. }();
  7019. THREE.Camera.prototype.clone = function () {
  7020. var camera = new THREE.Camera();
  7021. return camera.copy( this );
  7022. };
  7023. THREE.Camera.prototype.copy = function ( source ) {
  7024. THREE.Object3D.prototype.copy.call( this, source );
  7025. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7026. this.projectionMatrix.copy( source.projectionMatrix );
  7027. return this;
  7028. };
  7029. // File:src/cameras/CubeCamera.js
  7030. /**
  7031. * Camera for rendering cube maps
  7032. * - renders scene into axis-aligned cube
  7033. *
  7034. * @author alteredq / http://alteredqualia.com/
  7035. */
  7036. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  7037. THREE.Object3D.call( this );
  7038. this.type = 'CubeCamera';
  7039. var fov = 90, aspect = 1;
  7040. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7041. cameraPX.up.set( 0, - 1, 0 );
  7042. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  7043. this.add( cameraPX );
  7044. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7045. cameraNX.up.set( 0, - 1, 0 );
  7046. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  7047. this.add( cameraNX );
  7048. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7049. cameraPY.up.set( 0, 0, 1 );
  7050. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  7051. this.add( cameraPY );
  7052. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7053. cameraNY.up.set( 0, 0, - 1 );
  7054. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  7055. this.add( cameraNY );
  7056. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7057. cameraPZ.up.set( 0, - 1, 0 );
  7058. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  7059. this.add( cameraPZ );
  7060. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7061. cameraNZ.up.set( 0, - 1, 0 );
  7062. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  7063. this.add( cameraNZ );
  7064. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  7065. this.updateCubeMap = function ( renderer, scene ) {
  7066. if ( this.parent === null ) this.updateMatrixWorld();
  7067. var renderTarget = this.renderTarget;
  7068. var generateMipmaps = renderTarget.generateMipmaps;
  7069. renderTarget.generateMipmaps = false;
  7070. renderTarget.activeCubeFace = 0;
  7071. renderer.render( scene, cameraPX, renderTarget );
  7072. renderTarget.activeCubeFace = 1;
  7073. renderer.render( scene, cameraNX, renderTarget );
  7074. renderTarget.activeCubeFace = 2;
  7075. renderer.render( scene, cameraPY, renderTarget );
  7076. renderTarget.activeCubeFace = 3;
  7077. renderer.render( scene, cameraNY, renderTarget );
  7078. renderTarget.activeCubeFace = 4;
  7079. renderer.render( scene, cameraPZ, renderTarget );
  7080. renderTarget.generateMipmaps = generateMipmaps;
  7081. renderTarget.activeCubeFace = 5;
  7082. renderer.render( scene, cameraNZ, renderTarget );
  7083. renderer.setRenderTarget( null );
  7084. };
  7085. };
  7086. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  7087. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  7088. // File:src/cameras/OrthographicCamera.js
  7089. /**
  7090. * @author alteredq / http://alteredqualia.com/
  7091. */
  7092. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  7093. THREE.Camera.call( this );
  7094. this.type = 'OrthographicCamera';
  7095. this.zoom = 1;
  7096. this.left = left;
  7097. this.right = right;
  7098. this.top = top;
  7099. this.bottom = bottom;
  7100. this.near = ( near !== undefined ) ? near : 0.1;
  7101. this.far = ( far !== undefined ) ? far : 2000;
  7102. this.updateProjectionMatrix();
  7103. };
  7104. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  7105. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  7106. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  7107. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  7108. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  7109. var cx = ( this.right + this.left ) / 2;
  7110. var cy = ( this.top + this.bottom ) / 2;
  7111. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  7112. };
  7113. THREE.OrthographicCamera.prototype.clone = function () {
  7114. var camera = new THREE.OrthographicCamera();
  7115. camera.copy( this );
  7116. camera.zoom = this.zoom;
  7117. camera.left = this.left;
  7118. camera.right = this.right;
  7119. camera.top = this.top;
  7120. camera.bottom = this.bottom;
  7121. camera.near = this.near;
  7122. camera.far = this.far;
  7123. return camera;
  7124. };
  7125. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  7126. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7127. data.object.zoom = this.zoom;
  7128. data.object.left = this.left;
  7129. data.object.right = this.right;
  7130. data.object.top = this.top;
  7131. data.object.bottom = this.bottom;
  7132. data.object.near = this.near;
  7133. data.object.far = this.far;
  7134. return data;
  7135. };
  7136. // File:src/cameras/PerspectiveCamera.js
  7137. /**
  7138. * @author mrdoob / http://mrdoob.com/
  7139. * @author greggman / http://games.greggman.com/
  7140. * @author zz85 / http://www.lab4games.net/zz85/blog
  7141. */
  7142. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  7143. THREE.Camera.call( this );
  7144. this.type = 'PerspectiveCamera';
  7145. this.zoom = 1;
  7146. this.fov = fov !== undefined ? fov : 50;
  7147. this.aspect = aspect !== undefined ? aspect : 1;
  7148. this.near = near !== undefined ? near : 0.1;
  7149. this.far = far !== undefined ? far : 2000;
  7150. this.updateProjectionMatrix();
  7151. };
  7152. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  7153. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  7154. /**
  7155. * Uses Focal Length (in mm) to estimate and set FOV
  7156. * 35mm (full-frame) camera is used if frame size is not specified;
  7157. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  7158. */
  7159. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  7160. if ( frameHeight === undefined ) frameHeight = 24;
  7161. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  7162. this.updateProjectionMatrix();
  7163. };
  7164. /**
  7165. * Sets an offset in a larger frustum. This is useful for multi-window or
  7166. * multi-monitor/multi-machine setups.
  7167. *
  7168. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7169. * the monitors are in grid like this
  7170. *
  7171. * +---+---+---+
  7172. * | A | B | C |
  7173. * +---+---+---+
  7174. * | D | E | F |
  7175. * +---+---+---+
  7176. *
  7177. * then for each monitor you would call it like this
  7178. *
  7179. * var w = 1920;
  7180. * var h = 1080;
  7181. * var fullWidth = w * 3;
  7182. * var fullHeight = h * 2;
  7183. *
  7184. * --A--
  7185. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7186. * --B--
  7187. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7188. * --C--
  7189. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7190. * --D--
  7191. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7192. * --E--
  7193. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7194. * --F--
  7195. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7196. *
  7197. * Note there is no reason monitors have to be the same size or in a grid.
  7198. */
  7199. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  7200. this.fullWidth = fullWidth;
  7201. this.fullHeight = fullHeight;
  7202. this.x = x;
  7203. this.y = y;
  7204. this.width = width;
  7205. this.height = height;
  7206. this.updateProjectionMatrix();
  7207. };
  7208. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  7209. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  7210. if ( this.fullWidth ) {
  7211. var aspect = this.fullWidth / this.fullHeight;
  7212. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  7213. var bottom = - top;
  7214. var left = aspect * bottom;
  7215. var right = aspect * top;
  7216. var width = Math.abs( right - left );
  7217. var height = Math.abs( top - bottom );
  7218. this.projectionMatrix.makeFrustum(
  7219. left + this.x * width / this.fullWidth,
  7220. left + ( this.x + this.width ) * width / this.fullWidth,
  7221. top - ( this.y + this.height ) * height / this.fullHeight,
  7222. top - this.y * height / this.fullHeight,
  7223. this.near,
  7224. this.far
  7225. );
  7226. } else {
  7227. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  7228. }
  7229. };
  7230. THREE.PerspectiveCamera.prototype.clone = function () {
  7231. var camera = new THREE.PerspectiveCamera();
  7232. camera.copy( this );
  7233. camera.zoom = this.zoom;
  7234. camera.fov = this.fov;
  7235. camera.aspect = this.aspect;
  7236. camera.near = this.near;
  7237. camera.far = this.far;
  7238. return camera;
  7239. };
  7240. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  7241. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7242. data.object.zoom = this.zoom;
  7243. data.object.fov = this.fov;
  7244. data.object.aspect = this.aspect;
  7245. data.object.near = this.near;
  7246. data.object.far = this.far;
  7247. return data;
  7248. };
  7249. // File:src/lights/Light.js
  7250. /**
  7251. * @author mrdoob / http://mrdoob.com/
  7252. * @author alteredq / http://alteredqualia.com/
  7253. */
  7254. THREE.Light = function ( color ) {
  7255. THREE.Object3D.call( this );
  7256. this.type = 'Light';
  7257. this.color = new THREE.Color( color );
  7258. };
  7259. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  7260. THREE.Light.prototype.constructor = THREE.Light;
  7261. THREE.Light.prototype.clone = function () {
  7262. var light = new THREE.Light();
  7263. return light.copy( this );
  7264. };
  7265. THREE.Light.prototype.copy = function ( source ) {
  7266. THREE.Object3D.prototype.copy.call( this, source );
  7267. this.color.copy( source.color );
  7268. return this;
  7269. };
  7270. // File:src/lights/AmbientLight.js
  7271. /**
  7272. * @author mrdoob / http://mrdoob.com/
  7273. */
  7274. THREE.AmbientLight = function ( color ) {
  7275. THREE.Light.call( this, color );
  7276. this.type = 'AmbientLight';
  7277. };
  7278. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  7279. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  7280. THREE.AmbientLight.prototype.clone = function () {
  7281. var light = new THREE.AmbientLight();
  7282. light.copy( this );
  7283. return light;
  7284. };
  7285. THREE.AmbientLight.prototype.toJSON = function ( meta ) {
  7286. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7287. data.object.color = this.color.getHex();
  7288. return data;
  7289. };
  7290. // File:src/lights/AreaLight.js
  7291. /**
  7292. * @author MPanknin / http://www.redplant.de/
  7293. * @author alteredq / http://alteredqualia.com/
  7294. * @author prafullit
  7295. */
  7296. THREE.AreaLight = function ( color, intensity ) {
  7297. THREE.Light.call( this, color );
  7298. this.type = 'AreaLight';
  7299. this.normal = new THREE.Vector3( 0, - 1, 0 );
  7300. this.right = new THREE.Vector3( 1, 0, 0 );
  7301. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7302. this.width = 1.0;
  7303. this.height = 1.0;
  7304. this.constantAttenuation = 1.5;
  7305. this.linearAttenuation = 0.5;
  7306. this.quadraticAttenuation = 0.1;
  7307. };
  7308. THREE.AreaLight.prototype = Object.create( THREE.Light.prototype );
  7309. THREE.AreaLight.prototype.constructor = THREE.AreaLight;
  7310. THREE.AreaLight.prototype.clone = function () {
  7311. var light = new THREE.AreaLight();
  7312. light.copy( this );
  7313. light.normal.copy( this.normal );
  7314. light.right.copy( this.right );
  7315. light.intensity = this.intensity;
  7316. light.width = this.width;
  7317. light.height = this.height;
  7318. light.constantAttenuation = this.constantAttenuation;
  7319. light.linearAttenuation = this.linearAttenuation;
  7320. light.quadraticAttenuation = this.quadraticAttenuation;
  7321. return light;
  7322. };
  7323. THREE.AreaLight.prototype.toJSON = function ( meta ) {
  7324. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7325. data.object.color = this.color.getHex();
  7326. data.object.intensity = this.intensity;
  7327. return data;
  7328. };
  7329. // File:src/lights/DirectionalLight.js
  7330. /**
  7331. * @author mrdoob / http://mrdoob.com/
  7332. * @author alteredq / http://alteredqualia.com/
  7333. */
  7334. THREE.DirectionalLight = function ( color, intensity ) {
  7335. THREE.Light.call( this, color );
  7336. this.type = 'DirectionalLight';
  7337. this.position.set( 0, 1, 0 );
  7338. this.updateMatrix();
  7339. this.target = new THREE.Object3D();
  7340. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7341. this.castShadow = false;
  7342. this.onlyShadow = false;
  7343. //
  7344. this.shadowCameraNear = 50;
  7345. this.shadowCameraFar = 5000;
  7346. this.shadowCameraLeft = - 500;
  7347. this.shadowCameraRight = 500;
  7348. this.shadowCameraTop = 500;
  7349. this.shadowCameraBottom = - 500;
  7350. this.shadowCameraVisible = false;
  7351. this.shadowBias = 0;
  7352. this.shadowDarkness = 0.5;
  7353. this.shadowMapWidth = 512;
  7354. this.shadowMapHeight = 512;
  7355. //
  7356. this.shadowMap = null;
  7357. this.shadowMapSize = null;
  7358. this.shadowCamera = null;
  7359. this.shadowMatrix = null;
  7360. };
  7361. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  7362. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  7363. THREE.DirectionalLight.prototype.clone = function () {
  7364. var light = new THREE.DirectionalLight();
  7365. light.copy( this );
  7366. light.target = this.target.clone();
  7367. light.intensity = this.intensity;
  7368. light.castShadow = this.castShadow;
  7369. light.onlyShadow = this.onlyShadow;
  7370. //
  7371. light.shadowCameraNear = this.shadowCameraNear;
  7372. light.shadowCameraFar = this.shadowCameraFar;
  7373. light.shadowCameraLeft = this.shadowCameraLeft;
  7374. light.shadowCameraRight = this.shadowCameraRight;
  7375. light.shadowCameraTop = this.shadowCameraTop;
  7376. light.shadowCameraBottom = this.shadowCameraBottom;
  7377. light.shadowCameraVisible = this.shadowCameraVisible;
  7378. light.shadowBias = this.shadowBias;
  7379. light.shadowDarkness = this.shadowDarkness;
  7380. light.shadowMapWidth = this.shadowMapWidth;
  7381. light.shadowMapHeight = this.shadowMapHeight;
  7382. return light;
  7383. };
  7384. THREE.DirectionalLight.prototype.toJSON = function ( meta ) {
  7385. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7386. data.object.color = this.color.getHex();
  7387. data.object.intensity = this.intensity;
  7388. return data;
  7389. };
  7390. // File:src/lights/HemisphereLight.js
  7391. /**
  7392. * @author alteredq / http://alteredqualia.com/
  7393. */
  7394. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  7395. THREE.Light.call( this, skyColor );
  7396. this.type = 'HemisphereLight';
  7397. this.position.set( 0, 100, 0 );
  7398. this.updateMatrix();
  7399. this.groundColor = new THREE.Color( groundColor );
  7400. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7401. };
  7402. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  7403. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  7404. THREE.HemisphereLight.prototype.clone = function () {
  7405. var light = new THREE.HemisphereLight();
  7406. light.copy( this );
  7407. light.groundColor.copy( this.groundColor );
  7408. light.intensity = this.intensity;
  7409. return light;
  7410. };
  7411. THREE.HemisphereLight.prototype.toJSON = function ( meta ) {
  7412. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7413. data.object.color = this.color.getHex();
  7414. data.object.groundColor = this.groundColor.getHex();
  7415. data.object.intensity = this.intensity;
  7416. return data;
  7417. };
  7418. // File:src/lights/PointLight.js
  7419. /**
  7420. * @author mrdoob / http://mrdoob.com/
  7421. */
  7422. THREE.PointLight = function ( color, intensity, distance, decay ) {
  7423. THREE.Light.call( this, color );
  7424. this.type = 'PointLight';
  7425. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7426. this.distance = ( distance !== undefined ) ? distance : 0;
  7427. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7428. };
  7429. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  7430. THREE.PointLight.prototype.constructor = THREE.PointLight;
  7431. THREE.PointLight.prototype.clone = function () {
  7432. var light = new THREE.PointLight();
  7433. light.copy( this );
  7434. light.intensity = this.intensity;
  7435. light.distance = this.distance;
  7436. light.decay = this.decay;
  7437. return light;
  7438. };
  7439. THREE.PointLight.prototype.toJSON = function ( meta ) {
  7440. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7441. data.object.color = this.color.getHex();
  7442. data.object.intensity = this.intensity;
  7443. data.object.distance = this.distance;
  7444. data.object.decay = this.decay;
  7445. return data;
  7446. };
  7447. // File:src/lights/SpotLight.js
  7448. /**
  7449. * @author alteredq / http://alteredqualia.com/
  7450. */
  7451. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  7452. THREE.Light.call( this, color );
  7453. this.type = 'SpotLight';
  7454. this.position.set( 0, 1, 0 );
  7455. this.updateMatrix();
  7456. this.target = new THREE.Object3D();
  7457. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7458. this.distance = ( distance !== undefined ) ? distance : 0;
  7459. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  7460. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  7461. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7462. this.castShadow = false;
  7463. this.onlyShadow = false;
  7464. //
  7465. this.shadowCameraNear = 50;
  7466. this.shadowCameraFar = 5000;
  7467. this.shadowCameraFov = 50;
  7468. this.shadowCameraVisible = false;
  7469. this.shadowBias = 0;
  7470. this.shadowDarkness = 0.5;
  7471. this.shadowMapWidth = 512;
  7472. this.shadowMapHeight = 512;
  7473. //
  7474. this.shadowMap = null;
  7475. this.shadowMapSize = null;
  7476. this.shadowCamera = null;
  7477. this.shadowMatrix = null;
  7478. };
  7479. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  7480. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  7481. THREE.SpotLight.prototype.clone = function () {
  7482. var light = new THREE.SpotLight();
  7483. light.copy( this );
  7484. light.target = this.target.clone();
  7485. light.intensity = this.intensity;
  7486. light.distance = this.distance;
  7487. light.angle = this.angle;
  7488. light.exponent = this.exponent;
  7489. light.decay = this.decay;
  7490. light.castShadow = this.castShadow;
  7491. light.onlyShadow = this.onlyShadow;
  7492. //
  7493. light.shadowCameraNear = this.shadowCameraNear;
  7494. light.shadowCameraFar = this.shadowCameraFar;
  7495. light.shadowCameraFov = this.shadowCameraFov;
  7496. light.shadowCameraVisible = this.shadowCameraVisible;
  7497. light.shadowBias = this.shadowBias;
  7498. light.shadowDarkness = this.shadowDarkness;
  7499. light.shadowMapWidth = this.shadowMapWidth;
  7500. light.shadowMapHeight = this.shadowMapHeight;
  7501. return light;
  7502. };
  7503. THREE.SpotLight.prototype.toJSON = function ( meta ) {
  7504. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7505. data.object.color = this.color.getHex();
  7506. data.object.intensity = this.intensity;
  7507. data.object.distance = this.distance;
  7508. data.object.angle = this.angle;
  7509. data.object.exponent = this.exponent;
  7510. data.object.decay = this.decay;
  7511. return data;
  7512. };
  7513. // File:src/loaders/Cache.js
  7514. /**
  7515. * @author mrdoob / http://mrdoob.com/
  7516. */
  7517. THREE.Cache = {
  7518. enabled: false,
  7519. files: {},
  7520. add: function ( key, file ) {
  7521. if ( this.enabled === false ) return;
  7522. // console.log( 'THREE.Cache', 'Adding key:', key );
  7523. this.files[ key ] = file;
  7524. },
  7525. get: function ( key ) {
  7526. if ( this.enabled === false ) return;
  7527. // console.log( 'THREE.Cache', 'Checking key:', key );
  7528. return this.files[ key ];
  7529. },
  7530. remove: function ( key ) {
  7531. delete this.files[ key ];
  7532. },
  7533. clear: function () {
  7534. this.files = {};
  7535. }
  7536. };
  7537. // File:src/loaders/Loader.js
  7538. /**
  7539. * @author alteredq / http://alteredqualia.com/
  7540. */
  7541. THREE.Loader = function () {
  7542. this.onLoadStart = function () {};
  7543. this.onLoadProgress = function () {};
  7544. this.onLoadComplete = function () {};
  7545. };
  7546. THREE.Loader.prototype = {
  7547. constructor: THREE.Loader,
  7548. crossOrigin: undefined,
  7549. extractUrlBase: function ( url ) {
  7550. var parts = url.split( '/' );
  7551. if ( parts.length === 1 ) return './';
  7552. parts.pop();
  7553. return parts.join( '/' ) + '/';
  7554. },
  7555. initMaterials: function ( materials, texturePath, crossOrigin ) {
  7556. var array = [];
  7557. for ( var i = 0; i < materials.length; ++ i ) {
  7558. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  7559. }
  7560. return array;
  7561. },
  7562. needsTangents: function ( materials ) {
  7563. for ( var i = 0, il = materials.length; i < il; i ++ ) {
  7564. var m = materials[ i ];
  7565. if ( m instanceof THREE.ShaderMaterial ) return true;
  7566. }
  7567. return false;
  7568. },
  7569. createMaterial: ( function () {
  7570. var imageLoader;
  7571. return function createMaterial( m, texturePath, crossOrigin ) {
  7572. var scope = this;
  7573. if ( crossOrigin === undefined && scope.crossOrigin !== undefined ) crossOrigin = scope.crossOrigin;
  7574. if ( imageLoader === undefined ) imageLoader = new THREE.ImageLoader();
  7575. function nearest_pow2( n ) {
  7576. var l = Math.log( n ) / Math.LN2;
  7577. return Math.pow( 2, Math.round( l ) );
  7578. }
  7579. function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
  7580. var fullPath = texturePath + sourceFile;
  7581. var texture;
  7582. var loader = THREE.Loader.Handlers.get( fullPath );
  7583. if ( loader !== null ) {
  7584. texture = loader.load( fullPath );
  7585. } else {
  7586. texture = new THREE.Texture();
  7587. loader = imageLoader;
  7588. loader.setCrossOrigin( crossOrigin );
  7589. loader.load( fullPath, function ( image ) {
  7590. if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
  7591. THREE.Math.isPowerOfTwo( image.height ) === false ) {
  7592. var width = nearest_pow2( image.width );
  7593. var height = nearest_pow2( image.height );
  7594. var canvas = document.createElement( 'canvas' );
  7595. canvas.width = width;
  7596. canvas.height = height;
  7597. var context = canvas.getContext( '2d' );
  7598. context.drawImage( image, 0, 0, width, height );
  7599. texture.image = canvas;
  7600. } else {
  7601. texture.image = image;
  7602. }
  7603. texture.needsUpdate = true;
  7604. } );
  7605. }
  7606. texture.sourceFile = sourceFile;
  7607. if ( repeat ) {
  7608. texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
  7609. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  7610. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  7611. }
  7612. if ( offset ) {
  7613. texture.offset.set( offset[ 0 ], offset[ 1 ] );
  7614. }
  7615. if ( wrap ) {
  7616. var wrapMap = {
  7617. 'repeat': THREE.RepeatWrapping,
  7618. 'mirror': THREE.MirroredRepeatWrapping
  7619. };
  7620. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
  7621. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
  7622. }
  7623. if ( anisotropy ) {
  7624. texture.anisotropy = anisotropy;
  7625. }
  7626. where[ name ] = texture;
  7627. }
  7628. function rgb2hex( rgb ) {
  7629. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  7630. }
  7631. // defaults
  7632. var mtype = 'MeshLambertMaterial';
  7633. var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
  7634. // parameters from model file
  7635. if ( m.shading ) {
  7636. var shading = m.shading.toLowerCase();
  7637. if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
  7638. else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
  7639. }
  7640. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  7641. mpars.blending = THREE[ m.blending ];
  7642. }
  7643. if ( m.transparent !== undefined ) {
  7644. mpars.transparent = m.transparent;
  7645. }
  7646. if ( m.opacity !== undefined && m.opacity < 1.0 ) {
  7647. mpars.transparent = true;
  7648. }
  7649. if ( m.depthTest !== undefined ) {
  7650. mpars.depthTest = m.depthTest;
  7651. }
  7652. if ( m.depthWrite !== undefined ) {
  7653. mpars.depthWrite = m.depthWrite;
  7654. }
  7655. if ( m.visible !== undefined ) {
  7656. mpars.visible = m.visible;
  7657. }
  7658. if ( m.flipSided !== undefined ) {
  7659. mpars.side = THREE.BackSide;
  7660. }
  7661. if ( m.doubleSided !== undefined ) {
  7662. mpars.side = THREE.DoubleSide;
  7663. }
  7664. if ( m.wireframe !== undefined ) {
  7665. mpars.wireframe = m.wireframe;
  7666. }
  7667. if ( m.vertexColors !== undefined ) {
  7668. if ( m.vertexColors === 'face' ) {
  7669. mpars.vertexColors = THREE.FaceColors;
  7670. } else if ( m.vertexColors ) {
  7671. mpars.vertexColors = THREE.VertexColors;
  7672. }
  7673. }
  7674. // colors
  7675. if ( m.colorDiffuse ) {
  7676. mpars.color = rgb2hex( m.colorDiffuse );
  7677. } else if ( m.DbgColor ) {
  7678. mpars.color = m.DbgColor;
  7679. }
  7680. if ( m.colorSpecular ) {
  7681. mpars.specular = rgb2hex( m.colorSpecular );
  7682. }
  7683. if ( m.colorEmissive ) {
  7684. mpars.emissive = rgb2hex( m.colorEmissive );
  7685. }
  7686. // modifiers
  7687. if ( m.transparency !== undefined ) {
  7688. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  7689. m.opacity = m.transparency;
  7690. }
  7691. if ( m.opacity !== undefined ) {
  7692. mpars.opacity = m.opacity;
  7693. }
  7694. if ( m.specularCoef ) {
  7695. mpars.shininess = m.specularCoef;
  7696. }
  7697. // textures
  7698. if ( m.mapDiffuse && texturePath ) {
  7699. create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  7700. }
  7701. if ( m.mapLight && texturePath ) {
  7702. create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  7703. }
  7704. if ( m.mapAO && texturePath ) {
  7705. create_texture( mpars, 'aoMap', m.mapAO, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  7706. }
  7707. if ( m.mapBump && texturePath ) {
  7708. create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  7709. }
  7710. if ( m.mapNormal && texturePath ) {
  7711. create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  7712. }
  7713. if ( m.mapSpecular && texturePath ) {
  7714. create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  7715. }
  7716. if ( m.mapAlpha && texturePath ) {
  7717. create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  7718. }
  7719. //
  7720. if ( m.mapBumpScale ) {
  7721. mpars.bumpScale = m.mapBumpScale;
  7722. }
  7723. if ( m.mapNormalFactor ) {
  7724. mpars.normalScale = new THREE.Vector2( m.mapNormalFactor, m.mapNormalFactor );
  7725. }
  7726. var material = new THREE[ mtype ]( mpars );
  7727. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  7728. return material;
  7729. };
  7730. } )()
  7731. };
  7732. THREE.Loader.Handlers = {
  7733. handlers: [],
  7734. add: function ( regex, loader ) {
  7735. this.handlers.push( regex, loader );
  7736. },
  7737. get: function ( file ) {
  7738. for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
  7739. var regex = this.handlers[ i ];
  7740. var loader = this.handlers[ i + 1 ];
  7741. if ( regex.test( file ) ) {
  7742. return loader;
  7743. }
  7744. }
  7745. return null;
  7746. }
  7747. };
  7748. // File:src/loaders/XHRLoader.js
  7749. /**
  7750. * @author mrdoob / http://mrdoob.com/
  7751. */
  7752. THREE.XHRLoader = function ( manager ) {
  7753. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7754. };
  7755. THREE.XHRLoader.prototype = {
  7756. constructor: THREE.XHRLoader,
  7757. load: function ( url, onLoad, onProgress, onError ) {
  7758. var scope = this;
  7759. var cached = THREE.Cache.get( url );
  7760. if ( cached !== undefined ) {
  7761. if ( onLoad ) {
  7762. setTimeout( function () {
  7763. onLoad( cached );
  7764. }, 0 );
  7765. }
  7766. return cached;
  7767. }
  7768. var request = new XMLHttpRequest();
  7769. request.open( 'GET', url, true );
  7770. request.addEventListener( 'load', function ( event ) {
  7771. THREE.Cache.add( url, this.response );
  7772. if ( onLoad ) onLoad( this.response );
  7773. scope.manager.itemEnd( url );
  7774. }, false );
  7775. if ( onProgress !== undefined ) {
  7776. request.addEventListener( 'progress', function ( event ) {
  7777. onProgress( event );
  7778. }, false );
  7779. }
  7780. if ( onError !== undefined ) {
  7781. request.addEventListener( 'error', function ( event ) {
  7782. onError( event );
  7783. }, false );
  7784. }
  7785. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  7786. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  7787. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  7788. request.send( null );
  7789. scope.manager.itemStart( url );
  7790. return request;
  7791. },
  7792. setResponseType: function ( value ) {
  7793. this.responseType = value;
  7794. },
  7795. setCrossOrigin: function ( value ) {
  7796. this.crossOrigin = value;
  7797. },
  7798. setWithCredentials: function ( value ) {
  7799. this.withCredentials = value;
  7800. }
  7801. };
  7802. // File:src/loaders/ImageLoader.js
  7803. /**
  7804. * @author mrdoob / http://mrdoob.com/
  7805. */
  7806. THREE.ImageLoader = function ( manager ) {
  7807. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7808. };
  7809. THREE.ImageLoader.prototype = {
  7810. constructor: THREE.ImageLoader,
  7811. load: function ( url, onLoad, onProgress, onError ) {
  7812. var scope = this;
  7813. var cached = THREE.Cache.get( url );
  7814. if ( cached !== undefined ) {
  7815. if ( onLoad ) {
  7816. setTimeout( function () {
  7817. onLoad( cached );
  7818. }, 0 );
  7819. }
  7820. return cached;
  7821. }
  7822. var image = document.createElement( 'img' );
  7823. image.addEventListener( 'load', function ( event ) {
  7824. THREE.Cache.add( url, this );
  7825. if ( onLoad ) onLoad( this );
  7826. scope.manager.itemEnd( url );
  7827. }, false );
  7828. if ( onProgress !== undefined ) {
  7829. image.addEventListener( 'progress', function ( event ) {
  7830. onProgress( event );
  7831. }, false );
  7832. }
  7833. if ( onError !== undefined ) {
  7834. image.addEventListener( 'error', function ( event ) {
  7835. onError( event );
  7836. }, false );
  7837. }
  7838. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  7839. scope.manager.itemStart( url );
  7840. image.src = url;
  7841. return image;
  7842. },
  7843. setCrossOrigin: function ( value ) {
  7844. this.crossOrigin = value;
  7845. }
  7846. };
  7847. // File:src/loaders/JSONLoader.js
  7848. /**
  7849. * @author mrdoob / http://mrdoob.com/
  7850. * @author alteredq / http://alteredqualia.com/
  7851. */
  7852. THREE.JSONLoader = function ( manager ) {
  7853. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7854. this.withCredentials = false;
  7855. };
  7856. THREE.JSONLoader.prototype = {
  7857. constructor: THREE.JSONLoader,
  7858. load: function( url, onLoad, onProgress, onError ) {
  7859. var scope = this;
  7860. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  7861. var loader = new THREE.XHRLoader( this.manager );
  7862. loader.setCrossOrigin( this.crossOrigin );
  7863. loader.setWithCredentials( this.withCredentials );
  7864. loader.load( url, function ( text ) {
  7865. var json = JSON.parse( text );
  7866. var metadata = json.metadata;
  7867. if ( metadata !== undefined ) {
  7868. if ( metadata.type === 'object' ) {
  7869. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  7870. return;
  7871. }
  7872. if ( metadata.type === 'scene' ) {
  7873. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  7874. return;
  7875. }
  7876. }
  7877. var object = scope.parse( json, texturePath );
  7878. onLoad( object.geometry, object.materials );
  7879. } );
  7880. },
  7881. setCrossOrigin: function ( value ) {
  7882. this.crossOrigin = value;
  7883. },
  7884. setTexturePath: function ( value ) {
  7885. this.texturePath = value;
  7886. },
  7887. parse: function ( json, texturePath ) {
  7888. var geometry = new THREE.Geometry(),
  7889. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  7890. parseModel( scale );
  7891. parseSkin();
  7892. parseMorphing( scale );
  7893. geometry.computeFaceNormals();
  7894. geometry.computeBoundingSphere();
  7895. function parseModel( scale ) {
  7896. function isBitSet( value, position ) {
  7897. return value & ( 1 << position );
  7898. }
  7899. var i, j, fi,
  7900. offset, zLength,
  7901. colorIndex, normalIndex, uvIndex, materialIndex,
  7902. type,
  7903. isQuad,
  7904. hasMaterial,
  7905. hasFaceVertexUv,
  7906. hasFaceNormal, hasFaceVertexNormal,
  7907. hasFaceColor, hasFaceVertexColor,
  7908. vertex, face, faceA, faceB, hex, normal,
  7909. uvLayer, uv, u, v,
  7910. faces = json.faces,
  7911. vertices = json.vertices,
  7912. normals = json.normals,
  7913. colors = json.colors,
  7914. nUvLayers = 0;
  7915. if ( json.uvs !== undefined ) {
  7916. // disregard empty arrays
  7917. for ( i = 0; i < json.uvs.length; i ++ ) {
  7918. if ( json.uvs[ i ].length ) nUvLayers ++;
  7919. }
  7920. for ( i = 0; i < nUvLayers; i ++ ) {
  7921. geometry.faceVertexUvs[ i ] = [];
  7922. }
  7923. }
  7924. offset = 0;
  7925. zLength = vertices.length;
  7926. while ( offset < zLength ) {
  7927. vertex = new THREE.Vector3();
  7928. vertex.x = vertices[ offset ++ ] * scale;
  7929. vertex.y = vertices[ offset ++ ] * scale;
  7930. vertex.z = vertices[ offset ++ ] * scale;
  7931. geometry.vertices.push( vertex );
  7932. }
  7933. offset = 0;
  7934. zLength = faces.length;
  7935. while ( offset < zLength ) {
  7936. type = faces[ offset ++ ];
  7937. isQuad = isBitSet( type, 0 );
  7938. hasMaterial = isBitSet( type, 1 );
  7939. hasFaceVertexUv = isBitSet( type, 3 );
  7940. hasFaceNormal = isBitSet( type, 4 );
  7941. hasFaceVertexNormal = isBitSet( type, 5 );
  7942. hasFaceColor = isBitSet( type, 6 );
  7943. hasFaceVertexColor = isBitSet( type, 7 );
  7944. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  7945. if ( isQuad ) {
  7946. faceA = new THREE.Face3();
  7947. faceA.a = faces[ offset ];
  7948. faceA.b = faces[ offset + 1 ];
  7949. faceA.c = faces[ offset + 3 ];
  7950. faceB = new THREE.Face3();
  7951. faceB.a = faces[ offset + 1 ];
  7952. faceB.b = faces[ offset + 2 ];
  7953. faceB.c = faces[ offset + 3 ];
  7954. offset += 4;
  7955. if ( hasMaterial ) {
  7956. materialIndex = faces[ offset ++ ];
  7957. faceA.materialIndex = materialIndex;
  7958. faceB.materialIndex = materialIndex;
  7959. }
  7960. // to get face <=> uv index correspondence
  7961. fi = geometry.faces.length;
  7962. if ( hasFaceVertexUv ) {
  7963. for ( i = 0; i < nUvLayers; i ++ ) {
  7964. uvLayer = json.uvs[ i ];
  7965. geometry.faceVertexUvs[ i ][ fi ] = [];
  7966. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  7967. for ( j = 0; j < 4; j ++ ) {
  7968. uvIndex = faces[ offset ++ ];
  7969. u = uvLayer[ uvIndex * 2 ];
  7970. v = uvLayer[ uvIndex * 2 + 1 ];
  7971. uv = new THREE.Vector2( u, v );
  7972. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7973. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  7974. }
  7975. }
  7976. }
  7977. if ( hasFaceNormal ) {
  7978. normalIndex = faces[ offset ++ ] * 3;
  7979. faceA.normal.set(
  7980. normals[ normalIndex ++ ],
  7981. normals[ normalIndex ++ ],
  7982. normals[ normalIndex ]
  7983. );
  7984. faceB.normal.copy( faceA.normal );
  7985. }
  7986. if ( hasFaceVertexNormal ) {
  7987. for ( i = 0; i < 4; i ++ ) {
  7988. normalIndex = faces[ offset ++ ] * 3;
  7989. normal = new THREE.Vector3(
  7990. normals[ normalIndex ++ ],
  7991. normals[ normalIndex ++ ],
  7992. normals[ normalIndex ]
  7993. );
  7994. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  7995. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  7996. }
  7997. }
  7998. if ( hasFaceColor ) {
  7999. colorIndex = faces[ offset ++ ];
  8000. hex = colors[ colorIndex ];
  8001. faceA.color.setHex( hex );
  8002. faceB.color.setHex( hex );
  8003. }
  8004. if ( hasFaceVertexColor ) {
  8005. for ( i = 0; i < 4; i ++ ) {
  8006. colorIndex = faces[ offset ++ ];
  8007. hex = colors[ colorIndex ];
  8008. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  8009. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  8010. }
  8011. }
  8012. geometry.faces.push( faceA );
  8013. geometry.faces.push( faceB );
  8014. } else {
  8015. face = new THREE.Face3();
  8016. face.a = faces[ offset ++ ];
  8017. face.b = faces[ offset ++ ];
  8018. face.c = faces[ offset ++ ];
  8019. if ( hasMaterial ) {
  8020. materialIndex = faces[ offset ++ ];
  8021. face.materialIndex = materialIndex;
  8022. }
  8023. // to get face <=> uv index correspondence
  8024. fi = geometry.faces.length;
  8025. if ( hasFaceVertexUv ) {
  8026. for ( i = 0; i < nUvLayers; i ++ ) {
  8027. uvLayer = json.uvs[ i ];
  8028. geometry.faceVertexUvs[ i ][ fi ] = [];
  8029. for ( j = 0; j < 3; j ++ ) {
  8030. uvIndex = faces[ offset ++ ];
  8031. u = uvLayer[ uvIndex * 2 ];
  8032. v = uvLayer[ uvIndex * 2 + 1 ];
  8033. uv = new THREE.Vector2( u, v );
  8034. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  8035. }
  8036. }
  8037. }
  8038. if ( hasFaceNormal ) {
  8039. normalIndex = faces[ offset ++ ] * 3;
  8040. face.normal.set(
  8041. normals[ normalIndex ++ ],
  8042. normals[ normalIndex ++ ],
  8043. normals[ normalIndex ]
  8044. );
  8045. }
  8046. if ( hasFaceVertexNormal ) {
  8047. for ( i = 0; i < 3; i ++ ) {
  8048. normalIndex = faces[ offset ++ ] * 3;
  8049. normal = new THREE.Vector3(
  8050. normals[ normalIndex ++ ],
  8051. normals[ normalIndex ++ ],
  8052. normals[ normalIndex ]
  8053. );
  8054. face.vertexNormals.push( normal );
  8055. }
  8056. }
  8057. if ( hasFaceColor ) {
  8058. colorIndex = faces[ offset ++ ];
  8059. face.color.setHex( colors[ colorIndex ] );
  8060. }
  8061. if ( hasFaceVertexColor ) {
  8062. for ( i = 0; i < 3; i ++ ) {
  8063. colorIndex = faces[ offset ++ ];
  8064. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  8065. }
  8066. }
  8067. geometry.faces.push( face );
  8068. }
  8069. }
  8070. };
  8071. function parseSkin() {
  8072. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  8073. if ( json.skinWeights ) {
  8074. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  8075. var x = json.skinWeights[ i ];
  8076. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  8077. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  8078. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  8079. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  8080. }
  8081. }
  8082. if ( json.skinIndices ) {
  8083. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  8084. var a = json.skinIndices[ i ];
  8085. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  8086. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  8087. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  8088. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  8089. }
  8090. }
  8091. geometry.bones = json.bones;
  8092. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  8093. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  8094. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  8095. }
  8096. // could change this to json.animations[0] or remove completely
  8097. geometry.animation = json.animation;
  8098. geometry.animations = json.animations;
  8099. };
  8100. function parseMorphing( scale ) {
  8101. if ( json.morphTargets !== undefined ) {
  8102. var i, l, v, vl, dstVertices, srcVertices;
  8103. for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  8104. geometry.morphTargets[ i ] = {};
  8105. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  8106. geometry.morphTargets[ i ].vertices = [];
  8107. dstVertices = geometry.morphTargets[ i ].vertices;
  8108. srcVertices = json.morphTargets[ i ].vertices;
  8109. for ( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  8110. var vertex = new THREE.Vector3();
  8111. vertex.x = srcVertices[ v ] * scale;
  8112. vertex.y = srcVertices[ v + 1 ] * scale;
  8113. vertex.z = srcVertices[ v + 2 ] * scale;
  8114. dstVertices.push( vertex );
  8115. }
  8116. }
  8117. }
  8118. if ( json.morphColors !== undefined ) {
  8119. var i, l, c, cl, dstColors, srcColors, color;
  8120. for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
  8121. geometry.morphColors[ i ] = {};
  8122. geometry.morphColors[ i ].name = json.morphColors[ i ].name;
  8123. geometry.morphColors[ i ].colors = [];
  8124. dstColors = geometry.morphColors[ i ].colors;
  8125. srcColors = json.morphColors[ i ].colors;
  8126. for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
  8127. color = new THREE.Color( 0xffaa00 );
  8128. color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
  8129. dstColors.push( color );
  8130. }
  8131. }
  8132. }
  8133. };
  8134. if ( json.materials === undefined || json.materials.length === 0 ) {
  8135. return { geometry: geometry };
  8136. } else {
  8137. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  8138. if ( THREE.Loader.prototype.needsTangents( materials ) ) {
  8139. geometry.computeTangents();
  8140. }
  8141. return { geometry: geometry, materials: materials };
  8142. }
  8143. }
  8144. };
  8145. // File:src/loaders/LoadingManager.js
  8146. /**
  8147. * @author mrdoob / http://mrdoob.com/
  8148. */
  8149. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  8150. var scope = this;
  8151. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  8152. this.onLoad = onLoad;
  8153. this.onProgress = onProgress;
  8154. this.onError = onError;
  8155. this.itemStart = function ( url ) {
  8156. itemsTotal ++;
  8157. if ( isLoading === false ) {
  8158. if ( scope.onStart !== undefined ) {
  8159. scope.onStart( url, itemsLoaded, itemsTotal );
  8160. }
  8161. }
  8162. isLoading = true;
  8163. };
  8164. this.itemEnd = function ( url ) {
  8165. itemsLoaded ++;
  8166. if ( scope.onProgress !== undefined ) {
  8167. scope.onProgress( url, itemsLoaded, itemsTotal );
  8168. }
  8169. if ( itemsLoaded === itemsTotal ) {
  8170. isLoading = false;
  8171. if ( scope.onLoad !== undefined ) {
  8172. scope.onLoad();
  8173. }
  8174. }
  8175. };
  8176. };
  8177. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  8178. // File:src/loaders/BufferGeometryLoader.js
  8179. /**
  8180. * @author mrdoob / http://mrdoob.com/
  8181. */
  8182. THREE.BufferGeometryLoader = function ( manager ) {
  8183. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8184. };
  8185. THREE.BufferGeometryLoader.prototype = {
  8186. constructor: THREE.BufferGeometryLoader,
  8187. load: function ( url, onLoad, onProgress, onError ) {
  8188. var scope = this;
  8189. var loader = new THREE.XHRLoader( scope.manager );
  8190. loader.setCrossOrigin( this.crossOrigin );
  8191. loader.load( url, function ( text ) {
  8192. onLoad( scope.parse( JSON.parse( text ) ) );
  8193. }, onProgress, onError );
  8194. },
  8195. setCrossOrigin: function ( value ) {
  8196. this.crossOrigin = value;
  8197. },
  8198. parse: function ( json ) {
  8199. var geometry = new THREE.BufferGeometry();
  8200. var attributes = json.data.attributes;
  8201. for ( var key in attributes ) {
  8202. var attribute = attributes[ key ];
  8203. var typedArray = new self[ attribute.type ]( attribute.array );
  8204. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  8205. }
  8206. var drawcalls = json.data.drawcalls || json.data.offsets;
  8207. if ( drawcalls !== undefined ) {
  8208. for ( var i = 0, n = drawcalls.length; i !== n; ++ i ) {
  8209. var drawcall = drawcalls[ i ];
  8210. var indexStart = drawcall.start;
  8211. var indexCount = drawcall.count;
  8212. var indexOffset = drawcall.index;
  8213. geometry.addDrawcall( indexStart, indexCount, indexOffset );
  8214. }
  8215. }
  8216. var boundingSphere = json.data.boundingSphere;
  8217. if ( boundingSphere !== undefined ) {
  8218. var center = new THREE.Vector3();
  8219. if ( boundingSphere.center !== undefined ) {
  8220. center.fromArray( boundingSphere.center );
  8221. }
  8222. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  8223. }
  8224. return geometry;
  8225. }
  8226. };
  8227. // File:src/loaders/MaterialLoader.js
  8228. /**
  8229. * @author mrdoob / http://mrdoob.com/
  8230. */
  8231. THREE.MaterialLoader = function ( manager ) {
  8232. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8233. };
  8234. THREE.MaterialLoader.prototype = {
  8235. constructor: THREE.MaterialLoader,
  8236. load: function ( url, onLoad, onProgress, onError ) {
  8237. var scope = this;
  8238. var loader = new THREE.XHRLoader( scope.manager );
  8239. loader.setCrossOrigin( this.crossOrigin );
  8240. loader.load( url, function ( text ) {
  8241. onLoad( scope.parse( JSON.parse( text ) ) );
  8242. }, onProgress, onError );
  8243. },
  8244. setCrossOrigin: function ( value ) {
  8245. this.crossOrigin = value;
  8246. },
  8247. parse: function ( json ) {
  8248. var material = new THREE[ json.type ];
  8249. if ( json.color !== undefined ) material.color.setHex( json.color );
  8250. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  8251. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  8252. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  8253. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  8254. if ( json.attributes !== undefined ) material.attributes = json.attributes;
  8255. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  8256. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  8257. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  8258. if ( json.shading !== undefined ) material.shading = json.shading;
  8259. if ( json.blending !== undefined ) material.blending = json.blending;
  8260. if ( json.side !== undefined ) material.side = json.side;
  8261. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  8262. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  8263. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  8264. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  8265. // for PointCloudMaterial
  8266. if ( json.size !== undefined ) material.size = json.size;
  8267. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  8268. if ( json.materials !== undefined ) {
  8269. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  8270. material.materials.push( this.parse( json.materials[ i ] ) );
  8271. }
  8272. }
  8273. return material;
  8274. }
  8275. };
  8276. // File:src/loaders/ObjectLoader.js
  8277. /**
  8278. * @author mrdoob / http://mrdoob.com/
  8279. */
  8280. THREE.ObjectLoader = function ( manager ) {
  8281. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8282. this.texturePath = '';
  8283. };
  8284. THREE.ObjectLoader.prototype = {
  8285. constructor: THREE.ObjectLoader,
  8286. load: function ( url, onLoad, onProgress, onError ) {
  8287. if ( this.texturePath === '' ) {
  8288. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  8289. }
  8290. var scope = this;
  8291. var loader = new THREE.XHRLoader( scope.manager );
  8292. loader.setCrossOrigin( this.crossOrigin );
  8293. loader.load( url, function ( text ) {
  8294. scope.parse( JSON.parse( text ), onLoad );
  8295. }, onProgress, onError );
  8296. },
  8297. setTexturePath: function ( value ) {
  8298. this.texturePath = value;
  8299. },
  8300. setCrossOrigin: function ( value ) {
  8301. this.crossOrigin = value;
  8302. },
  8303. parse: function ( json, onLoad ) {
  8304. var geometries = this.parseGeometries( json.geometries );
  8305. var images = this.parseImages( json.images, function () {
  8306. if ( onLoad !== undefined ) onLoad( object );
  8307. } );
  8308. var textures = this.parseTextures( json.textures, images );
  8309. var materials = this.parseMaterials( json.materials, textures );
  8310. var object = this.parseObject( json.object, geometries, materials );
  8311. if ( json.images === undefined || json.images.length === 0 ) {
  8312. if ( onLoad !== undefined ) onLoad( object );
  8313. }
  8314. return object;
  8315. },
  8316. parseGeometries: function ( json ) {
  8317. var geometries = {};
  8318. if ( json !== undefined ) {
  8319. var geometryLoader = new THREE.JSONLoader();
  8320. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  8321. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8322. var geometry;
  8323. var data = json[ i ];
  8324. switch ( data.type ) {
  8325. case 'PlaneGeometry':
  8326. case 'PlaneBufferGeometry':
  8327. geometry = new THREE[ data.type ](
  8328. data.width,
  8329. data.height,
  8330. data.widthSegments,
  8331. data.heightSegments
  8332. );
  8333. break;
  8334. case 'BoxGeometry':
  8335. case 'CubeGeometry': // backwards compatible
  8336. geometry = new THREE.BoxGeometry(
  8337. data.width,
  8338. data.height,
  8339. data.depth,
  8340. data.widthSegments,
  8341. data.heightSegments,
  8342. data.depthSegments
  8343. );
  8344. break;
  8345. case 'CircleBufferGeometry':
  8346. geometry = new THREE.CircleBufferGeometry(
  8347. data.radius,
  8348. data.segments,
  8349. data.thetaStart,
  8350. data.thetaLength
  8351. );
  8352. break;
  8353. case 'CircleGeometry':
  8354. geometry = new THREE.CircleGeometry(
  8355. data.radius,
  8356. data.segments,
  8357. data.thetaStart,
  8358. data.thetaLength
  8359. );
  8360. break;
  8361. case 'CylinderGeometry':
  8362. geometry = new THREE.CylinderGeometry(
  8363. data.radiusTop,
  8364. data.radiusBottom,
  8365. data.height,
  8366. data.radialSegments,
  8367. data.heightSegments,
  8368. data.openEnded,
  8369. data.thetaStart,
  8370. data.thetaLength
  8371. );
  8372. break;
  8373. case 'SphereGeometry':
  8374. geometry = new THREE.SphereGeometry(
  8375. data.radius,
  8376. data.widthSegments,
  8377. data.heightSegments,
  8378. data.phiStart,
  8379. data.phiLength,
  8380. data.thetaStart,
  8381. data.thetaLength
  8382. );
  8383. break;
  8384. case 'SphereBufferGeometry':
  8385. geometry = new THREE.SphereBufferGeometry(
  8386. data.radius,
  8387. data.widthSegments,
  8388. data.heightSegments,
  8389. data.phiStart,
  8390. data.phiLength,
  8391. data.thetaStart,
  8392. data.thetaLength
  8393. );
  8394. break;
  8395. case 'DodecahedronGeometry':
  8396. geometry = new THREE.DodecahedronGeometry(
  8397. data.radius,
  8398. data.detail
  8399. );
  8400. break;
  8401. case 'IcosahedronGeometry':
  8402. geometry = new THREE.IcosahedronGeometry(
  8403. data.radius,
  8404. data.detail
  8405. );
  8406. break;
  8407. case 'OctahedronGeometry':
  8408. geometry = new THREE.OctahedronGeometry(
  8409. data.radius,
  8410. data.detail
  8411. );
  8412. break;
  8413. case 'TetrahedronGeometry':
  8414. geometry = new THREE.TetrahedronGeometry(
  8415. data.radius,
  8416. data.detail
  8417. );
  8418. break;
  8419. case 'RingGeometry':
  8420. geometry = new THREE.RingGeometry(
  8421. data.innerRadius,
  8422. data.outerRadius,
  8423. data.thetaSegments,
  8424. data.phiSegments,
  8425. data.thetaStart,
  8426. data.thetaLength
  8427. );
  8428. break;
  8429. case 'TorusGeometry':
  8430. geometry = new THREE.TorusGeometry(
  8431. data.radius,
  8432. data.tube,
  8433. data.radialSegments,
  8434. data.tubularSegments,
  8435. data.arc
  8436. );
  8437. break;
  8438. case 'TorusKnotGeometry':
  8439. geometry = new THREE.TorusKnotGeometry(
  8440. data.radius,
  8441. data.tube,
  8442. data.radialSegments,
  8443. data.tubularSegments,
  8444. data.p,
  8445. data.q,
  8446. data.heightScale
  8447. );
  8448. break;
  8449. case 'BufferGeometry':
  8450. geometry = bufferGeometryLoader.parse( data );
  8451. break;
  8452. case 'Geometry':
  8453. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  8454. break;
  8455. case 'TextGeometry':
  8456. geometry = new THREE.TextGeometry(
  8457. data.text,
  8458. data.data
  8459. );
  8460. break;
  8461. }
  8462. geometry.uuid = data.uuid;
  8463. if ( data.name !== undefined ) geometry.name = data.name;
  8464. geometries[ data.uuid ] = geometry;
  8465. }
  8466. }
  8467. return geometries;
  8468. },
  8469. parseMaterials: function ( json, textures ) {
  8470. var materials = {};
  8471. if ( json !== undefined ) {
  8472. var getTexture = function ( name ) {
  8473. if ( textures[ name ] === undefined ) {
  8474. console.warn( 'THREE.ObjectLoader: Undefined texture', name );
  8475. }
  8476. return textures[ name ];
  8477. };
  8478. var loader = new THREE.MaterialLoader();
  8479. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8480. var data = json[ i ];
  8481. var material = loader.parse( data );
  8482. material.uuid = data.uuid;
  8483. if ( data.depthTest !== undefined ) material.depthTest = data.depthTest;
  8484. if ( data.depthWrite !== undefined ) material.depthWrite = data.depthWrite;
  8485. if ( data.name !== undefined ) material.name = data.name;
  8486. if ( data.map !== undefined ) material.map = getTexture( data.map );
  8487. if ( data.alphaMap !== undefined ) {
  8488. material.alphaMap = getTexture( data.alphaMap );
  8489. material.transparent = true;
  8490. }
  8491. if ( data.bumpMap !== undefined ) material.bumpMap = getTexture( data.bumpMap );
  8492. if ( data.bumpScale !== undefined ) material.bumpScale = data.bumpScale;
  8493. if ( data.normalMap !== undefined ) material.normalMap = getTexture( data.normalMap );
  8494. if ( data.normalScale ) material.normalScale = new THREE.Vector2( data.normalScale, data.normalScale );
  8495. if ( data.specularMap !== undefined ) material.specularMap = getTexture( data.specularMap );
  8496. if ( data.envMap !== undefined ) {
  8497. material.envMap = getTexture( data.envMap );
  8498. material.combine = THREE.MultiplyOperation;
  8499. }
  8500. if ( data.reflectivity ) material.reflectivity = data.reflectivity;
  8501. if ( data.lightMap !== undefined ) material.lightMap = getTexture( data.lightMap );
  8502. if ( data.lightMapIntensity !== undefined ) material.lightMapIntensity = data.lightMapIntensity;
  8503. if ( data.aoMap !== undefined ) material.aoMap = getTexture( data.aoMap );
  8504. if ( data.aoMapIntensity !== undefined ) material.aoMapIntensity = data.aoMapIntensity;
  8505. materials[ data.uuid ] = material;
  8506. }
  8507. }
  8508. return materials;
  8509. },
  8510. parseImages: function ( json, onLoad ) {
  8511. var scope = this;
  8512. var images = {};
  8513. if ( json !== undefined && json.length > 0 ) {
  8514. var manager = new THREE.LoadingManager( onLoad );
  8515. var loader = new THREE.ImageLoader( manager );
  8516. loader.setCrossOrigin( this.crossOrigin );
  8517. var loadImage = function ( url ) {
  8518. url = scope.texturePath + url;
  8519. scope.manager.itemStart( url );
  8520. return loader.load( url, function () {
  8521. scope.manager.itemEnd( url );
  8522. } );
  8523. };
  8524. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8525. var image = json[ i ];
  8526. images[ image.uuid ] = loadImage( image.url );
  8527. }
  8528. }
  8529. return images;
  8530. },
  8531. parseTextures: function ( json, images ) {
  8532. function parseConstant( value ) {
  8533. if ( typeof( value ) === 'number' ) return value;
  8534. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  8535. return THREE[ value ];
  8536. }
  8537. var textures = {};
  8538. if ( json !== undefined ) {
  8539. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8540. var data = json[ i ];
  8541. if ( data.image === undefined ) {
  8542. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  8543. }
  8544. if ( images[ data.image ] === undefined ) {
  8545. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  8546. }
  8547. var texture = new THREE.Texture( images[ data.image ] );
  8548. texture.needsUpdate = true;
  8549. texture.uuid = data.uuid;
  8550. if ( data.name !== undefined ) texture.name = data.name;
  8551. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  8552. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  8553. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  8554. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  8555. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  8556. if ( Array.isArray( data.wrap ) ) {
  8557. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  8558. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  8559. }
  8560. textures[ data.uuid ] = texture;
  8561. }
  8562. }
  8563. return textures;
  8564. },
  8565. parseObject: function () {
  8566. var matrix = new THREE.Matrix4();
  8567. return function ( data, geometries, materials ) {
  8568. var object;
  8569. var getGeometry = function ( name ) {
  8570. if ( geometries[ name ] === undefined ) {
  8571. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  8572. }
  8573. return geometries[ name ];
  8574. };
  8575. var getMaterial = function ( name ) {
  8576. if ( materials[ name ] === undefined ) {
  8577. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  8578. }
  8579. return materials[ name ];
  8580. };
  8581. switch ( data.type ) {
  8582. case 'Scene':
  8583. object = new THREE.Scene();
  8584. break;
  8585. case 'PerspectiveCamera':
  8586. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  8587. break;
  8588. case 'OrthographicCamera':
  8589. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  8590. break;
  8591. case 'AmbientLight':
  8592. object = new THREE.AmbientLight( data.color );
  8593. break;
  8594. case 'AreaLight':
  8595. object = new THREE.AreaLight( data.color, data.intensity );
  8596. break;
  8597. case 'DirectionalLight':
  8598. object = new THREE.DirectionalLight( data.color, data.intensity );
  8599. break;
  8600. case 'PointLight':
  8601. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  8602. break;
  8603. case 'SpotLight':
  8604. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  8605. break;
  8606. case 'HemisphereLight':
  8607. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  8608. break;
  8609. case 'Mesh':
  8610. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  8611. break;
  8612. case 'Line':
  8613. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  8614. break;
  8615. case 'PointCloud':
  8616. object = new THREE.PointCloud( getGeometry( data.geometry ), getMaterial( data.material ) );
  8617. break;
  8618. case 'Sprite':
  8619. object = new THREE.Sprite( getMaterial( data.material ) );
  8620. break;
  8621. case 'Group':
  8622. object = new THREE.Group();
  8623. break;
  8624. default:
  8625. object = new THREE.Object3D();
  8626. }
  8627. object.uuid = data.uuid;
  8628. if ( data.name !== undefined ) object.name = data.name;
  8629. if ( data.matrix !== undefined ) {
  8630. matrix.fromArray( data.matrix );
  8631. matrix.decompose( object.position, object.quaternion, object.scale );
  8632. } else {
  8633. if ( data.position !== undefined ) object.position.fromArray( data.position );
  8634. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  8635. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  8636. }
  8637. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  8638. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  8639. if ( data.visible !== undefined ) object.visible = data.visible;
  8640. if ( data.userData !== undefined ) object.userData = data.userData;
  8641. if ( data.children !== undefined ) {
  8642. for ( var child in data.children ) {
  8643. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  8644. }
  8645. }
  8646. return object;
  8647. }
  8648. }()
  8649. };
  8650. // File:src/loaders/TextureLoader.js
  8651. /**
  8652. * @author mrdoob / http://mrdoob.com/
  8653. */
  8654. THREE.TextureLoader = function ( manager ) {
  8655. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8656. };
  8657. THREE.TextureLoader.prototype = {
  8658. constructor: THREE.TextureLoader,
  8659. load: function ( url, onLoad, onProgress, onError ) {
  8660. var scope = this;
  8661. var loader = new THREE.ImageLoader( scope.manager );
  8662. loader.setCrossOrigin( this.crossOrigin );
  8663. loader.load( url, function ( image ) {
  8664. var texture = new THREE.Texture( image );
  8665. texture.needsUpdate = true;
  8666. if ( onLoad !== undefined ) {
  8667. onLoad( texture );
  8668. }
  8669. }, onProgress, onError );
  8670. },
  8671. setCrossOrigin: function ( value ) {
  8672. this.crossOrigin = value;
  8673. }
  8674. };
  8675. // File:src/loaders/BinaryTextureLoader.js
  8676. /**
  8677. * @author Nikos M. / https://github.com/foo123/
  8678. *
  8679. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  8680. */
  8681. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  8682. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8683. // override in sub classes
  8684. this._parser = null;
  8685. };
  8686. THREE.BinaryTextureLoader.prototype = {
  8687. constructor: THREE.BinaryTextureLoader,
  8688. load: function ( url, onLoad, onProgress, onError ) {
  8689. var scope = this;
  8690. var texture = new THREE.DataTexture();
  8691. var loader = new THREE.XHRLoader( this.manager );
  8692. loader.setCrossOrigin( this.crossOrigin );
  8693. loader.setResponseType( 'arraybuffer' );
  8694. loader.load( url, function ( buffer ) {
  8695. var texData = scope._parser( buffer );
  8696. if ( ! texData ) return;
  8697. if ( undefined !== texData.image ) {
  8698. texture.image = texData.image;
  8699. } else if ( undefined !== texData.data ) {
  8700. texture.image.width = texData.width;
  8701. texture.image.height = texData.height;
  8702. texture.image.data = texData.data;
  8703. }
  8704. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  8705. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  8706. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  8707. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  8708. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  8709. if ( undefined !== texData.format ) {
  8710. texture.format = texData.format;
  8711. }
  8712. if ( undefined !== texData.type ) {
  8713. texture.type = texData.type;
  8714. }
  8715. if ( undefined !== texData.mipmaps ) {
  8716. texture.mipmaps = texData.mipmaps;
  8717. }
  8718. if ( 1 === texData.mipmapCount ) {
  8719. texture.minFilter = THREE.LinearFilter;
  8720. }
  8721. texture.needsUpdate = true;
  8722. if ( onLoad ) onLoad( texture, texData );
  8723. }, onProgress, onError );
  8724. return texture;
  8725. },
  8726. setCrossOrigin: function ( value ) {
  8727. this.crossOrigin = value;
  8728. }
  8729. };
  8730. // File:src/loaders/CompressedTextureLoader.js
  8731. /**
  8732. * @author mrdoob / http://mrdoob.com/
  8733. *
  8734. * Abstract Base class to block based textures loader (dds, pvr, ...)
  8735. */
  8736. THREE.CompressedTextureLoader = function ( manager ) {
  8737. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8738. // override in sub classes
  8739. this._parser = null;
  8740. };
  8741. THREE.CompressedTextureLoader.prototype = {
  8742. constructor: THREE.CompressedTextureLoader,
  8743. load: function ( url, onLoad, onProgress, onError ) {
  8744. var scope = this;
  8745. var images = [];
  8746. var texture = new THREE.CompressedTexture();
  8747. texture.image = images;
  8748. var loader = new THREE.XHRLoader( this.manager );
  8749. loader.setCrossOrigin( this.crossOrigin );
  8750. loader.setResponseType( 'arraybuffer' );
  8751. if ( Array.isArray( url ) ) {
  8752. var loaded = 0;
  8753. var loadTexture = function ( i ) {
  8754. loader.load( url[ i ], function ( buffer ) {
  8755. var texDatas = scope._parser( buffer, true );
  8756. images[ i ] = {
  8757. width: texDatas.width,
  8758. height: texDatas.height,
  8759. format: texDatas.format,
  8760. mipmaps: texDatas.mipmaps
  8761. };
  8762. loaded += 1;
  8763. if ( loaded === 6 ) {
  8764. if ( texDatas.mipmapCount === 1 )
  8765. texture.minFilter = THREE.LinearFilter;
  8766. texture.format = texDatas.format;
  8767. texture.needsUpdate = true;
  8768. if ( onLoad ) onLoad( texture );
  8769. }
  8770. }, onProgress, onError );
  8771. };
  8772. for ( var i = 0, il = url.length; i < il; ++ i ) {
  8773. loadTexture( i );
  8774. }
  8775. } else {
  8776. // compressed cubemap texture stored in a single DDS file
  8777. loader.load( url, function ( buffer ) {
  8778. var texDatas = scope._parser( buffer, true );
  8779. if ( texDatas.isCubemap ) {
  8780. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  8781. for ( var f = 0; f < faces; f ++ ) {
  8782. images[ f ] = { mipmaps : [] };
  8783. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  8784. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  8785. images[ f ].format = texDatas.format;
  8786. images[ f ].width = texDatas.width;
  8787. images[ f ].height = texDatas.height;
  8788. }
  8789. }
  8790. } else {
  8791. texture.image.width = texDatas.width;
  8792. texture.image.height = texDatas.height;
  8793. texture.mipmaps = texDatas.mipmaps;
  8794. }
  8795. if ( texDatas.mipmapCount === 1 ) {
  8796. texture.minFilter = THREE.LinearFilter;
  8797. }
  8798. texture.format = texDatas.format;
  8799. texture.needsUpdate = true;
  8800. if ( onLoad ) onLoad( texture );
  8801. }, onProgress, onError );
  8802. }
  8803. return texture;
  8804. },
  8805. setCrossOrigin: function ( value ) {
  8806. this.crossOrigin = value;
  8807. }
  8808. };
  8809. // File:src/materials/Material.js
  8810. /**
  8811. * @author mrdoob / http://mrdoob.com/
  8812. * @author alteredq / http://alteredqualia.com/
  8813. */
  8814. THREE.Material = function () {
  8815. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  8816. this.uuid = THREE.Math.generateUUID();
  8817. this.name = '';
  8818. this.type = 'Material';
  8819. this.side = THREE.FrontSide;
  8820. this.opacity = 1;
  8821. this.transparent = false;
  8822. this.blending = THREE.NormalBlending;
  8823. this.blendSrc = THREE.SrcAlphaFactor;
  8824. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  8825. this.blendEquation = THREE.AddEquation;
  8826. this.blendSrcAlpha = null;
  8827. this.blendDstAlpha = null;
  8828. this.blendEquationAlpha = null;
  8829. this.depthFunc = THREE.LessEqualDepth;
  8830. this.depthTest = true;
  8831. this.depthWrite = true;
  8832. this.colorWrite = true;
  8833. this.precision = null; // override the renderer's default precision for this material
  8834. this.polygonOffset = false;
  8835. this.polygonOffsetFactor = 0;
  8836. this.polygonOffsetUnits = 0;
  8837. this.alphaTest = 0;
  8838. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  8839. this.visible = true;
  8840. this._needsUpdate = true;
  8841. };
  8842. THREE.Material.prototype = {
  8843. constructor: THREE.Material,
  8844. get needsUpdate () {
  8845. return this._needsUpdate;
  8846. },
  8847. set needsUpdate ( value ) {
  8848. if ( value === true ) this.update();
  8849. this._needsUpdate = value;
  8850. },
  8851. setValues: function ( values ) {
  8852. if ( values === undefined ) return;
  8853. for ( var key in values ) {
  8854. var newValue = values[ key ];
  8855. if ( newValue === undefined ) {
  8856. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  8857. continue;
  8858. }
  8859. if ( key in this ) {
  8860. var currentValue = this[ key ];
  8861. if ( currentValue instanceof THREE.Color ) {
  8862. currentValue.set( newValue );
  8863. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  8864. currentValue.copy( newValue );
  8865. } else if ( key === 'overdraw' ) {
  8866. // ensure overdraw is backwards-compatible with legacy boolean type
  8867. this[ key ] = Number( newValue );
  8868. } else {
  8869. this[ key ] = newValue;
  8870. }
  8871. }
  8872. }
  8873. },
  8874. toJSON: function ( meta ) {
  8875. var data = {
  8876. metadata: {
  8877. version: 4.4,
  8878. type: 'Material',
  8879. generator: 'Material.toJSON'
  8880. }
  8881. };
  8882. // standard Material serialization
  8883. data.uuid = this.uuid;
  8884. data.type = this.type;
  8885. if ( this.name !== '' ) data.name = this.name;
  8886. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  8887. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  8888. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  8889. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  8890. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  8891. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  8892. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  8893. if ( this.bumpMap instanceof THREE.Texture ) {
  8894. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  8895. data.bumpScale = this.bumpScale;
  8896. }
  8897. if ( this.normalMap instanceof THREE.Texture ) {
  8898. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  8899. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  8900. }
  8901. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  8902. if ( this.envMap instanceof THREE.Texture ) {
  8903. data.envMap = this.envMap.toJSON( meta ).uuid;
  8904. data.reflectivity = this.reflectivity; // Scale behind envMap
  8905. }
  8906. if ( this.size !== undefined ) data.size = this.size;
  8907. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  8908. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  8909. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  8910. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  8911. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  8912. if ( this.opacity < 1 ) data.opacity = this.opacity;
  8913. if ( this.transparent === true ) data.transparent = this.transparent;
  8914. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  8915. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  8916. return data;
  8917. },
  8918. clone: function () {
  8919. return new THREE.Material().copy( this );
  8920. },
  8921. copy: function ( source ) {
  8922. this.name = source.name;
  8923. this.side = source.side;
  8924. this.opacity = source.opacity;
  8925. this.transparent = source.transparent;
  8926. this.blending = source.blending;
  8927. this.blendSrc = source.blendSrc;
  8928. this.blendDst = source.blendDst;
  8929. this.blendEquation = source.blendEquation;
  8930. this.blendSrcAlpha = source.blendSrcAlpha;
  8931. this.blendDstAlpha = source.blendDstAlpha;
  8932. this.blendEquationAlpha = source.blendEquationAlpha;
  8933. this.depthFunc = source.depthFunc;
  8934. this.depthTest = source.depthTest;
  8935. this.depthWrite = source.depthWrite;
  8936. this.precision = source.precision;
  8937. this.polygonOffset = source.polygonOffset;
  8938. this.polygonOffsetFactor = source.polygonOffsetFactor;
  8939. this.polygonOffsetUnits = source.polygonOffsetUnits;
  8940. this.alphaTest = source.alphaTest;
  8941. this.overdraw = source.overdraw;
  8942. this.visible = source.visible;
  8943. return this;
  8944. },
  8945. update: function () {
  8946. this.dispatchEvent( { type: 'update' } );
  8947. },
  8948. dispose: function () {
  8949. this.dispatchEvent( { type: 'dispose' } );
  8950. }
  8951. };
  8952. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  8953. THREE.MaterialIdCount = 0;
  8954. // File:src/materials/LineBasicMaterial.js
  8955. /**
  8956. * @author mrdoob / http://mrdoob.com/
  8957. * @author alteredq / http://alteredqualia.com/
  8958. *
  8959. * parameters = {
  8960. * color: <hex>,
  8961. * opacity: <float>,
  8962. *
  8963. * blending: THREE.NormalBlending,
  8964. * depthTest: <bool>,
  8965. * depthWrite: <bool>,
  8966. *
  8967. * linewidth: <float>,
  8968. * linecap: "round",
  8969. * linejoin: "round",
  8970. *
  8971. * vertexColors: <bool>
  8972. *
  8973. * fog: <bool>
  8974. * }
  8975. */
  8976. THREE.LineBasicMaterial = function ( parameters ) {
  8977. THREE.Material.call( this );
  8978. this.type = 'LineBasicMaterial';
  8979. this.color = new THREE.Color( 0xffffff );
  8980. this.linewidth = 1;
  8981. this.linecap = 'round';
  8982. this.linejoin = 'round';
  8983. this.vertexColors = THREE.NoColors;
  8984. this.fog = true;
  8985. this.setValues( parameters );
  8986. };
  8987. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8988. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  8989. THREE.LineBasicMaterial.prototype.clone = function () {
  8990. var material = new THREE.LineBasicMaterial();
  8991. material.copy( this );
  8992. material.color.copy( this.color );
  8993. material.linewidth = this.linewidth;
  8994. material.linecap = this.linecap;
  8995. material.linejoin = this.linejoin;
  8996. material.vertexColors = this.vertexColors;
  8997. material.fog = this.fog;
  8998. return material;
  8999. };
  9000. // File:src/materials/LineDashedMaterial.js
  9001. /**
  9002. * @author alteredq / http://alteredqualia.com/
  9003. *
  9004. * parameters = {
  9005. * color: <hex>,
  9006. * opacity: <float>,
  9007. *
  9008. * blending: THREE.NormalBlending,
  9009. * depthTest: <bool>,
  9010. * depthWrite: <bool>,
  9011. *
  9012. * linewidth: <float>,
  9013. *
  9014. * scale: <float>,
  9015. * dashSize: <float>,
  9016. * gapSize: <float>,
  9017. *
  9018. * vertexColors: <bool>
  9019. *
  9020. * fog: <bool>
  9021. * }
  9022. */
  9023. THREE.LineDashedMaterial = function ( parameters ) {
  9024. THREE.Material.call( this );
  9025. this.type = 'LineDashedMaterial';
  9026. this.color = new THREE.Color( 0xffffff );
  9027. this.linewidth = 1;
  9028. this.scale = 1;
  9029. this.dashSize = 3;
  9030. this.gapSize = 1;
  9031. this.vertexColors = false;
  9032. this.fog = true;
  9033. this.setValues( parameters );
  9034. };
  9035. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  9036. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  9037. THREE.LineDashedMaterial.prototype.clone = function () {
  9038. var material = new THREE.LineDashedMaterial();
  9039. material.copy( this );
  9040. material.color.copy( this.color );
  9041. material.linewidth = this.linewidth;
  9042. material.scale = this.scale;
  9043. material.dashSize = this.dashSize;
  9044. material.gapSize = this.gapSize;
  9045. material.vertexColors = this.vertexColors;
  9046. material.fog = this.fog;
  9047. return material;
  9048. };
  9049. // File:src/materials/MeshBasicMaterial.js
  9050. /**
  9051. * @author mrdoob / http://mrdoob.com/
  9052. * @author alteredq / http://alteredqualia.com/
  9053. *
  9054. * parameters = {
  9055. * color: <hex>,
  9056. * opacity: <float>,
  9057. * map: new THREE.Texture( <Image> ),
  9058. *
  9059. * aoMap: new THREE.Texture( <Image> ),
  9060. * aoMapIntensity: <float>
  9061. *
  9062. * specularMap: new THREE.Texture( <Image> ),
  9063. *
  9064. * alphaMap: new THREE.Texture( <Image> ),
  9065. *
  9066. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  9067. * combine: THREE.Multiply,
  9068. * reflectivity: <float>,
  9069. * refractionRatio: <float>,
  9070. *
  9071. * shading: THREE.SmoothShading,
  9072. * blending: THREE.NormalBlending,
  9073. * depthTest: <bool>,
  9074. * depthWrite: <bool>,
  9075. *
  9076. * wireframe: <boolean>,
  9077. * wireframeLinewidth: <float>,
  9078. *
  9079. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9080. *
  9081. * skinning: <bool>,
  9082. * morphTargets: <bool>,
  9083. *
  9084. * fog: <bool>
  9085. * }
  9086. */
  9087. THREE.MeshBasicMaterial = function ( parameters ) {
  9088. THREE.Material.call( this );
  9089. this.type = 'MeshBasicMaterial';
  9090. this.color = new THREE.Color( 0xffffff ); // emissive
  9091. this.map = null;
  9092. this.aoMap = null;
  9093. this.aoMapIntensity = 1.0;
  9094. this.specularMap = null;
  9095. this.alphaMap = null;
  9096. this.envMap = null;
  9097. this.combine = THREE.MultiplyOperation;
  9098. this.reflectivity = 1;
  9099. this.refractionRatio = 0.98;
  9100. this.fog = true;
  9101. this.shading = THREE.SmoothShading;
  9102. this.wireframe = false;
  9103. this.wireframeLinewidth = 1;
  9104. this.wireframeLinecap = 'round';
  9105. this.wireframeLinejoin = 'round';
  9106. this.vertexColors = THREE.NoColors;
  9107. this.skinning = false;
  9108. this.morphTargets = false;
  9109. this.setValues( parameters );
  9110. };
  9111. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  9112. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  9113. THREE.MeshBasicMaterial.prototype.clone = function () {
  9114. var material = new THREE.MeshBasicMaterial();
  9115. material.copy( this );
  9116. material.color.copy( this.color );
  9117. material.map = this.map;
  9118. material.aoMap = this.aoMap;
  9119. material.aoMapIntensity = this.aoMapIntensity;
  9120. material.specularMap = this.specularMap;
  9121. material.alphaMap = this.alphaMap;
  9122. material.envMap = this.envMap;
  9123. material.combine = this.combine;
  9124. material.reflectivity = this.reflectivity;
  9125. material.refractionRatio = this.refractionRatio;
  9126. material.fog = this.fog;
  9127. material.shading = this.shading;
  9128. material.wireframe = this.wireframe;
  9129. material.wireframeLinewidth = this.wireframeLinewidth;
  9130. material.wireframeLinecap = this.wireframeLinecap;
  9131. material.wireframeLinejoin = this.wireframeLinejoin;
  9132. material.vertexColors = this.vertexColors;
  9133. material.skinning = this.skinning;
  9134. material.morphTargets = this.morphTargets;
  9135. return material;
  9136. };
  9137. // File:src/materials/MeshLambertMaterial.js
  9138. /**
  9139. * @author mrdoob / http://mrdoob.com/
  9140. * @author alteredq / http://alteredqualia.com/
  9141. *
  9142. * parameters = {
  9143. * color: <hex>,
  9144. * emissive: <hex>,
  9145. * opacity: <float>,
  9146. *
  9147. * map: new THREE.Texture( <Image> ),
  9148. *
  9149. * specularMap: new THREE.Texture( <Image> ),
  9150. *
  9151. * alphaMap: new THREE.Texture( <Image> ),
  9152. *
  9153. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  9154. * combine: THREE.Multiply,
  9155. * reflectivity: <float>,
  9156. * refractionRatio: <float>,
  9157. *
  9158. * shading: THREE.SmoothShading,
  9159. * blending: THREE.NormalBlending,
  9160. * depthTest: <bool>,
  9161. * depthWrite: <bool>,
  9162. *
  9163. * wireframe: <boolean>,
  9164. * wireframeLinewidth: <float>,
  9165. *
  9166. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9167. *
  9168. * skinning: <bool>,
  9169. * morphTargets: <bool>,
  9170. * morphNormals: <bool>,
  9171. *
  9172. * fog: <bool>
  9173. * }
  9174. */
  9175. THREE.MeshLambertMaterial = function ( parameters ) {
  9176. THREE.Material.call( this );
  9177. this.type = 'MeshLambertMaterial';
  9178. this.color = new THREE.Color( 0xffffff ); // diffuse
  9179. this.emissive = new THREE.Color( 0x000000 );
  9180. this.map = null;
  9181. this.specularMap = null;
  9182. this.alphaMap = null;
  9183. this.envMap = null;
  9184. this.combine = THREE.MultiplyOperation;
  9185. this.reflectivity = 1;
  9186. this.refractionRatio = 0.98;
  9187. this.fog = true;
  9188. this.shading = THREE.SmoothShading;
  9189. this.wireframe = false;
  9190. this.wireframeLinewidth = 1;
  9191. this.wireframeLinecap = 'round';
  9192. this.wireframeLinejoin = 'round';
  9193. this.vertexColors = THREE.NoColors;
  9194. this.skinning = false;
  9195. this.morphTargets = false;
  9196. this.morphNormals = false;
  9197. this.setValues( parameters );
  9198. };
  9199. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  9200. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  9201. THREE.MeshLambertMaterial.prototype.clone = function () {
  9202. var material = new THREE.MeshLambertMaterial();
  9203. material.copy( this );
  9204. material.color.copy( this.color );
  9205. material.emissive.copy( this.emissive );
  9206. material.map = this.map;
  9207. material.specularMap = this.specularMap;
  9208. material.alphaMap = this.alphaMap;
  9209. material.envMap = this.envMap;
  9210. material.combine = this.combine;
  9211. material.reflectivity = this.reflectivity;
  9212. material.refractionRatio = this.refractionRatio;
  9213. material.fog = this.fog;
  9214. material.shading = this.shading;
  9215. material.wireframe = this.wireframe;
  9216. material.wireframeLinewidth = this.wireframeLinewidth;
  9217. material.wireframeLinecap = this.wireframeLinecap;
  9218. material.wireframeLinejoin = this.wireframeLinejoin;
  9219. material.vertexColors = this.vertexColors;
  9220. material.skinning = this.skinning;
  9221. material.morphTargets = this.morphTargets;
  9222. material.morphNormals = this.morphNormals;
  9223. return material;
  9224. };
  9225. // File:src/materials/MeshPhongMaterial.js
  9226. /**
  9227. * @author mrdoob / http://mrdoob.com/
  9228. * @author alteredq / http://alteredqualia.com/
  9229. *
  9230. * parameters = {
  9231. * color: <hex>,
  9232. * emissive: <hex>,
  9233. * specular: <hex>,
  9234. * shininess: <float>,
  9235. * opacity: <float>,
  9236. *
  9237. * map: new THREE.Texture( <Image> ),
  9238. *
  9239. * lightMap: new THREE.Texture( <Image> ),
  9240. * lightMapIntensity: <float>
  9241. *
  9242. * aoMap: new THREE.Texture( <Image> ),
  9243. * aoMapIntensity: <float>
  9244. *
  9245. * emissiveMap: new THREE.Texture( <Image> ),
  9246. *
  9247. * bumpMap: new THREE.Texture( <Image> ),
  9248. * bumpScale: <float>,
  9249. *
  9250. * normalMap: new THREE.Texture( <Image> ),
  9251. * normalScale: <Vector2>,
  9252. *
  9253. * specularMap: new THREE.Texture( <Image> ),
  9254. *
  9255. * alphaMap: new THREE.Texture( <Image> ),
  9256. *
  9257. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  9258. * combine: THREE.Multiply,
  9259. * reflectivity: <float>,
  9260. * refractionRatio: <float>,
  9261. *
  9262. * shading: THREE.SmoothShading,
  9263. * blending: THREE.NormalBlending,
  9264. * depthTest: <bool>,
  9265. * depthWrite: <bool>,
  9266. *
  9267. * wireframe: <boolean>,
  9268. * wireframeLinewidth: <float>,
  9269. *
  9270. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9271. *
  9272. * skinning: <bool>,
  9273. * morphTargets: <bool>,
  9274. * morphNormals: <bool>,
  9275. *
  9276. * fog: <bool>
  9277. * }
  9278. */
  9279. THREE.MeshPhongMaterial = function ( parameters ) {
  9280. THREE.Material.call( this );
  9281. this.type = 'MeshPhongMaterial';
  9282. this.color = new THREE.Color( 0xffffff ); // diffuse
  9283. this.emissive = new THREE.Color( 0x000000 );
  9284. this.specular = new THREE.Color( 0x111111 );
  9285. this.shininess = 30;
  9286. this.metal = false;
  9287. this.map = null;
  9288. this.lightMap = null;
  9289. this.lightMapIntensity = 1.0;
  9290. this.aoMap = null;
  9291. this.aoMapIntensity = 1.0;
  9292. this.emissiveMap = null;
  9293. this.bumpMap = null;
  9294. this.bumpScale = 1;
  9295. this.normalMap = null;
  9296. this.normalScale = new THREE.Vector2( 1, 1 );
  9297. this.specularMap = null;
  9298. this.alphaMap = null;
  9299. this.envMap = null;
  9300. this.combine = THREE.MultiplyOperation;
  9301. this.reflectivity = 1;
  9302. this.refractionRatio = 0.98;
  9303. this.fog = true;
  9304. this.shading = THREE.SmoothShading;
  9305. this.wireframe = false;
  9306. this.wireframeLinewidth = 1;
  9307. this.wireframeLinecap = 'round';
  9308. this.wireframeLinejoin = 'round';
  9309. this.vertexColors = THREE.NoColors;
  9310. this.skinning = false;
  9311. this.morphTargets = false;
  9312. this.morphNormals = false;
  9313. this.setValues( parameters );
  9314. };
  9315. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  9316. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  9317. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  9318. THREE.Material.prototype.copy.call( this, source );
  9319. this.color.copy( source.color );
  9320. this.emissive.copy( source.emissive );
  9321. this.specular.copy( source.specular );
  9322. this.shininess = source.shininess;
  9323. this.metal = source.metal;
  9324. this.map = source.map;
  9325. this.lightMap = source.lightMap;
  9326. this.lightMapIntensity = source.lightMapIntensity;
  9327. this.aoMap = source.aoMap;
  9328. this.aoMapIntensity = source.aoMapIntensity;
  9329. this.emissiveMap = source.emissiveMap;
  9330. this.bumpMap = source.bumpMap;
  9331. this.bumpScale = source.bumpScale;
  9332. this.normalMap = source.normalMap;
  9333. this.normalScale.copy( source.normalScale );
  9334. this.specularMap = source.specularMap;
  9335. this.alphaMap = source.alphaMap;
  9336. this.envMap = source.envMap;
  9337. this.combine = source.combine;
  9338. this.reflectivity = source.reflectivity;
  9339. this.refractionRatio = source.refractionRatio;
  9340. this.fog = source.fog;
  9341. this.shading = source.shading;
  9342. this.wireframe = source.wireframe;
  9343. this.wireframeLinewidth = source.wireframeLinewidth;
  9344. this.wireframeLinecap = source.wireframeLinecap;
  9345. this.wireframeLinejoin = source.wireframeLinejoin;
  9346. this.vertexColors = source.vertexColors;
  9347. this.skinning = source.skinning;
  9348. this.morphTargets = source.morphTargets;
  9349. this.morphNormals = source.morphNormals;
  9350. return this;
  9351. };
  9352. THREE.MeshPhongMaterial.prototype.clone = function () {
  9353. return new THREE.MeshPhongMaterial().copy( this );
  9354. };
  9355. // File:src/materials/MeshDepthMaterial.js
  9356. /**
  9357. * @author mrdoob / http://mrdoob.com/
  9358. * @author alteredq / http://alteredqualia.com/
  9359. *
  9360. * parameters = {
  9361. * opacity: <float>,
  9362. *
  9363. * blending: THREE.NormalBlending,
  9364. * depthTest: <bool>,
  9365. * depthWrite: <bool>,
  9366. *
  9367. * wireframe: <boolean>,
  9368. * wireframeLinewidth: <float>
  9369. * }
  9370. */
  9371. THREE.MeshDepthMaterial = function ( parameters ) {
  9372. THREE.Material.call( this );
  9373. this.type = 'MeshDepthMaterial';
  9374. this.morphTargets = false;
  9375. this.wireframe = false;
  9376. this.wireframeLinewidth = 1;
  9377. this.setValues( parameters );
  9378. };
  9379. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  9380. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  9381. THREE.MeshDepthMaterial.prototype.clone = function () {
  9382. var material = new THREE.MeshDepthMaterial();
  9383. material.copy( this );
  9384. material.wireframe = this.wireframe;
  9385. material.wireframeLinewidth = this.wireframeLinewidth;
  9386. return material;
  9387. };
  9388. // File:src/materials/MeshNormalMaterial.js
  9389. /**
  9390. * @author mrdoob / http://mrdoob.com/
  9391. *
  9392. * parameters = {
  9393. * opacity: <float>,
  9394. *
  9395. * shading: THREE.FlatShading,
  9396. * blending: THREE.NormalBlending,
  9397. * depthTest: <bool>,
  9398. * depthWrite: <bool>,
  9399. *
  9400. * wireframe: <boolean>,
  9401. * wireframeLinewidth: <float>
  9402. * }
  9403. */
  9404. THREE.MeshNormalMaterial = function ( parameters ) {
  9405. THREE.Material.call( this, parameters );
  9406. this.type = 'MeshNormalMaterial';
  9407. this.wireframe = false;
  9408. this.wireframeLinewidth = 1;
  9409. this.morphTargets = false;
  9410. this.setValues( parameters );
  9411. };
  9412. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  9413. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  9414. THREE.MeshNormalMaterial.prototype.clone = function () {
  9415. var material = new THREE.MeshNormalMaterial();
  9416. material.copy( this );
  9417. material.wireframe = this.wireframe;
  9418. material.wireframeLinewidth = this.wireframeLinewidth;
  9419. return material;
  9420. };
  9421. // File:src/materials/MeshFaceMaterial.js
  9422. /**
  9423. * @author mrdoob / http://mrdoob.com/
  9424. */
  9425. THREE.MeshFaceMaterial = function ( materials ) {
  9426. this.uuid = THREE.Math.generateUUID();
  9427. this.type = 'MeshFaceMaterial';
  9428. this.materials = materials instanceof Array ? materials : [];
  9429. this.visible = true;
  9430. };
  9431. THREE.MeshFaceMaterial.prototype = {
  9432. constructor: THREE.MeshFaceMaterial,
  9433. toJSON: function () {
  9434. var output = {
  9435. metadata: {
  9436. version: 4.2,
  9437. type: 'material',
  9438. generator: 'MaterialExporter'
  9439. },
  9440. uuid: this.uuid,
  9441. type: this.type,
  9442. materials: []
  9443. };
  9444. for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
  9445. output.materials.push( this.materials[ i ].toJSON() );
  9446. }
  9447. output.visible = this.visible;
  9448. return output;
  9449. },
  9450. clone: function () {
  9451. var material = new THREE.MeshFaceMaterial();
  9452. for ( var i = 0; i < this.materials.length; i ++ ) {
  9453. material.materials.push( this.materials[ i ].clone() );
  9454. }
  9455. material.visible = this.visible;
  9456. return material;
  9457. }
  9458. };
  9459. // File:src/materials/PointCloudMaterial.js
  9460. /**
  9461. * @author mrdoob / http://mrdoob.com/
  9462. * @author alteredq / http://alteredqualia.com/
  9463. *
  9464. * parameters = {
  9465. * color: <hex>,
  9466. * opacity: <float>,
  9467. * map: new THREE.Texture( <Image> ),
  9468. *
  9469. * size: <float>,
  9470. * sizeAttenuation: <bool>,
  9471. *
  9472. * blending: THREE.NormalBlending,
  9473. * depthTest: <bool>,
  9474. * depthWrite: <bool>,
  9475. *
  9476. * vertexColors: <bool>,
  9477. *
  9478. * fog: <bool>
  9479. * }
  9480. */
  9481. THREE.PointCloudMaterial = function ( parameters ) {
  9482. THREE.Material.call( this );
  9483. this.type = 'PointCloudMaterial';
  9484. this.color = new THREE.Color( 0xffffff );
  9485. this.map = null;
  9486. this.size = 1;
  9487. this.sizeAttenuation = true;
  9488. this.vertexColors = THREE.NoColors;
  9489. this.fog = true;
  9490. this.setValues( parameters );
  9491. };
  9492. THREE.PointCloudMaterial.prototype = Object.create( THREE.Material.prototype );
  9493. THREE.PointCloudMaterial.prototype.constructor = THREE.PointCloudMaterial;
  9494. THREE.PointCloudMaterial.prototype.clone = function () {
  9495. var material = new THREE.PointCloudMaterial();
  9496. material.copy( this );
  9497. material.color.copy( this.color );
  9498. material.map = this.map;
  9499. material.size = this.size;
  9500. material.sizeAttenuation = this.sizeAttenuation;
  9501. material.vertexColors = this.vertexColors;
  9502. material.fog = this.fog;
  9503. return material;
  9504. };
  9505. // backwards compatibility
  9506. THREE.ParticleBasicMaterial = function ( parameters ) {
  9507. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointCloudMaterial.' );
  9508. return new THREE.PointCloudMaterial( parameters );
  9509. };
  9510. THREE.ParticleSystemMaterial = function ( parameters ) {
  9511. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointCloudMaterial.' );
  9512. return new THREE.PointCloudMaterial( parameters );
  9513. };
  9514. // File:src/materials/ShaderMaterial.js
  9515. /**
  9516. * @author alteredq / http://alteredqualia.com/
  9517. *
  9518. * parameters = {
  9519. * defines: { "label" : "value" },
  9520. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  9521. *
  9522. * fragmentShader: <string>,
  9523. * vertexShader: <string>,
  9524. *
  9525. * shading: THREE.SmoothShading,
  9526. * blending: THREE.NormalBlending,
  9527. * depthTest: <bool>,
  9528. * depthWrite: <bool>,
  9529. *
  9530. * wireframe: <boolean>,
  9531. * wireframeLinewidth: <float>,
  9532. *
  9533. * lights: <bool>,
  9534. *
  9535. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9536. *
  9537. * skinning: <bool>,
  9538. * morphTargets: <bool>,
  9539. * morphNormals: <bool>,
  9540. *
  9541. * fog: <bool>
  9542. * }
  9543. */
  9544. THREE.ShaderMaterial = function ( parameters ) {
  9545. THREE.Material.call( this );
  9546. this.type = 'ShaderMaterial';
  9547. this.defines = {};
  9548. this.uniforms = {};
  9549. this.attributes = [];
  9550. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  9551. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  9552. this.shading = THREE.SmoothShading;
  9553. this.linewidth = 1;
  9554. this.wireframe = false;
  9555. this.wireframeLinewidth = 1;
  9556. this.fog = false; // set to use scene fog
  9557. this.lights = false; // set to use scene lights
  9558. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  9559. this.skinning = false; // set to use skinning attribute streams
  9560. this.morphTargets = false; // set to use morph targets
  9561. this.morphNormals = false; // set to use morph normals
  9562. this.derivatives = false; // set to use derivatives
  9563. // When rendered geometry doesn't include these attributes but the material does,
  9564. // use these default values in WebGL. This avoids errors when buffer data is missing.
  9565. this.defaultAttributeValues = {
  9566. 'color': [ 1, 1, 1 ],
  9567. 'uv': [ 0, 0 ],
  9568. 'uv2': [ 0, 0 ]
  9569. };
  9570. this.index0AttributeName = undefined;
  9571. if ( parameters !== undefined ) {
  9572. if ( parameters.attributes !== undefined && Array.isArray( parameters.attributes ) === false ) {
  9573. console.warn( 'THREE.ShaderMaterial: attributes should now be an array of attribute names.' );
  9574. parameters.attributes = Object.keys( parameters.attributes );
  9575. }
  9576. this.setValues( parameters );
  9577. }
  9578. };
  9579. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  9580. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  9581. THREE.ShaderMaterial.prototype.clone = function () {
  9582. var material = new THREE.ShaderMaterial();
  9583. return material.copy( this );
  9584. };
  9585. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  9586. THREE.Material.prototype.copy.call( this, source );
  9587. this.fragmentShader = source.fragmentShader;
  9588. this.vertexShader = source.vertexShader;
  9589. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  9590. this.attributes = source.attributes;
  9591. this.defines = source.defines;
  9592. this.shading = source.shading;
  9593. this.wireframe = source.wireframe;
  9594. this.wireframeLinewidth = source.wireframeLinewidth;
  9595. this.fog = source.fog;
  9596. this.lights = source.lights;
  9597. this.vertexColors = source.vertexColors;
  9598. this.skinning = source.skinning;
  9599. this.morphTargets = source.morphTargets;
  9600. this.morphNormals = source.morphNormals;
  9601. return this;
  9602. };
  9603. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  9604. var data = THREE.Material.prototype.toJSON.call( this, meta );
  9605. data.uniforms = this.uniforms;
  9606. data.attributes = this.attributes;
  9607. data.vertexShader = this.vertexShader;
  9608. data.fragmentShader = this.fragmentShader;
  9609. return data;
  9610. };
  9611. // File:src/materials/RawShaderMaterial.js
  9612. /**
  9613. * @author mrdoob / http://mrdoob.com/
  9614. */
  9615. THREE.RawShaderMaterial = function ( parameters ) {
  9616. THREE.ShaderMaterial.call( this, parameters );
  9617. this.type = 'RawShaderMaterial';
  9618. };
  9619. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  9620. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  9621. THREE.RawShaderMaterial.prototype.clone = function () {
  9622. var material = new THREE.RawShaderMaterial();
  9623. material.copy( this );
  9624. return material;
  9625. };
  9626. // File:src/materials/SpriteMaterial.js
  9627. /**
  9628. * @author alteredq / http://alteredqualia.com/
  9629. *
  9630. * parameters = {
  9631. * color: <hex>,
  9632. * opacity: <float>,
  9633. * map: new THREE.Texture( <Image> ),
  9634. *
  9635. * blending: THREE.NormalBlending,
  9636. * depthTest: <bool>,
  9637. * depthWrite: <bool>,
  9638. *
  9639. * uvOffset: new THREE.Vector2(),
  9640. * uvScale: new THREE.Vector2(),
  9641. *
  9642. * fog: <bool>
  9643. * }
  9644. */
  9645. THREE.SpriteMaterial = function ( parameters ) {
  9646. THREE.Material.call( this );
  9647. this.type = 'SpriteMaterial';
  9648. this.color = new THREE.Color( 0xffffff );
  9649. this.map = null;
  9650. this.rotation = 0;
  9651. this.fog = false;
  9652. // set parameters
  9653. this.setValues( parameters );
  9654. };
  9655. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  9656. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  9657. THREE.SpriteMaterial.prototype.clone = function () {
  9658. var material = new THREE.SpriteMaterial();
  9659. material.copy( this );
  9660. material.color.copy( this.color );
  9661. material.map = this.map;
  9662. material.rotation = this.rotation;
  9663. material.fog = this.fog;
  9664. return material;
  9665. };
  9666. // File:src/textures/Texture.js
  9667. /**
  9668. * @author mrdoob / http://mrdoob.com/
  9669. * @author alteredq / http://alteredqualia.com/
  9670. * @author szimek / https://github.com/szimek/
  9671. */
  9672. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9673. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  9674. this.uuid = THREE.Math.generateUUID();
  9675. this.name = '';
  9676. this.sourceFile = '';
  9677. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  9678. this.mipmaps = [];
  9679. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  9680. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  9681. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  9682. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  9683. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  9684. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  9685. this.format = format !== undefined ? format : THREE.RGBAFormat;
  9686. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  9687. this.offset = new THREE.Vector2( 0, 0 );
  9688. this.repeat = new THREE.Vector2( 1, 1 );
  9689. this.generateMipmaps = true;
  9690. this.premultiplyAlpha = false;
  9691. this.flipY = true;
  9692. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  9693. this.version = 0;
  9694. this.onUpdate = null;
  9695. };
  9696. THREE.Texture.DEFAULT_IMAGE = undefined;
  9697. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  9698. THREE.Texture.prototype = {
  9699. constructor: THREE.Texture,
  9700. set needsUpdate ( value ) {
  9701. if ( value === true ) this.version ++;
  9702. },
  9703. clone: function () {
  9704. return new THREE.Texture().copy( this );
  9705. },
  9706. copy: function ( source ) {
  9707. this.image = source.image;
  9708. this.mipmaps = source.mipmaps.slice( 0 );
  9709. this.mapping = source.mapping;
  9710. this.wrapS = source.wrapS;
  9711. this.wrapT = source.wrapT;
  9712. this.magFilter = source.magFilter;
  9713. this.minFilter = source.minFilter;
  9714. this.anisotropy = source.anisotropy;
  9715. this.format = source.format;
  9716. this.type = source.type;
  9717. this.offset.copy( source.offset );
  9718. this.repeat.copy( source.repeat );
  9719. this.generateMipmaps = source.generateMipmaps;
  9720. this.premultiplyAlpha = source.premultiplyAlpha;
  9721. this.flipY = source.flipY;
  9722. this.unpackAlignment = source.unpackAlignment;
  9723. return this;
  9724. },
  9725. toJSON: function ( meta ) {
  9726. if ( meta.textures[ this.uuid ] !== undefined ) {
  9727. return meta.textures[ this.uuid ];
  9728. }
  9729. function getDataURL( image ) {
  9730. var canvas;
  9731. if ( image.toDataURL !== undefined ) {
  9732. canvas = image;
  9733. } else {
  9734. canvas = document.createElement( 'canvas' );
  9735. canvas.width = image.width;
  9736. canvas.height = image.height;
  9737. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  9738. }
  9739. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  9740. return canvas.toDataURL( 'image/jpeg', 0.6 );
  9741. } else {
  9742. return canvas.toDataURL( 'image/png' );
  9743. }
  9744. }
  9745. var output = {
  9746. metadata: {
  9747. version: 4.4,
  9748. type: 'Texture',
  9749. generator: 'Texture.toJSON'
  9750. },
  9751. uuid: this.uuid,
  9752. name: this.name,
  9753. mapping: this.mapping,
  9754. repeat: [ this.repeat.x, this.repeat.y ],
  9755. offset: [ this.offset.x, this.offset.y ],
  9756. wrap: [ this.wrapS, this.wrapT ],
  9757. minFilter: this.minFilter,
  9758. magFilter: this.magFilter,
  9759. anisotropy: this.anisotropy
  9760. };
  9761. if ( this.image !== undefined ) {
  9762. // TODO: Move to THREE.Image
  9763. var image = this.image;
  9764. if ( image.uuid === undefined ) {
  9765. image.uuid = THREE.Math.generateUUID(); // UGH
  9766. }
  9767. if ( meta.images[ image.uuid ] === undefined ) {
  9768. meta.images[ image.uuid ] = {
  9769. uuid: image.uuid,
  9770. url: getDataURL( image )
  9771. };
  9772. }
  9773. output.image = image.uuid;
  9774. }
  9775. meta.textures[ this.uuid ] = output;
  9776. return output;
  9777. },
  9778. dispose: function () {
  9779. this.dispatchEvent( { type: 'dispose' } );
  9780. }
  9781. };
  9782. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  9783. THREE.TextureIdCount = 0;
  9784. // File:src/textures/CubeTexture.js
  9785. /**
  9786. * @author mrdoob / http://mrdoob.com/
  9787. */
  9788. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9789. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  9790. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9791. this.images = images;
  9792. this.flipY = false;
  9793. };
  9794. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  9795. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  9796. THREE.CubeTexture.clone = function () {
  9797. var texture = new THREE.CubeTexture();
  9798. texture.copy( this );
  9799. texture.images = this.images;
  9800. return texture;
  9801. };
  9802. // File:src/textures/CompressedTexture.js
  9803. /**
  9804. * @author alteredq / http://alteredqualia.com/
  9805. */
  9806. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9807. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9808. this.image = { width: width, height: height };
  9809. this.mipmaps = mipmaps;
  9810. // no flipping for cube textures
  9811. // (also flipping doesn't work for compressed textures )
  9812. this.flipY = false;
  9813. // can't generate mipmaps for compressed textures
  9814. // mips must be embedded in DDS files
  9815. this.generateMipmaps = false;
  9816. };
  9817. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  9818. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  9819. THREE.CompressedTexture.prototype.clone = function () {
  9820. var texture = new THREE.CompressedTexture();
  9821. texture.copy( this );
  9822. return texture;
  9823. };
  9824. // File:src/textures/DataTexture.js
  9825. /**
  9826. * @author alteredq / http://alteredqualia.com/
  9827. */
  9828. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9829. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9830. this.image = { data: data, width: width, height: height };
  9831. };
  9832. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  9833. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  9834. THREE.DataTexture.prototype.clone = function () {
  9835. var texture = new THREE.DataTexture();
  9836. texture.copy( this );
  9837. return texture;
  9838. };
  9839. // File:src/textures/VideoTexture.js
  9840. /**
  9841. * @author mrdoob / http://mrdoob.com/
  9842. */
  9843. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9844. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9845. this.generateMipmaps = false;
  9846. var scope = this;
  9847. var update = function () {
  9848. requestAnimationFrame( update );
  9849. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  9850. scope.needsUpdate = true;
  9851. }
  9852. };
  9853. update();
  9854. };
  9855. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  9856. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  9857. // File:src/objects/Group.js
  9858. /**
  9859. * @author mrdoob / http://mrdoob.com/
  9860. */
  9861. THREE.Group = function () {
  9862. THREE.Object3D.call( this );
  9863. this.type = 'Group';
  9864. };
  9865. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  9866. THREE.Group.prototype.constructor = THREE.Group;
  9867. THREE.Group.prototype.clone = function () {
  9868. var group = new THREE.Group();
  9869. return group.copy( this );
  9870. };
  9871. THREE.Group.prototype.copy = function ( source ) {
  9872. THREE.Object3D.prototype.copy.call( this, source );
  9873. return this;
  9874. };
  9875. // File:src/objects/PointCloud.js
  9876. /**
  9877. * @author alteredq / http://alteredqualia.com/
  9878. */
  9879. THREE.PointCloud = function ( geometry, material ) {
  9880. THREE.Object3D.call( this );
  9881. this.type = 'PointCloud';
  9882. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9883. this.material = material !== undefined ? material : new THREE.PointCloudMaterial( { color: Math.random() * 0xffffff } );
  9884. };
  9885. THREE.PointCloud.prototype = Object.create( THREE.Object3D.prototype );
  9886. THREE.PointCloud.prototype.constructor = THREE.PointCloud;
  9887. THREE.PointCloud.prototype.raycast = ( function () {
  9888. var inverseMatrix = new THREE.Matrix4();
  9889. var ray = new THREE.Ray();
  9890. return function raycast( raycaster, intersects ) {
  9891. var object = this;
  9892. var geometry = object.geometry;
  9893. var threshold = raycaster.params.PointCloud.threshold;
  9894. inverseMatrix.getInverse( this.matrixWorld );
  9895. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9896. if ( geometry.boundingBox !== null ) {
  9897. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  9898. return;
  9899. }
  9900. }
  9901. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  9902. var localThresholdSq = localThreshold * localThreshold;
  9903. var position = new THREE.Vector3();
  9904. var testPoint = function ( point, index ) {
  9905. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  9906. if ( rayPointDistanceSq < localThresholdSq ) {
  9907. var intersectPoint = ray.closestPointToPoint( point );
  9908. intersectPoint.applyMatrix4( object.matrixWorld );
  9909. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  9910. if ( distance < raycaster.near || distance > raycaster.far ) return;
  9911. intersects.push( {
  9912. distance: distance,
  9913. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  9914. point: intersectPoint.clone(),
  9915. index: index,
  9916. face: null,
  9917. object: object
  9918. } );
  9919. }
  9920. };
  9921. if ( geometry instanceof THREE.BufferGeometry ) {
  9922. var attributes = geometry.attributes;
  9923. var positions = attributes.position.array;
  9924. if ( attributes.index !== undefined ) {
  9925. var indices = attributes.index.array;
  9926. var offsets = geometry.drawcalls;
  9927. if ( offsets.length === 0 ) {
  9928. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9929. }
  9930. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  9931. var offset = offsets[ oi ];
  9932. var start = offset.start;
  9933. var count = offset.count;
  9934. var index = offset.index;
  9935. for ( var i = start, il = start + count; i < il; i ++ ) {
  9936. var a = index + indices[ i ];
  9937. position.fromArray( positions, a * 3 );
  9938. testPoint( position, a );
  9939. }
  9940. }
  9941. } else {
  9942. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  9943. position.fromArray( positions, i * 3 );
  9944. testPoint( position, i );
  9945. }
  9946. }
  9947. } else {
  9948. var vertices = geometry.vertices;
  9949. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  9950. testPoint( vertices[ i ], i );
  9951. }
  9952. }
  9953. };
  9954. }() );
  9955. THREE.PointCloud.prototype.clone = function () {
  9956. var pointCloud = new THREE.PointCloud( this.geometry, this.material );
  9957. return pointCloud.copy( this );
  9958. };
  9959. THREE.PointCloud.prototype.copy = function ( source ) {
  9960. THREE.Object3D.prototype.copy.call( this, source );
  9961. return this;
  9962. };
  9963. THREE.PointCloud.prototype.toJSON = function ( meta ) {
  9964. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9965. // only serialize if not in meta geometries cache
  9966. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9967. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9968. }
  9969. // only serialize if not in meta materials cache
  9970. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9971. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9972. }
  9973. data.object.geometry = this.geometry.uuid;
  9974. data.object.material = this.material.uuid;
  9975. return data;
  9976. };
  9977. // Backwards compatibility
  9978. THREE.ParticleSystem = function ( geometry, material ) {
  9979. console.warn( 'THREE.ParticleSystem has been renamed to THREE.PointCloud.' );
  9980. return new THREE.PointCloud( geometry, material );
  9981. };
  9982. // File:src/objects/Line.js
  9983. /**
  9984. * @author mrdoob / http://mrdoob.com/
  9985. */
  9986. THREE.Line = function ( geometry, material, mode ) {
  9987. if ( mode === 1 ) {
  9988. console.error( 'THREE.Line: THREE.LinePieces mode has been removed. Use THREE.LineSegments instead.' );
  9989. }
  9990. THREE.Object3D.call( this );
  9991. this.type = 'Line';
  9992. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9993. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  9994. };
  9995. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  9996. THREE.Line.prototype.constructor = THREE.Line;
  9997. THREE.Line.prototype.raycast = ( function () {
  9998. var inverseMatrix = new THREE.Matrix4();
  9999. var ray = new THREE.Ray();
  10000. var sphere = new THREE.Sphere();
  10001. return function raycast( raycaster, intersects ) {
  10002. var precision = raycaster.linePrecision;
  10003. var precisionSq = precision * precision;
  10004. var geometry = this.geometry;
  10005. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10006. // Checking boundingSphere distance to ray
  10007. sphere.copy( geometry.boundingSphere );
  10008. sphere.applyMatrix4( this.matrixWorld );
  10009. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  10010. return;
  10011. }
  10012. inverseMatrix.getInverse( this.matrixWorld );
  10013. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  10014. var vStart = new THREE.Vector3();
  10015. var vEnd = new THREE.Vector3();
  10016. var interSegment = new THREE.Vector3();
  10017. var interRay = new THREE.Vector3();
  10018. var step = this instanceof THREE.LineSegments ? 2 : 1;
  10019. if ( geometry instanceof THREE.BufferGeometry ) {
  10020. var attributes = geometry.attributes;
  10021. if ( attributes.index !== undefined ) {
  10022. var indices = attributes.index.array;
  10023. var positions = attributes.position.array;
  10024. var offsets = geometry.drawcalls;
  10025. if ( offsets.length === 0 ) {
  10026. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  10027. }
  10028. for ( var oi = 0; oi < offsets.length; oi ++ ) {
  10029. var start = offsets[ oi ].start;
  10030. var count = offsets[ oi ].count;
  10031. var index = offsets[ oi ].index;
  10032. for ( var i = start; i < start + count - 1; i += step ) {
  10033. var a = index + indices[ i ];
  10034. var b = index + indices[ i + 1 ];
  10035. vStart.fromArray( positions, a * 3 );
  10036. vEnd.fromArray( positions, b * 3 );
  10037. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  10038. if ( distSq > precisionSq ) continue;
  10039. var distance = ray.origin.distanceTo( interRay );
  10040. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10041. intersects.push( {
  10042. distance: distance,
  10043. // What do we want? intersection point on the ray or on the segment??
  10044. // point: raycaster.ray.at( distance ),
  10045. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  10046. index: i,
  10047. offsetIndex: oi,
  10048. face: null,
  10049. faceIndex: null,
  10050. object: this
  10051. } );
  10052. }
  10053. }
  10054. } else {
  10055. var positions = attributes.position.array;
  10056. for ( var i = 0; i < positions.length / 3 - 1; i += step ) {
  10057. vStart.fromArray( positions, 3 * i );
  10058. vEnd.fromArray( positions, 3 * i + 3 );
  10059. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  10060. if ( distSq > precisionSq ) continue;
  10061. var distance = ray.origin.distanceTo( interRay );
  10062. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10063. intersects.push( {
  10064. distance: distance,
  10065. // What do we want? intersection point on the ray or on the segment??
  10066. // point: raycaster.ray.at( distance ),
  10067. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  10068. index: i,
  10069. face: null,
  10070. faceIndex: null,
  10071. object: this
  10072. } );
  10073. }
  10074. }
  10075. } else if ( geometry instanceof THREE.Geometry ) {
  10076. var vertices = geometry.vertices;
  10077. var nbVertices = vertices.length;
  10078. for ( var i = 0; i < nbVertices - 1; i += step ) {
  10079. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  10080. if ( distSq > precisionSq ) continue;
  10081. var distance = ray.origin.distanceTo( interRay );
  10082. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10083. intersects.push( {
  10084. distance: distance,
  10085. // What do we want? intersection point on the ray or on the segment??
  10086. // point: raycaster.ray.at( distance ),
  10087. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  10088. index: i,
  10089. face: null,
  10090. faceIndex: null,
  10091. object: this
  10092. } );
  10093. }
  10094. }
  10095. };
  10096. }() );
  10097. THREE.Line.prototype.clone = function () {
  10098. var line = new THREE.Line( this.geometry, this.material );
  10099. return line.copy( this );
  10100. };
  10101. THREE.Line.prototype.copy = function ( source ) {
  10102. THREE.Object3D.prototype.copy.call( this, source );
  10103. return this;
  10104. };
  10105. THREE.Line.prototype.toJSON = function ( meta ) {
  10106. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10107. // only serialize if not in meta geometries cache
  10108. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  10109. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  10110. }
  10111. // only serialize if not in meta materials cache
  10112. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10113. meta.materials[ this.material.uuid ] = this.material.toJSON();
  10114. }
  10115. data.object.geometry = this.geometry.uuid;
  10116. data.object.material = this.material.uuid;
  10117. return data;
  10118. };
  10119. // DEPRECATED
  10120. THREE.LineStrip = 0;
  10121. THREE.LinePieces = 1;
  10122. // File:src/objects/LineSegments.js
  10123. /**
  10124. * @author mrdoob / http://mrdoob.com/
  10125. */
  10126. THREE.LineSegments = function ( geometry, material ) {
  10127. THREE.Line.call( this, geometry, material );
  10128. this.type = 'LineSegments';
  10129. };
  10130. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  10131. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  10132. THREE.LineSegments.prototype.clone = function () {
  10133. var line = new THREE.LineSegments( this.geometry, this.material );
  10134. line.copy( this );
  10135. return line;
  10136. };
  10137. // File:src/objects/Mesh.js
  10138. /**
  10139. * @author mrdoob / http://mrdoob.com/
  10140. * @author alteredq / http://alteredqualia.com/
  10141. * @author mikael emtinger / http://gomo.se/
  10142. * @author jonobr1 / http://jonobr1.com/
  10143. */
  10144. THREE.Mesh = function ( geometry, material ) {
  10145. THREE.Object3D.call( this );
  10146. this.type = 'Mesh';
  10147. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  10148. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  10149. this.updateMorphTargets();
  10150. };
  10151. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  10152. THREE.Mesh.prototype.constructor = THREE.Mesh;
  10153. THREE.Mesh.prototype.updateMorphTargets = function () {
  10154. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  10155. this.morphTargetBase = - 1;
  10156. this.morphTargetForcedOrder = [];
  10157. this.morphTargetInfluences = [];
  10158. this.morphTargetDictionary = {};
  10159. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  10160. this.morphTargetInfluences.push( 0 );
  10161. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  10162. }
  10163. }
  10164. };
  10165. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  10166. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  10167. return this.morphTargetDictionary[ name ];
  10168. }
  10169. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  10170. return 0;
  10171. };
  10172. THREE.Mesh.prototype.raycast = ( function () {
  10173. var inverseMatrix = new THREE.Matrix4();
  10174. var ray = new THREE.Ray();
  10175. var sphere = new THREE.Sphere();
  10176. var vA = new THREE.Vector3();
  10177. var vB = new THREE.Vector3();
  10178. var vC = new THREE.Vector3();
  10179. var tempA = new THREE.Vector3();
  10180. var tempB = new THREE.Vector3();
  10181. var tempC = new THREE.Vector3();
  10182. return function raycast( raycaster, intersects ) {
  10183. var geometry = this.geometry;
  10184. var material = this.material;
  10185. if ( material === undefined ) return;
  10186. // Checking boundingSphere distance to ray
  10187. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10188. sphere.copy( geometry.boundingSphere );
  10189. sphere.applyMatrix4( this.matrixWorld );
  10190. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  10191. return;
  10192. }
  10193. // Check boundingBox before continuing
  10194. inverseMatrix.getInverse( this.matrixWorld );
  10195. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  10196. if ( geometry.boundingBox !== null ) {
  10197. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  10198. return;
  10199. }
  10200. }
  10201. var a, b, c;
  10202. if ( geometry instanceof THREE.BufferGeometry ) {
  10203. var attributes = geometry.attributes;
  10204. if ( attributes.index !== undefined ) {
  10205. var indices = attributes.index.array;
  10206. var positions = attributes.position.array;
  10207. var offsets = geometry.drawcalls;
  10208. if ( offsets.length === 0 ) {
  10209. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  10210. }
  10211. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  10212. var start = offsets[ oi ].start;
  10213. var count = offsets[ oi ].count;
  10214. var index = offsets[ oi ].index;
  10215. for ( var i = start, il = start + count; i < il; i += 3 ) {
  10216. a = index + indices[ i ];
  10217. b = index + indices[ i + 1 ];
  10218. c = index + indices[ i + 2 ];
  10219. vA.fromArray( positions, a * 3 );
  10220. vB.fromArray( positions, b * 3 );
  10221. vC.fromArray( positions, c * 3 );
  10222. if ( material.side === THREE.BackSide ) {
  10223. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  10224. } else {
  10225. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  10226. }
  10227. if ( intersectionPoint === null ) continue;
  10228. intersectionPoint.applyMatrix4( this.matrixWorld );
  10229. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10230. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10231. intersects.push( {
  10232. distance: distance,
  10233. point: intersectionPoint,
  10234. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  10235. faceIndex: Math.floor( i / 3 ), // triangle number in indices buffer semantics
  10236. object: this
  10237. } );
  10238. }
  10239. }
  10240. } else {
  10241. var positions = attributes.position.array;
  10242. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  10243. vA.fromArray( positions, i );
  10244. vB.fromArray( positions, i + 3 );
  10245. vC.fromArray( positions, i + 6 );
  10246. if ( material.side === THREE.BackSide ) {
  10247. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  10248. } else {
  10249. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  10250. }
  10251. if ( intersectionPoint === null ) continue;
  10252. intersectionPoint.applyMatrix4( this.matrixWorld );
  10253. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10254. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10255. a = i / 3;
  10256. b = a + 1;
  10257. c = a + 2;
  10258. intersects.push( {
  10259. distance: distance,
  10260. point: intersectionPoint,
  10261. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  10262. index: a, // triangle number in positions buffer semantics
  10263. object: this
  10264. } );
  10265. }
  10266. }
  10267. } else if ( geometry instanceof THREE.Geometry ) {
  10268. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  10269. var materials = isFaceMaterial === true ? material.materials : null;
  10270. var vertices = geometry.vertices;
  10271. var faces = geometry.faces;
  10272. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  10273. var face = faces[ f ];
  10274. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  10275. if ( faceMaterial === undefined ) continue;
  10276. a = vertices[ face.a ];
  10277. b = vertices[ face.b ];
  10278. c = vertices[ face.c ];
  10279. if ( faceMaterial.morphTargets === true ) {
  10280. var morphTargets = geometry.morphTargets;
  10281. var morphInfluences = this.morphTargetInfluences;
  10282. vA.set( 0, 0, 0 );
  10283. vB.set( 0, 0, 0 );
  10284. vC.set( 0, 0, 0 );
  10285. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  10286. var influence = morphInfluences[ t ];
  10287. if ( influence === 0 ) continue;
  10288. var targets = morphTargets[ t ].vertices;
  10289. vA.addScaledVector( tempA.subVectors( targets[ face.a ], a ), influence );
  10290. vB.addScaledVector( tempB.subVectors( targets[ face.b ], b ), influence );
  10291. vC.addScaledVector( tempC.subVectors( targets[ face.c ], c ), influence );
  10292. }
  10293. vA.add( a );
  10294. vB.add( b );
  10295. vC.add( c );
  10296. a = vA;
  10297. b = vB;
  10298. c = vC;
  10299. }
  10300. if ( faceMaterial.side === THREE.BackSide ) {
  10301. var intersectionPoint = ray.intersectTriangle( c, b, a, true );
  10302. } else {
  10303. var intersectionPoint = ray.intersectTriangle( a, b, c, faceMaterial.side !== THREE.DoubleSide );
  10304. }
  10305. if ( intersectionPoint === null ) continue;
  10306. intersectionPoint.applyMatrix4( this.matrixWorld );
  10307. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10308. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10309. intersects.push( {
  10310. distance: distance,
  10311. point: intersectionPoint,
  10312. face: face,
  10313. faceIndex: f,
  10314. object: this
  10315. } );
  10316. }
  10317. }
  10318. };
  10319. }() );
  10320. THREE.Mesh.prototype.clone = function () {
  10321. var mesh = new THREE.Mesh( this.geometry, this.material );
  10322. return mesh.copy( this );
  10323. };
  10324. THREE.Mesh.prototype.copy = function ( source ) {
  10325. THREE.Object3D.prototype.copy.call( this, source );
  10326. return this;
  10327. };
  10328. THREE.Mesh.prototype.toJSON = function ( meta ) {
  10329. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10330. // only serialize if not in meta geometries cache
  10331. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  10332. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  10333. }
  10334. // only serialize if not in meta materials cache
  10335. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10336. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  10337. }
  10338. data.object.geometry = this.geometry.uuid;
  10339. data.object.material = this.material.uuid;
  10340. return data;
  10341. };
  10342. // File:src/objects/Bone.js
  10343. /**
  10344. * @author mikael emtinger / http://gomo.se/
  10345. * @author alteredq / http://alteredqualia.com/
  10346. * @author ikerr / http://verold.com
  10347. */
  10348. THREE.Bone = function ( skin ) {
  10349. THREE.Object3D.call( this );
  10350. this.type = 'Bone';
  10351. this.skin = skin;
  10352. };
  10353. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  10354. THREE.Bone.prototype.constructor = THREE.Bone;
  10355. THREE.Bone.prototype.clone = function () {
  10356. var bone = new THREE.Bone( this.skin );
  10357. return bone.copy( this );
  10358. };
  10359. THREE.Bone.prototype.copy = function ( source ) {
  10360. THREE.Object3D.prototype.copy.call( this, source );
  10361. this.skin = source.skin;
  10362. return this;
  10363. };
  10364. // File:src/objects/Skeleton.js
  10365. /**
  10366. * @author mikael emtinger / http://gomo.se/
  10367. * @author alteredq / http://alteredqualia.com/
  10368. * @author michael guerrero / http://realitymeltdown.com
  10369. * @author ikerr / http://verold.com
  10370. */
  10371. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  10372. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  10373. this.identityMatrix = new THREE.Matrix4();
  10374. // copy the bone array
  10375. bones = bones || [];
  10376. this.bones = bones.slice( 0 );
  10377. // create a bone texture or an array of floats
  10378. if ( this.useVertexTexture ) {
  10379. // layout (1 matrix = 4 pixels)
  10380. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  10381. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  10382. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  10383. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  10384. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  10385. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  10386. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  10387. size = Math.max( size, 4 );
  10388. this.boneTextureWidth = size;
  10389. this.boneTextureHeight = size;
  10390. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  10391. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  10392. this.boneTexture.minFilter = THREE.NearestFilter;
  10393. this.boneTexture.magFilter = THREE.NearestFilter;
  10394. this.boneTexture.generateMipmaps = false;
  10395. this.boneTexture.flipY = false;
  10396. } else {
  10397. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  10398. }
  10399. // use the supplied bone inverses or calculate the inverses
  10400. if ( boneInverses === undefined ) {
  10401. this.calculateInverses();
  10402. } else {
  10403. if ( this.bones.length === boneInverses.length ) {
  10404. this.boneInverses = boneInverses.slice( 0 );
  10405. } else {
  10406. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  10407. this.boneInverses = [];
  10408. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10409. this.boneInverses.push( new THREE.Matrix4() );
  10410. }
  10411. }
  10412. }
  10413. };
  10414. THREE.Skeleton.prototype.calculateInverses = function () {
  10415. this.boneInverses = [];
  10416. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10417. var inverse = new THREE.Matrix4();
  10418. if ( this.bones[ b ] ) {
  10419. inverse.getInverse( this.bones[ b ].matrixWorld );
  10420. }
  10421. this.boneInverses.push( inverse );
  10422. }
  10423. };
  10424. THREE.Skeleton.prototype.pose = function () {
  10425. var bone;
  10426. // recover the bind-time world matrices
  10427. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10428. bone = this.bones[ b ];
  10429. if ( bone ) {
  10430. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  10431. }
  10432. }
  10433. // compute the local matrices, positions, rotations and scales
  10434. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10435. bone = this.bones[ b ];
  10436. if ( bone ) {
  10437. if ( bone.parent ) {
  10438. bone.matrix.getInverse( bone.parent.matrixWorld );
  10439. bone.matrix.multiply( bone.matrixWorld );
  10440. } else {
  10441. bone.matrix.copy( bone.matrixWorld );
  10442. }
  10443. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  10444. }
  10445. }
  10446. };
  10447. THREE.Skeleton.prototype.update = ( function () {
  10448. var offsetMatrix = new THREE.Matrix4();
  10449. return function update() {
  10450. // flatten bone matrices to array
  10451. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10452. // compute the offset between the current and the original transform
  10453. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  10454. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  10455. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  10456. }
  10457. if ( this.useVertexTexture ) {
  10458. this.boneTexture.needsUpdate = true;
  10459. }
  10460. };
  10461. } )();
  10462. THREE.Skeleton.prototype.clone = function () {
  10463. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  10464. };
  10465. // File:src/objects/SkinnedMesh.js
  10466. /**
  10467. * @author mikael emtinger / http://gomo.se/
  10468. * @author alteredq / http://alteredqualia.com/
  10469. * @author ikerr / http://verold.com
  10470. */
  10471. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  10472. THREE.Mesh.call( this, geometry, material );
  10473. this.type = 'SkinnedMesh';
  10474. this.bindMode = "attached";
  10475. this.bindMatrix = new THREE.Matrix4();
  10476. this.bindMatrixInverse = new THREE.Matrix4();
  10477. // init bones
  10478. // TODO: remove bone creation as there is no reason (other than
  10479. // convenience) for THREE.SkinnedMesh to do this.
  10480. var bones = [];
  10481. if ( this.geometry && this.geometry.bones !== undefined ) {
  10482. var bone, gbone;
  10483. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10484. gbone = this.geometry.bones[ b ];
  10485. bone = new THREE.Bone( this );
  10486. bones.push( bone );
  10487. bone.name = gbone.name;
  10488. bone.position.fromArray( gbone.pos );
  10489. bone.quaternion.fromArray( gbone.rotq );
  10490. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  10491. }
  10492. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10493. gbone = this.geometry.bones[ b ];
  10494. if ( gbone.parent !== - 1 ) {
  10495. bones[ gbone.parent ].add( bones[ b ] );
  10496. } else {
  10497. this.add( bones[ b ] );
  10498. }
  10499. }
  10500. }
  10501. this.normalizeSkinWeights();
  10502. this.updateMatrixWorld( true );
  10503. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  10504. };
  10505. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  10506. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  10507. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  10508. this.skeleton = skeleton;
  10509. if ( bindMatrix === undefined ) {
  10510. this.updateMatrixWorld( true );
  10511. this.skeleton.calculateInverses();
  10512. bindMatrix = this.matrixWorld;
  10513. }
  10514. this.bindMatrix.copy( bindMatrix );
  10515. this.bindMatrixInverse.getInverse( bindMatrix );
  10516. };
  10517. THREE.SkinnedMesh.prototype.pose = function () {
  10518. this.skeleton.pose();
  10519. };
  10520. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  10521. if ( this.geometry instanceof THREE.Geometry ) {
  10522. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  10523. var sw = this.geometry.skinWeights[ i ];
  10524. var scale = 1.0 / sw.lengthManhattan();
  10525. if ( scale !== Infinity ) {
  10526. sw.multiplyScalar( scale );
  10527. } else {
  10528. sw.set( 1 ); // this will be normalized by the shader anyway
  10529. }
  10530. }
  10531. } else {
  10532. // skinning weights assumed to be normalized for THREE.BufferGeometry
  10533. }
  10534. };
  10535. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  10536. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  10537. if ( this.bindMode === "attached" ) {
  10538. this.bindMatrixInverse.getInverse( this.matrixWorld );
  10539. } else if ( this.bindMode === "detached" ) {
  10540. this.bindMatrixInverse.getInverse( this.bindMatrix );
  10541. } else {
  10542. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  10543. }
  10544. };
  10545. THREE.SkinnedMesh.prototype.clone = function() {
  10546. var skinMesh = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
  10547. return skinMesh.copy( this );
  10548. };
  10549. THREE.SkinnedMesh.prototype.copy = function( source ) {
  10550. THREE.Mesh.prototype.copy.call( this, source );
  10551. return this;
  10552. };
  10553. // File:src/objects/MorphAnimMesh.js
  10554. /**
  10555. * @author alteredq / http://alteredqualia.com/
  10556. */
  10557. THREE.MorphAnimMesh = function ( geometry, material ) {
  10558. THREE.Mesh.call( this, geometry, material );
  10559. this.type = 'MorphAnimMesh';
  10560. // API
  10561. this.duration = 1000; // milliseconds
  10562. this.mirroredLoop = false;
  10563. this.time = 0;
  10564. // internals
  10565. this.lastKeyframe = 0;
  10566. this.currentKeyframe = 0;
  10567. this.direction = 1;
  10568. this.directionBackwards = false;
  10569. this.setFrameRange( 0, geometry.morphTargets.length - 1 );
  10570. };
  10571. THREE.MorphAnimMesh.prototype = Object.create( THREE.Mesh.prototype );
  10572. THREE.MorphAnimMesh.prototype.constructor = THREE.MorphAnimMesh;
  10573. THREE.MorphAnimMesh.prototype.setFrameRange = function ( start, end ) {
  10574. this.startKeyframe = start;
  10575. this.endKeyframe = end;
  10576. this.length = this.endKeyframe - this.startKeyframe + 1;
  10577. };
  10578. THREE.MorphAnimMesh.prototype.setDirectionForward = function () {
  10579. this.direction = 1;
  10580. this.directionBackwards = false;
  10581. };
  10582. THREE.MorphAnimMesh.prototype.setDirectionBackward = function () {
  10583. this.direction = - 1;
  10584. this.directionBackwards = true;
  10585. };
  10586. THREE.MorphAnimMesh.prototype.parseAnimations = function () {
  10587. var geometry = this.geometry;
  10588. if ( ! geometry.animations ) geometry.animations = {};
  10589. var firstAnimation, animations = geometry.animations;
  10590. var pattern = /([a-z]+)_?(\d+)/;
  10591. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  10592. var morph = geometry.morphTargets[ i ];
  10593. var parts = morph.name.match( pattern );
  10594. if ( parts && parts.length > 1 ) {
  10595. var label = parts[ 1 ];
  10596. if ( ! animations[ label ] ) animations[ label ] = { start: Infinity, end: - Infinity };
  10597. var animation = animations[ label ];
  10598. if ( i < animation.start ) animation.start = i;
  10599. if ( i > animation.end ) animation.end = i;
  10600. if ( ! firstAnimation ) firstAnimation = label;
  10601. }
  10602. }
  10603. geometry.firstAnimation = firstAnimation;
  10604. };
  10605. THREE.MorphAnimMesh.prototype.setAnimationLabel = function ( label, start, end ) {
  10606. if ( ! this.geometry.animations ) this.geometry.animations = {};
  10607. this.geometry.animations[ label ] = { start: start, end: end };
  10608. };
  10609. THREE.MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {
  10610. var animation = this.geometry.animations[ label ];
  10611. if ( animation ) {
  10612. this.setFrameRange( animation.start, animation.end );
  10613. this.duration = 1000 * ( ( animation.end - animation.start ) / fps );
  10614. this.time = 0;
  10615. } else {
  10616. console.warn( 'THREE.MorphAnimMesh: animation[' + label + '] undefined in .playAnimation()' );
  10617. }
  10618. };
  10619. THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
  10620. var frameTime = this.duration / this.length;
  10621. this.time += this.direction * delta;
  10622. if ( this.mirroredLoop ) {
  10623. if ( this.time > this.duration || this.time < 0 ) {
  10624. this.direction *= - 1;
  10625. if ( this.time > this.duration ) {
  10626. this.time = this.duration;
  10627. this.directionBackwards = true;
  10628. }
  10629. if ( this.time < 0 ) {
  10630. this.time = 0;
  10631. this.directionBackwards = false;
  10632. }
  10633. }
  10634. } else {
  10635. this.time = this.time % this.duration;
  10636. if ( this.time < 0 ) this.time += this.duration;
  10637. }
  10638. var keyframe = this.startKeyframe + THREE.Math.clamp( Math.floor( this.time / frameTime ), 0, this.length - 1 );
  10639. var influences = this.morphTargetInfluences;
  10640. if ( keyframe !== this.currentKeyframe ) {
  10641. influences[ this.lastKeyframe ] = 0;
  10642. influences[ this.currentKeyframe ] = 1;
  10643. influences[ keyframe ] = 0;
  10644. this.lastKeyframe = this.currentKeyframe;
  10645. this.currentKeyframe = keyframe;
  10646. }
  10647. var mix = ( this.time % frameTime ) / frameTime;
  10648. if ( this.directionBackwards ) {
  10649. mix = 1 - mix;
  10650. }
  10651. influences[ this.currentKeyframe ] = mix;
  10652. influences[ this.lastKeyframe ] = 1 - mix;
  10653. };
  10654. THREE.MorphAnimMesh.prototype.interpolateTargets = function ( a, b, t ) {
  10655. var influences = this.morphTargetInfluences;
  10656. for ( var i = 0, l = influences.length; i < l; i ++ ) {
  10657. influences[ i ] = 0;
  10658. }
  10659. if ( a > - 1 ) influences[ a ] = 1 - t;
  10660. if ( b > - 1 ) influences[ b ] = t;
  10661. };
  10662. THREE.MorphAnimMesh.prototype.clone = function () {
  10663. var morph = new THREE.MorphAnimMesh( this.geometry, this.material );
  10664. return morph.copy( this );
  10665. };
  10666. THREE.MorphAnimMesh.prototype.copy = function ( source ) {
  10667. this.duration = source.duration;
  10668. this.mirroredLoop = source.mirroredLoop;
  10669. this.time = source.time;
  10670. this.lastKeyframe = source.lastKeyframe;
  10671. this.currentKeyframe = source.currentKeyframe;
  10672. this.direction = source.direction;
  10673. this.directionBackwards = source.directionBackwards;
  10674. THREE.Mesh.prototype.copy.call( this, source );
  10675. return this;
  10676. };
  10677. // File:src/objects/LOD.js
  10678. /**
  10679. * @author mikael emtinger / http://gomo.se/
  10680. * @author alteredq / http://alteredqualia.com/
  10681. * @author mrdoob / http://mrdoob.com/
  10682. */
  10683. THREE.LOD = function () {
  10684. THREE.Object3D.call( this );
  10685. Object.defineProperties( this, {
  10686. levels: {
  10687. enumerable: true,
  10688. value: []
  10689. },
  10690. objects: {
  10691. get: function () {
  10692. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  10693. return this.levels;
  10694. }
  10695. }
  10696. } );
  10697. };
  10698. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  10699. THREE.LOD.prototype.constructor = THREE.LOD;
  10700. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  10701. if ( distance === undefined ) distance = 0;
  10702. distance = Math.abs( distance );
  10703. var levels = this.levels;
  10704. for ( var l = 0; l < levels.length; l ++ ) {
  10705. if ( distance < levels[ l ].distance ) {
  10706. break;
  10707. }
  10708. }
  10709. levels.splice( l, 0, { distance: distance, object: object } );
  10710. this.add( object );
  10711. };
  10712. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  10713. var levels = this.levels;
  10714. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10715. if ( distance < levels[ i ].distance ) {
  10716. break;
  10717. }
  10718. }
  10719. return levels[ i - 1 ].object;
  10720. };
  10721. THREE.LOD.prototype.raycast = ( function () {
  10722. var matrixPosition = new THREE.Vector3();
  10723. return function raycast( raycaster, intersects ) {
  10724. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10725. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  10726. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  10727. };
  10728. }() );
  10729. THREE.LOD.prototype.update = function () {
  10730. var v1 = new THREE.Vector3();
  10731. var v2 = new THREE.Vector3();
  10732. return function update( camera ) {
  10733. var levels = this.levels;
  10734. if ( levels.length > 1 ) {
  10735. v1.setFromMatrixPosition( camera.matrixWorld );
  10736. v2.setFromMatrixPosition( this.matrixWorld );
  10737. var distance = v1.distanceTo( v2 );
  10738. levels[ 0 ].object.visible = true;
  10739. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10740. if ( distance >= levels[ i ].distance ) {
  10741. levels[ i - 1 ].object.visible = false;
  10742. levels[ i ].object.visible = true;
  10743. } else {
  10744. break;
  10745. }
  10746. }
  10747. for ( ; i < l; i ++ ) {
  10748. levels[ i ].object.visible = false;
  10749. }
  10750. }
  10751. };
  10752. }();
  10753. THREE.LOD.prototype.clone = function () {
  10754. var lod = new THREE.LOD();
  10755. return lod.copy( this );
  10756. };
  10757. THREE.LOD.prototype.copy = function ( source ) {
  10758. THREE.Object3D.prototype.copy.call( this, source, false );
  10759. var levels = source.levels;
  10760. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  10761. var level = levels[ i ];
  10762. this.addLevel( level.object.clone(), level.distance );
  10763. }
  10764. return this;
  10765. };
  10766. // File:src/objects/Sprite.js
  10767. /**
  10768. * @author mikael emtinger / http://gomo.se/
  10769. * @author alteredq / http://alteredqualia.com/
  10770. */
  10771. THREE.Sprite = ( function () {
  10772. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  10773. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  10774. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  10775. var geometry = new THREE.BufferGeometry();
  10776. geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  10777. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  10778. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  10779. return function Sprite( material ) {
  10780. THREE.Object3D.call( this );
  10781. this.type = 'Sprite';
  10782. this.geometry = geometry;
  10783. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  10784. };
  10785. } )();
  10786. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  10787. THREE.Sprite.prototype.constructor = THREE.Sprite;
  10788. THREE.Sprite.prototype.raycast = ( function () {
  10789. var matrixPosition = new THREE.Vector3();
  10790. return function raycast( raycaster, intersects ) {
  10791. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10792. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  10793. var guessSizeSq = this.scale.x * this.scale.y;
  10794. if ( distanceSq > guessSizeSq ) {
  10795. return;
  10796. }
  10797. intersects.push( {
  10798. distance: Math.sqrt( distanceSq ),
  10799. point: this.position,
  10800. face: null,
  10801. object: this
  10802. } );
  10803. };
  10804. }() );
  10805. THREE.Sprite.prototype.clone = function () {
  10806. var sprite = new THREE.Sprite( this.material );
  10807. return sprite.copy( this );
  10808. };
  10809. THREE.Sprite.prototype.copy = function ( source ) {
  10810. THREE.Object3D.prototype.copy.call( this, source );
  10811. return this;
  10812. };
  10813. THREE.Sprite.prototype.toJSON = function ( meta ) {
  10814. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10815. // only serialize if not in meta materials cache
  10816. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10817. meta.materials[ this.material.uuid ] = this.material.toJSON();
  10818. }
  10819. data.object.material = this.material.uuid;
  10820. return data;
  10821. };
  10822. // Backwards compatibility
  10823. THREE.Particle = THREE.Sprite;
  10824. // File:src/objects/LensFlare.js
  10825. /**
  10826. * @author mikael emtinger / http://gomo.se/
  10827. * @author alteredq / http://alteredqualia.com/
  10828. */
  10829. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  10830. THREE.Object3D.call( this );
  10831. this.lensFlares = [];
  10832. this.positionScreen = new THREE.Vector3();
  10833. this.customUpdateCallback = undefined;
  10834. if ( texture !== undefined ) {
  10835. this.add( texture, size, distance, blending, color );
  10836. }
  10837. };
  10838. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  10839. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  10840. /*
  10841. * Add: adds another flare
  10842. */
  10843. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  10844. if ( size === undefined ) size = - 1;
  10845. if ( distance === undefined ) distance = 0;
  10846. if ( opacity === undefined ) opacity = 1;
  10847. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  10848. if ( blending === undefined ) blending = THREE.NormalBlending;
  10849. distance = Math.min( distance, Math.max( 0, distance ) );
  10850. this.lensFlares.push( {
  10851. texture: texture, // THREE.Texture
  10852. size: size, // size in pixels (-1 = use texture.width)
  10853. distance: distance, // distance (0-1) from light source (0=at light source)
  10854. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  10855. scale: 1, // scale
  10856. rotation: 0, // rotation
  10857. opacity: opacity, // opacity
  10858. color: color, // color
  10859. blending: blending // blending
  10860. } );
  10861. };
  10862. /*
  10863. * Update lens flares update positions on all flares based on the screen position
  10864. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  10865. */
  10866. THREE.LensFlare.prototype.updateLensFlares = function () {
  10867. var f, fl = this.lensFlares.length;
  10868. var flare;
  10869. var vecX = - this.positionScreen.x * 2;
  10870. var vecY = - this.positionScreen.y * 2;
  10871. for ( f = 0; f < fl; f ++ ) {
  10872. flare = this.lensFlares[ f ];
  10873. flare.x = this.positionScreen.x + vecX * flare.distance;
  10874. flare.y = this.positionScreen.y + vecY * flare.distance;
  10875. flare.wantedRotation = flare.x * Math.PI * 0.25;
  10876. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  10877. }
  10878. };
  10879. THREE.LensFlare.prototype.clone = function () {
  10880. var flare = new THREE.LensFlare();
  10881. return flare.copy( this );
  10882. };
  10883. THREE.LensFlare.prototype.copy = function ( source ) {
  10884. THREE.Object3D.prototype.copy.call( this, source );
  10885. this.positionScreen.copy( source.positionScreen );
  10886. this.customUpdateCallback = source.customUpdateCallback;
  10887. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  10888. this.lensFlares.push( source.lensFlares[ i ] );
  10889. }
  10890. return this;
  10891. };
  10892. // File:src/scenes/Scene.js
  10893. /**
  10894. * @author mrdoob / http://mrdoob.com/
  10895. */
  10896. THREE.Scene = function () {
  10897. THREE.Object3D.call( this );
  10898. this.type = 'Scene';
  10899. this.fog = null;
  10900. this.overrideMaterial = null;
  10901. this.autoUpdate = true; // checked by the renderer
  10902. };
  10903. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  10904. THREE.Scene.prototype.constructor = THREE.Scene;
  10905. THREE.Scene.prototype.clone = function () {
  10906. var scene = new THREE.Scene();
  10907. return scene.copy( this );
  10908. };
  10909. THREE.Scene.prototype.copy = function ( source ) {
  10910. THREE.Object3D.prototype.copy.call( this, source );
  10911. if ( source.fog !== null ) this.fog = source.fog.clone();
  10912. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  10913. this.autoUpdate = source.autoUpdate;
  10914. this.matrixAutoUpdate = source.matrixAutoUpdate;
  10915. return this;
  10916. };
  10917. // File:src/scenes/Fog.js
  10918. /**
  10919. * @author mrdoob / http://mrdoob.com/
  10920. * @author alteredq / http://alteredqualia.com/
  10921. */
  10922. THREE.Fog = function ( color, near, far ) {
  10923. this.name = '';
  10924. this.color = new THREE.Color( color );
  10925. this.near = ( near !== undefined ) ? near : 1;
  10926. this.far = ( far !== undefined ) ? far : 1000;
  10927. };
  10928. THREE.Fog.prototype.clone = function () {
  10929. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  10930. };
  10931. // File:src/scenes/FogExp2.js
  10932. /**
  10933. * @author mrdoob / http://mrdoob.com/
  10934. * @author alteredq / http://alteredqualia.com/
  10935. */
  10936. THREE.FogExp2 = function ( color, density ) {
  10937. this.name = '';
  10938. this.color = new THREE.Color( color );
  10939. this.density = ( density !== undefined ) ? density : 0.00025;
  10940. };
  10941. THREE.FogExp2.prototype.clone = function () {
  10942. return new THREE.FogExp2( this.color.getHex(), this.density );
  10943. };
  10944. // File:src/renderers/shaders/ShaderChunk.js
  10945. THREE.ShaderChunk = {};
  10946. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  10947. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  10948. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  10949. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  10950. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  10951. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  10952. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  10953. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  10954. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  10955. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  10956. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  10957. 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";
  10958. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  10959. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  10960. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  10961. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  10962. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  10963. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  10964. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  10965. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = color.xyz;\n\n#endif";
  10966. // File:src/renderers/shaders/ShaderChunk/common.glsl
  10967. 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";
  10968. // File:src/renderers/shaders/ShaderChunk/default_vertex.glsl
  10969. 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";
  10970. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  10971. 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";
  10972. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  10973. 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";
  10974. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  10975. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n";
  10976. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  10977. 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";
  10978. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  10979. 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";
  10980. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  10981. 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";
  10982. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  10983. 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";
  10984. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  10985. 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";
  10986. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  10987. 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";
  10988. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  10989. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  10990. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  10991. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  10992. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  10993. 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";
  10994. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  10995. 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";
  10996. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  10997. 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";
  10998. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  10999. 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";
  11000. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  11001. 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";
  11002. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  11003. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif";
  11004. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  11005. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  11006. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  11007. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  11008. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  11009. THREE.ShaderChunk[ 'logdepthbuf_pars_fragment'] = "#ifdef USE_LOGDEPTHBUF\n\n uniform float logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n varying float vFragDepth;\n\n #endif\n\n#endif\n";
  11010. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  11011. 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";
  11012. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  11013. 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";
  11014. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  11015. 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";
  11016. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  11017. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  11018. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  11019. 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";
  11020. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  11021. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  11022. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  11023. 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";
  11024. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  11025. 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";
  11026. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  11027. 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";
  11028. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  11029. 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";
  11030. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  11031. 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";
  11032. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  11033. 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";
  11034. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  11035. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n\n#endif";
  11036. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  11037. 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";
  11038. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  11039. 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";
  11040. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  11041. 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";
  11042. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  11043. 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";
  11044. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  11045. 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";
  11046. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  11047. 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";
  11048. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  11049. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  11050. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  11051. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  11052. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  11053. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  11054. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  11055. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  11056. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  11057. 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";
  11058. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  11059. 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";
  11060. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  11061. 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";
  11062. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  11063. 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";
  11064. // File:src/renderers/shaders/UniformsUtils.js
  11065. /**
  11066. * Uniform Utilities
  11067. */
  11068. THREE.UniformsUtils = {
  11069. merge: function ( uniforms ) {
  11070. var merged = {};
  11071. for ( var u = 0; u < uniforms.length; u ++ ) {
  11072. var tmp = this.clone( uniforms[ u ] );
  11073. for ( var p in tmp ) {
  11074. merged[ p ] = tmp[ p ];
  11075. }
  11076. }
  11077. return merged;
  11078. },
  11079. clone: function ( uniforms_src ) {
  11080. var uniforms_dst = {};
  11081. for ( var u in uniforms_src ) {
  11082. uniforms_dst[ u ] = {};
  11083. for ( var p in uniforms_src[ u ] ) {
  11084. var parameter_src = uniforms_src[ u ][ p ];
  11085. if ( parameter_src instanceof THREE.Color ||
  11086. parameter_src instanceof THREE.Vector2 ||
  11087. parameter_src instanceof THREE.Vector3 ||
  11088. parameter_src instanceof THREE.Vector4 ||
  11089. parameter_src instanceof THREE.Matrix3 ||
  11090. parameter_src instanceof THREE.Matrix4 ||
  11091. parameter_src instanceof THREE.Texture ) {
  11092. uniforms_dst[ u ][ p ] = parameter_src.clone();
  11093. } else if ( Array.isArray( parameter_src ) ) {
  11094. uniforms_dst[ u ][ p ] = parameter_src.slice();
  11095. } else {
  11096. uniforms_dst[ u ][ p ] = parameter_src;
  11097. }
  11098. }
  11099. }
  11100. return uniforms_dst;
  11101. }
  11102. };
  11103. // File:src/renderers/shaders/UniformsLib.js
  11104. /**
  11105. * Uniforms library for shared webgl shaders
  11106. */
  11107. THREE.UniformsLib = {
  11108. common: {
  11109. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  11110. "opacity" : { type: "f", value: 1.0 },
  11111. "map" : { type: "t", value: null },
  11112. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  11113. "specularMap" : { type: "t", value: null },
  11114. "alphaMap" : { type: "t", value: null },
  11115. "envMap" : { type: "t", value: null },
  11116. "flipEnvMap" : { type: "f", value: - 1 },
  11117. "reflectivity" : { type: "f", value: 1.0 },
  11118. "refractionRatio" : { type: "f", value: 0.98 }
  11119. },
  11120. aomap: {
  11121. "aoMap" : { type: "t", value: null },
  11122. "aoMapIntensity" : { type: "f", value: 1 },
  11123. },
  11124. lightmap: {
  11125. "lightMap" : { type: "t", value: null },
  11126. "lightMapIntensity" : { type: "f", value: 1 },
  11127. },
  11128. emissivemap: {
  11129. "emissiveMap" : { type: "t", value: null },
  11130. },
  11131. bump: {
  11132. "bumpMap" : { type: "t", value: null },
  11133. "bumpScale" : { type: "f", value: 1 }
  11134. },
  11135. normalmap: {
  11136. "normalMap" : { type: "t", value: null },
  11137. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  11138. },
  11139. fog : {
  11140. "fogDensity" : { type: "f", value: 0.00025 },
  11141. "fogNear" : { type: "f", value: 1 },
  11142. "fogFar" : { type: "f", value: 2000 },
  11143. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  11144. },
  11145. lights: {
  11146. "ambientLightColor" : { type: "fv", value: [] },
  11147. "directionalLightDirection" : { type: "fv", value: [] },
  11148. "directionalLightColor" : { type: "fv", value: [] },
  11149. "hemisphereLightDirection" : { type: "fv", value: [] },
  11150. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  11151. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  11152. "pointLightColor" : { type: "fv", value: [] },
  11153. "pointLightPosition" : { type: "fv", value: [] },
  11154. "pointLightDistance" : { type: "fv1", value: [] },
  11155. "pointLightDecay" : { type: "fv1", value: [] },
  11156. "spotLightColor" : { type: "fv", value: [] },
  11157. "spotLightPosition" : { type: "fv", value: [] },
  11158. "spotLightDirection" : { type: "fv", value: [] },
  11159. "spotLightDistance" : { type: "fv1", value: [] },
  11160. "spotLightAngleCos" : { type: "fv1", value: [] },
  11161. "spotLightExponent" : { type: "fv1", value: [] },
  11162. "spotLightDecay" : { type: "fv1", value: [] }
  11163. },
  11164. particle: {
  11165. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  11166. "opacity" : { type: "f", value: 1.0 },
  11167. "size" : { type: "f", value: 1.0 },
  11168. "scale" : { type: "f", value: 1.0 },
  11169. "map" : { type: "t", value: null },
  11170. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  11171. "fogDensity" : { type: "f", value: 0.00025 },
  11172. "fogNear" : { type: "f", value: 1 },
  11173. "fogFar" : { type: "f", value: 2000 },
  11174. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  11175. },
  11176. shadowmap: {
  11177. "shadowMap": { type: "tv", value: [] },
  11178. "shadowMapSize": { type: "v2v", value: [] },
  11179. "shadowBias" : { type: "fv1", value: [] },
  11180. "shadowDarkness": { type: "fv1", value: [] },
  11181. "shadowMatrix" : { type: "m4v", value: [] }
  11182. }
  11183. };
  11184. // File:src/renderers/shaders/ShaderLib.js
  11185. /**
  11186. * Webgl Shader Library for three.js
  11187. *
  11188. * @author alteredq / http://alteredqualia.com/
  11189. * @author mrdoob / http://mrdoob.com/
  11190. * @author mikael emtinger / http://gomo.se/
  11191. */
  11192. THREE.ShaderLib = {
  11193. 'basic': {
  11194. uniforms: THREE.UniformsUtils.merge( [
  11195. THREE.UniformsLib[ "common" ],
  11196. THREE.UniformsLib[ "aomap" ],
  11197. THREE.UniformsLib[ "fog" ],
  11198. THREE.UniformsLib[ "shadowmap" ]
  11199. ] ),
  11200. vertexShader: [
  11201. THREE.ShaderChunk[ "common" ],
  11202. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11203. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11204. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11205. THREE.ShaderChunk[ "color_pars_vertex" ],
  11206. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11207. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11208. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11209. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11210. "void main() {",
  11211. THREE.ShaderChunk[ "uv_vertex" ],
  11212. THREE.ShaderChunk[ "uv2_vertex" ],
  11213. THREE.ShaderChunk[ "color_vertex" ],
  11214. THREE.ShaderChunk[ "skinbase_vertex" ],
  11215. " #ifdef USE_ENVMAP",
  11216. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11217. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11218. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11219. " #endif",
  11220. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11221. THREE.ShaderChunk[ "skinning_vertex" ],
  11222. THREE.ShaderChunk[ "default_vertex" ],
  11223. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11224. THREE.ShaderChunk[ "worldpos_vertex" ],
  11225. THREE.ShaderChunk[ "envmap_vertex" ],
  11226. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11227. "}"
  11228. ].join( "\n" ),
  11229. fragmentShader: [
  11230. "uniform vec3 diffuse;",
  11231. "uniform float opacity;",
  11232. THREE.ShaderChunk[ "common" ],
  11233. THREE.ShaderChunk[ "color_pars_fragment" ],
  11234. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11235. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11236. THREE.ShaderChunk[ "map_pars_fragment" ],
  11237. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11238. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  11239. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11240. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11241. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11242. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11243. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11244. "void main() {",
  11245. " vec3 outgoingLight = vec3( 0.0 );",
  11246. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11247. " vec3 totalAmbientLight = vec3( 1.0 );", // hardwired
  11248. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11249. THREE.ShaderChunk[ "map_fragment" ],
  11250. THREE.ShaderChunk[ "color_fragment" ],
  11251. THREE.ShaderChunk[ "alphamap_fragment" ],
  11252. THREE.ShaderChunk[ "alphatest_fragment" ],
  11253. THREE.ShaderChunk[ "specularmap_fragment" ],
  11254. THREE.ShaderChunk[ "aomap_fragment" ],
  11255. " outgoingLight = diffuseColor.rgb * totalAmbientLight;", // simple shader
  11256. THREE.ShaderChunk[ "envmap_fragment" ],
  11257. THREE.ShaderChunk[ "shadowmap_fragment" ], // TODO: Shadows on an otherwise unlit surface doesn't make sense.
  11258. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11259. THREE.ShaderChunk[ "fog_fragment" ],
  11260. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11261. "}"
  11262. ].join( "\n" )
  11263. },
  11264. 'lambert': {
  11265. uniforms: THREE.UniformsUtils.merge( [
  11266. THREE.UniformsLib[ "common" ],
  11267. THREE.UniformsLib[ "fog" ],
  11268. THREE.UniformsLib[ "lights" ],
  11269. THREE.UniformsLib[ "shadowmap" ],
  11270. {
  11271. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  11272. }
  11273. ] ),
  11274. vertexShader: [
  11275. "#define LAMBERT",
  11276. "varying vec3 vLightFront;",
  11277. "#ifdef DOUBLE_SIDED",
  11278. " varying vec3 vLightBack;",
  11279. "#endif",
  11280. THREE.ShaderChunk[ "common" ],
  11281. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11282. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11283. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11284. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  11285. THREE.ShaderChunk[ "color_pars_vertex" ],
  11286. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11287. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11288. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11289. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11290. "void main() {",
  11291. THREE.ShaderChunk[ "uv_vertex" ],
  11292. THREE.ShaderChunk[ "uv2_vertex" ],
  11293. THREE.ShaderChunk[ "color_vertex" ],
  11294. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11295. THREE.ShaderChunk[ "skinbase_vertex" ],
  11296. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11297. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11298. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11299. THREE.ShaderChunk[ "skinning_vertex" ],
  11300. THREE.ShaderChunk[ "default_vertex" ],
  11301. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11302. THREE.ShaderChunk[ "worldpos_vertex" ],
  11303. THREE.ShaderChunk[ "envmap_vertex" ],
  11304. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  11305. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11306. "}"
  11307. ].join( "\n" ),
  11308. fragmentShader: [
  11309. "uniform vec3 diffuse;",
  11310. "uniform vec3 emissive;",
  11311. "uniform float opacity;",
  11312. "varying vec3 vLightFront;",
  11313. "#ifdef DOUBLE_SIDED",
  11314. " varying vec3 vLightBack;",
  11315. "#endif",
  11316. THREE.ShaderChunk[ "common" ],
  11317. THREE.ShaderChunk[ "color_pars_fragment" ],
  11318. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11319. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11320. THREE.ShaderChunk[ "map_pars_fragment" ],
  11321. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11322. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11323. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11324. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11325. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11326. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11327. "void main() {",
  11328. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  11329. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11330. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11331. THREE.ShaderChunk[ "map_fragment" ],
  11332. THREE.ShaderChunk[ "color_fragment" ],
  11333. THREE.ShaderChunk[ "alphamap_fragment" ],
  11334. THREE.ShaderChunk[ "alphatest_fragment" ],
  11335. THREE.ShaderChunk[ "specularmap_fragment" ],
  11336. " #ifdef DOUBLE_SIDED",
  11337. " if ( gl_FrontFacing )",
  11338. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11339. " else",
  11340. " outgoingLight += diffuseColor.rgb * vLightBack + emissive;",
  11341. " #else",
  11342. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11343. " #endif",
  11344. THREE.ShaderChunk[ "envmap_fragment" ],
  11345. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11346. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11347. THREE.ShaderChunk[ "fog_fragment" ],
  11348. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11349. "}"
  11350. ].join( "\n" )
  11351. },
  11352. 'phong': {
  11353. uniforms: THREE.UniformsUtils.merge( [
  11354. THREE.UniformsLib[ "common" ],
  11355. THREE.UniformsLib[ "aomap" ],
  11356. THREE.UniformsLib[ "lightmap" ],
  11357. THREE.UniformsLib[ "emissivemap" ],
  11358. THREE.UniformsLib[ "bump" ],
  11359. THREE.UniformsLib[ "normalmap" ],
  11360. THREE.UniformsLib[ "fog" ],
  11361. THREE.UniformsLib[ "lights" ],
  11362. THREE.UniformsLib[ "shadowmap" ],
  11363. {
  11364. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  11365. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  11366. "shininess": { type: "f", value: 30 }
  11367. }
  11368. ] ),
  11369. vertexShader: [
  11370. "#define PHONG",
  11371. "varying vec3 vViewPosition;",
  11372. "#ifndef FLAT_SHADED",
  11373. " varying vec3 vNormal;",
  11374. "#endif",
  11375. THREE.ShaderChunk[ "common" ],
  11376. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11377. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11378. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11379. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  11380. THREE.ShaderChunk[ "color_pars_vertex" ],
  11381. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11382. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11383. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11384. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11385. "void main() {",
  11386. THREE.ShaderChunk[ "uv_vertex" ],
  11387. THREE.ShaderChunk[ "uv2_vertex" ],
  11388. THREE.ShaderChunk[ "color_vertex" ],
  11389. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11390. THREE.ShaderChunk[ "skinbase_vertex" ],
  11391. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11392. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11393. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  11394. " vNormal = normalize( transformedNormal );",
  11395. "#endif",
  11396. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11397. THREE.ShaderChunk[ "skinning_vertex" ],
  11398. THREE.ShaderChunk[ "default_vertex" ],
  11399. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11400. " vViewPosition = - mvPosition.xyz;",
  11401. THREE.ShaderChunk[ "worldpos_vertex" ],
  11402. THREE.ShaderChunk[ "envmap_vertex" ],
  11403. THREE.ShaderChunk[ "lights_phong_vertex" ],
  11404. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11405. "}"
  11406. ].join( "\n" ),
  11407. fragmentShader: [
  11408. "#define PHONG",
  11409. "uniform vec3 diffuse;",
  11410. "uniform vec3 emissive;",
  11411. "uniform vec3 specular;",
  11412. "uniform float shininess;",
  11413. "uniform float opacity;",
  11414. THREE.ShaderChunk[ "common" ],
  11415. THREE.ShaderChunk[ "color_pars_fragment" ],
  11416. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11417. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11418. THREE.ShaderChunk[ "map_pars_fragment" ],
  11419. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11420. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  11421. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  11422. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  11423. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11424. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11425. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  11426. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11427. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  11428. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  11429. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11430. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11431. "void main() {",
  11432. " vec3 outgoingLight = vec3( 0.0 );",
  11433. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11434. " vec3 totalAmbientLight = ambientLightColor;",
  11435. " vec3 totalEmissiveLight = emissive;",
  11436. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11437. THREE.ShaderChunk[ "map_fragment" ],
  11438. THREE.ShaderChunk[ "color_fragment" ],
  11439. THREE.ShaderChunk[ "alphamap_fragment" ],
  11440. THREE.ShaderChunk[ "alphatest_fragment" ],
  11441. THREE.ShaderChunk[ "specularmap_fragment" ],
  11442. THREE.ShaderChunk[ "lightmap_fragment" ],
  11443. THREE.ShaderChunk[ "aomap_fragment" ],
  11444. THREE.ShaderChunk[ "emissivemap_fragment" ],
  11445. THREE.ShaderChunk[ "lights_phong_fragment" ],
  11446. THREE.ShaderChunk[ "envmap_fragment" ],
  11447. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11448. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11449. THREE.ShaderChunk[ "fog_fragment" ],
  11450. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11451. "}"
  11452. ].join( "\n" )
  11453. },
  11454. 'particle_basic': {
  11455. uniforms: THREE.UniformsUtils.merge( [
  11456. THREE.UniformsLib[ "particle" ],
  11457. THREE.UniformsLib[ "shadowmap" ]
  11458. ] ),
  11459. vertexShader: [
  11460. "uniform float size;",
  11461. "uniform float scale;",
  11462. THREE.ShaderChunk[ "common" ],
  11463. THREE.ShaderChunk[ "color_pars_vertex" ],
  11464. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11465. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11466. "void main() {",
  11467. THREE.ShaderChunk[ "color_vertex" ],
  11468. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11469. " #ifdef USE_SIZEATTENUATION",
  11470. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  11471. " #else",
  11472. " gl_PointSize = size;",
  11473. " #endif",
  11474. " gl_Position = projectionMatrix * mvPosition;",
  11475. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11476. THREE.ShaderChunk[ "worldpos_vertex" ],
  11477. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11478. "}"
  11479. ].join( "\n" ),
  11480. fragmentShader: [
  11481. "uniform vec3 psColor;",
  11482. "uniform float opacity;",
  11483. THREE.ShaderChunk[ "common" ],
  11484. THREE.ShaderChunk[ "color_pars_fragment" ],
  11485. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  11486. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11487. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11488. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11489. "void main() {",
  11490. " vec3 outgoingLight = vec3( 0.0 );",
  11491. " vec4 diffuseColor = vec4( psColor, opacity );",
  11492. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11493. THREE.ShaderChunk[ "map_particle_fragment" ],
  11494. THREE.ShaderChunk[ "color_fragment" ],
  11495. THREE.ShaderChunk[ "alphatest_fragment" ],
  11496. " outgoingLight = diffuseColor.rgb;", // simple shader
  11497. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11498. THREE.ShaderChunk[ "fog_fragment" ],
  11499. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11500. "}"
  11501. ].join( "\n" )
  11502. },
  11503. 'dashed': {
  11504. uniforms: THREE.UniformsUtils.merge( [
  11505. THREE.UniformsLib[ "common" ],
  11506. THREE.UniformsLib[ "fog" ],
  11507. {
  11508. "scale" : { type: "f", value: 1 },
  11509. "dashSize" : { type: "f", value: 1 },
  11510. "totalSize": { type: "f", value: 2 }
  11511. }
  11512. ] ),
  11513. vertexShader: [
  11514. "uniform float scale;",
  11515. "attribute float lineDistance;",
  11516. "varying float vLineDistance;",
  11517. THREE.ShaderChunk[ "common" ],
  11518. THREE.ShaderChunk[ "color_pars_vertex" ],
  11519. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11520. "void main() {",
  11521. THREE.ShaderChunk[ "color_vertex" ],
  11522. " vLineDistance = scale * lineDistance;",
  11523. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11524. " gl_Position = projectionMatrix * mvPosition;",
  11525. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11526. "}"
  11527. ].join( "\n" ),
  11528. fragmentShader: [
  11529. "uniform vec3 diffuse;",
  11530. "uniform float opacity;",
  11531. "uniform float dashSize;",
  11532. "uniform float totalSize;",
  11533. "varying float vLineDistance;",
  11534. THREE.ShaderChunk[ "common" ],
  11535. THREE.ShaderChunk[ "color_pars_fragment" ],
  11536. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11537. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11538. "void main() {",
  11539. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  11540. " discard;",
  11541. " }",
  11542. " vec3 outgoingLight = vec3( 0.0 );",
  11543. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11544. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11545. THREE.ShaderChunk[ "color_fragment" ],
  11546. " outgoingLight = diffuseColor.rgb;", // simple shader
  11547. THREE.ShaderChunk[ "fog_fragment" ],
  11548. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11549. "}"
  11550. ].join( "\n" )
  11551. },
  11552. 'depth': {
  11553. uniforms: {
  11554. "mNear": { type: "f", value: 1.0 },
  11555. "mFar" : { type: "f", value: 2000.0 },
  11556. "opacity" : { type: "f", value: 1.0 }
  11557. },
  11558. vertexShader: [
  11559. THREE.ShaderChunk[ "common" ],
  11560. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11561. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11562. "void main() {",
  11563. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11564. THREE.ShaderChunk[ "default_vertex" ],
  11565. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11566. "}"
  11567. ].join( "\n" ),
  11568. fragmentShader: [
  11569. "uniform float mNear;",
  11570. "uniform float mFar;",
  11571. "uniform float opacity;",
  11572. THREE.ShaderChunk[ "common" ],
  11573. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11574. "void main() {",
  11575. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11576. " #ifdef USE_LOGDEPTHBUF_EXT",
  11577. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  11578. " #else",
  11579. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  11580. " #endif",
  11581. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  11582. " gl_FragColor = vec4( vec3( color ), opacity );",
  11583. "}"
  11584. ].join( "\n" )
  11585. },
  11586. 'normal': {
  11587. uniforms: {
  11588. "opacity" : { type: "f", value: 1.0 }
  11589. },
  11590. vertexShader: [
  11591. "varying vec3 vNormal;",
  11592. THREE.ShaderChunk[ "common" ],
  11593. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11594. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11595. "void main() {",
  11596. " vNormal = normalize( normalMatrix * normal );",
  11597. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11598. THREE.ShaderChunk[ "default_vertex" ],
  11599. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11600. "}"
  11601. ].join( "\n" ),
  11602. fragmentShader: [
  11603. "uniform float opacity;",
  11604. "varying vec3 vNormal;",
  11605. THREE.ShaderChunk[ "common" ],
  11606. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11607. "void main() {",
  11608. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  11609. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11610. "}"
  11611. ].join( "\n" )
  11612. },
  11613. /* -------------------------------------------------------------------------
  11614. // Cube map shader
  11615. ------------------------------------------------------------------------- */
  11616. 'cube': {
  11617. uniforms: { "tCube": { type: "t", value: null },
  11618. "tFlip": { type: "f", value: - 1 } },
  11619. vertexShader: [
  11620. "varying vec3 vWorldPosition;",
  11621. THREE.ShaderChunk[ "common" ],
  11622. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11623. "void main() {",
  11624. " vWorldPosition = transformDirection( position, modelMatrix );",
  11625. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11626. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11627. "}"
  11628. ].join( "\n" ),
  11629. fragmentShader: [
  11630. "uniform samplerCube tCube;",
  11631. "uniform float tFlip;",
  11632. "varying vec3 vWorldPosition;",
  11633. THREE.ShaderChunk[ "common" ],
  11634. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11635. "void main() {",
  11636. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11637. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11638. "}"
  11639. ].join( "\n" )
  11640. },
  11641. /* -------------------------------------------------------------------------
  11642. // Cube map shader
  11643. ------------------------------------------------------------------------- */
  11644. 'equirect': {
  11645. uniforms: { "tEquirect": { type: "t", value: null },
  11646. "tFlip": { type: "f", value: - 1 } },
  11647. vertexShader: [
  11648. "varying vec3 vWorldPosition;",
  11649. THREE.ShaderChunk[ "common" ],
  11650. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11651. "void main() {",
  11652. " vWorldPosition = transformDirection( position, modelMatrix );",
  11653. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11654. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11655. "}"
  11656. ].join( "\n" ),
  11657. fragmentShader: [
  11658. "uniform sampler2D tEquirect;",
  11659. "uniform float tFlip;",
  11660. "varying vec3 vWorldPosition;",
  11661. THREE.ShaderChunk[ "common" ],
  11662. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11663. "void main() {",
  11664. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11665. "vec3 direction = normalize( vWorldPosition );",
  11666. "vec2 sampleUV;",
  11667. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  11668. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  11669. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  11670. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11671. "}"
  11672. ].join( "\n" )
  11673. },
  11674. /* Depth encoding into RGBA texture
  11675. *
  11676. * based on SpiderGL shadow map example
  11677. * http://spidergl.org/example.php?id=6
  11678. *
  11679. * originally from
  11680. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  11681. *
  11682. * see also
  11683. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  11684. */
  11685. 'depthRGBA': {
  11686. uniforms: {},
  11687. vertexShader: [
  11688. THREE.ShaderChunk[ "common" ],
  11689. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11690. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11691. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11692. "void main() {",
  11693. THREE.ShaderChunk[ "skinbase_vertex" ],
  11694. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11695. THREE.ShaderChunk[ "skinning_vertex" ],
  11696. THREE.ShaderChunk[ "default_vertex" ],
  11697. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11698. "}"
  11699. ].join( "\n" ),
  11700. fragmentShader: [
  11701. THREE.ShaderChunk[ "common" ],
  11702. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11703. "vec4 pack_depth( const in float depth ) {",
  11704. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  11705. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  11706. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  11707. " res -= res.xxyz * bit_mask;",
  11708. " return res;",
  11709. "}",
  11710. "void main() {",
  11711. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11712. " #ifdef USE_LOGDEPTHBUF_EXT",
  11713. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  11714. " #else",
  11715. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  11716. " #endif",
  11717. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  11718. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  11719. //"gl_FragData[ 0 ] = pack_depth( z );",
  11720. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  11721. "}"
  11722. ].join( "\n" )
  11723. }
  11724. };
  11725. // File:src/renderers/WebGLRenderer.js
  11726. /**
  11727. * @author supereggbert / http://www.paulbrunt.co.uk/
  11728. * @author mrdoob / http://mrdoob.com/
  11729. * @author alteredq / http://alteredqualia.com/
  11730. * @author szimek / https://github.com/szimek/
  11731. */
  11732. THREE.WebGLRenderer = function ( parameters ) {
  11733. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  11734. parameters = parameters || {};
  11735. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  11736. _context = parameters.context !== undefined ? parameters.context : null,
  11737. _width = _canvas.width,
  11738. _height = _canvas.height,
  11739. pixelRatio = 1,
  11740. _precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  11741. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  11742. _depth = parameters.depth !== undefined ? parameters.depth : true,
  11743. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  11744. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  11745. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  11746. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  11747. _logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false,
  11748. _clearColor = new THREE.Color( 0x000000 ),
  11749. _clearAlpha = 0;
  11750. var lights = [];
  11751. var opaqueObjects = [];
  11752. var transparentObjects = [];
  11753. var opaqueImmediateObjects = [];
  11754. var transparentImmediateObjects = [];
  11755. var morphInfluences = new Float32Array( 8 );
  11756. var sprites = [];
  11757. var lensFlares = [];
  11758. // public properties
  11759. this.domElement = _canvas;
  11760. this.context = null;
  11761. // clearing
  11762. this.autoClear = true;
  11763. this.autoClearColor = true;
  11764. this.autoClearDepth = true;
  11765. this.autoClearStencil = true;
  11766. // scene graph
  11767. this.sortObjects = true;
  11768. // physically based shading
  11769. this.gammaFactor = 2.0; // for backwards compatibility
  11770. this.gammaInput = false;
  11771. this.gammaOutput = false;
  11772. // morphs
  11773. this.maxMorphTargets = 8;
  11774. this.maxMorphNormals = 4;
  11775. // flags
  11776. this.autoScaleCubemaps = true;
  11777. // internal properties
  11778. var _this = this,
  11779. _programs = [],
  11780. // internal state cache
  11781. _currentProgram = null,
  11782. _currentFramebuffer = null,
  11783. _currentMaterialId = - 1,
  11784. _currentGeometryProgram = '',
  11785. _currentCamera = null,
  11786. _usedTextureUnits = 0,
  11787. _viewportX = 0,
  11788. _viewportY = 0,
  11789. _viewportWidth = _canvas.width,
  11790. _viewportHeight = _canvas.height,
  11791. _currentWidth = 0,
  11792. _currentHeight = 0,
  11793. // frustum
  11794. _frustum = new THREE.Frustum(),
  11795. // camera matrices cache
  11796. _projScreenMatrix = new THREE.Matrix4(),
  11797. _vector3 = new THREE.Vector3(),
  11798. // light arrays cache
  11799. _direction = new THREE.Vector3(),
  11800. _lightsNeedUpdate = true,
  11801. _lights = {
  11802. ambient: [ 0, 0, 0 ],
  11803. directional: { length: 0, colors: [], positions: [] },
  11804. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  11805. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  11806. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  11807. },
  11808. // info
  11809. _infoMemory = {
  11810. programs: 0,
  11811. geometries: 0,
  11812. textures: 0
  11813. },
  11814. _infoRender = {
  11815. calls: 0,
  11816. vertices: 0,
  11817. faces: 0,
  11818. points: 0
  11819. };
  11820. this.info = {
  11821. render: _infoRender,
  11822. memory: _infoMemory,
  11823. programs: _programs
  11824. };
  11825. // initialize
  11826. var _gl;
  11827. try {
  11828. var attributes = {
  11829. alpha: _alpha,
  11830. depth: _depth,
  11831. stencil: _stencil,
  11832. antialias: _antialias,
  11833. premultipliedAlpha: _premultipliedAlpha,
  11834. preserveDrawingBuffer: _preserveDrawingBuffer
  11835. };
  11836. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  11837. if ( _gl === null ) {
  11838. if ( _canvas.getContext( 'webgl' ) !== null ) {
  11839. throw 'Error creating WebGL context with your selected attributes.';
  11840. } else {
  11841. throw 'Error creating WebGL context.';
  11842. }
  11843. }
  11844. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  11845. } catch ( error ) {
  11846. console.error( 'THREE.WebGLRenderer: ' + error );
  11847. }
  11848. var extensions = new THREE.WebGLExtensions( _gl );
  11849. extensions.get( 'OES_texture_float' );
  11850. extensions.get( 'OES_texture_float_linear' );
  11851. extensions.get( 'OES_texture_half_float' );
  11852. extensions.get( 'OES_texture_half_float_linear' );
  11853. extensions.get( 'OES_standard_derivatives' );
  11854. extensions.get( 'ANGLE_instanced_arrays' );
  11855. if ( extensions.get( 'OES_element_index_uint' ) ) {
  11856. THREE.BufferGeometry.MaxIndex = 4294967296;
  11857. }
  11858. if ( _logarithmicDepthBuffer ) {
  11859. extensions.get( 'EXT_frag_depth' );
  11860. }
  11861. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  11862. var properties = new THREE.WebGLProperties();
  11863. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  11864. //
  11865. function glClearColor( r, g, b, a ) {
  11866. if ( _premultipliedAlpha === true ) {
  11867. r *= a; g *= a; b *= a;
  11868. }
  11869. _gl.clearColor( r, g, b, a );
  11870. }
  11871. function setDefaultGLState() {
  11872. state.init();
  11873. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11874. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11875. }
  11876. function resetGLState() {
  11877. _currentProgram = null;
  11878. _currentCamera = null;
  11879. _currentGeometryProgram = '';
  11880. _currentMaterialId = - 1;
  11881. _lightsNeedUpdate = true;
  11882. state.reset();
  11883. }
  11884. setDefaultGLState();
  11885. this.context = _gl;
  11886. this.extensions = extensions;
  11887. this.state = state;
  11888. // shadow map
  11889. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  11890. this.shadowMap = shadowMap;
  11891. // GPU capabilities
  11892. var _maxTextures = _gl.getParameter( _gl.MAX_TEXTURE_IMAGE_UNITS );
  11893. var _maxVertexTextures = _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  11894. var _maxTextureSize = _gl.getParameter( _gl.MAX_TEXTURE_SIZE );
  11895. var _maxCubemapSize = _gl.getParameter( _gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  11896. var _supportsVertexTextures = _maxVertexTextures > 0;
  11897. var _supportsBoneTextures = _supportsVertexTextures && extensions.get( 'OES_texture_float' );
  11898. var _supportsInstancedArrays = extensions.get( 'ANGLE_instanced_arrays' );
  11899. //
  11900. //
  11901. var _maxPrecision = state.getMaxPrecision( _precision );
  11902. if ( _maxPrecision !== _precision ) {
  11903. console.warn( 'THREE.WebGLRenderer:', _precision, 'not supported, using', _maxPrecision, 'instead.' );
  11904. _precision = _maxPrecision;
  11905. }
  11906. // Plugins
  11907. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  11908. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  11909. // API
  11910. this.getContext = function () {
  11911. return _gl;
  11912. };
  11913. this.getContextAttributes = function () {
  11914. return _gl.getContextAttributes();
  11915. };
  11916. this.forceContextLoss = function () {
  11917. extensions.get( 'WEBGL_lose_context' ).loseContext();
  11918. };
  11919. this.supportsVertexTextures = function () {
  11920. return _supportsVertexTextures;
  11921. };
  11922. this.supportsInstancedArrays = function () {
  11923. return _supportsInstancedArrays;
  11924. };
  11925. this.getMaxAnisotropy = ( function () {
  11926. var value;
  11927. return function getMaxAnisotropy() {
  11928. if ( value !== undefined ) return value;
  11929. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  11930. if ( extension !== null ) {
  11931. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  11932. } else {
  11933. value = 0;
  11934. }
  11935. return value;
  11936. }
  11937. } )();
  11938. this.getPrecision = function () {
  11939. return _precision;
  11940. };
  11941. this.getPixelRatio = function () {
  11942. return pixelRatio;
  11943. };
  11944. this.setPixelRatio = function ( value ) {
  11945. if ( value !== undefined ) pixelRatio = value;
  11946. };
  11947. this.getSize = function () {
  11948. return {
  11949. width: _width,
  11950. height: _height
  11951. };
  11952. };
  11953. this.setSize = function ( width, height, updateStyle ) {
  11954. _width = width;
  11955. _height = height;
  11956. _canvas.width = width * pixelRatio;
  11957. _canvas.height = height * pixelRatio;
  11958. if ( updateStyle !== false ) {
  11959. _canvas.style.width = width + 'px';
  11960. _canvas.style.height = height + 'px';
  11961. }
  11962. this.setViewport( 0, 0, width, height );
  11963. };
  11964. this.setViewport = function ( x, y, width, height ) {
  11965. _viewportX = x * pixelRatio;
  11966. _viewportY = y * pixelRatio;
  11967. _viewportWidth = width * pixelRatio;
  11968. _viewportHeight = height * pixelRatio;
  11969. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11970. };
  11971. this.setScissor = function ( x, y, width, height ) {
  11972. _gl.scissor(
  11973. x * pixelRatio,
  11974. y * pixelRatio,
  11975. width * pixelRatio,
  11976. height * pixelRatio
  11977. );
  11978. };
  11979. this.enableScissorTest = function ( boolean ) {
  11980. state.setScissorTest( boolean );
  11981. };
  11982. // Clearing
  11983. this.getClearColor = function () {
  11984. return _clearColor;
  11985. };
  11986. this.setClearColor = function ( color, alpha ) {
  11987. _clearColor.set( color );
  11988. _clearAlpha = alpha !== undefined ? alpha : 1;
  11989. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11990. };
  11991. this.getClearAlpha = function () {
  11992. return _clearAlpha;
  11993. };
  11994. this.setClearAlpha = function ( alpha ) {
  11995. _clearAlpha = alpha;
  11996. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11997. };
  11998. this.clear = function ( color, depth, stencil ) {
  11999. var bits = 0;
  12000. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  12001. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  12002. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  12003. _gl.clear( bits );
  12004. };
  12005. this.clearColor = function () {
  12006. _gl.clear( _gl.COLOR_BUFFER_BIT );
  12007. };
  12008. this.clearDepth = function () {
  12009. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  12010. };
  12011. this.clearStencil = function () {
  12012. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  12013. };
  12014. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  12015. this.setRenderTarget( renderTarget );
  12016. this.clear( color, depth, stencil );
  12017. };
  12018. // Reset
  12019. this.resetGLState = resetGLState;
  12020. this.dispose = function() {
  12021. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  12022. };
  12023. // Events
  12024. function onContextLost( event ) {
  12025. event.preventDefault();
  12026. resetGLState();
  12027. setDefaultGLState();
  12028. objects.clear();
  12029. properties.clear();
  12030. };
  12031. function onTextureDispose( event ) {
  12032. var texture = event.target;
  12033. texture.removeEventListener( 'dispose', onTextureDispose );
  12034. deallocateTexture( texture );
  12035. _infoMemory.textures --;
  12036. }
  12037. function onRenderTargetDispose( event ) {
  12038. var renderTarget = event.target;
  12039. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12040. deallocateRenderTarget( renderTarget );
  12041. _infoMemory.textures --;
  12042. }
  12043. function onMaterialDispose( event ) {
  12044. var material = event.target;
  12045. material.removeEventListener( 'dispose', onMaterialDispose );
  12046. deallocateMaterial( material );
  12047. }
  12048. // Buffer deallocation
  12049. function deallocateTexture( texture ) {
  12050. var textureProperties = properties.get( texture );
  12051. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  12052. // cube texture
  12053. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  12054. } else {
  12055. // 2D texture
  12056. if ( textureProperties.__webglInit === undefined ) return;
  12057. _gl.deleteTexture( textureProperties.__webglTexture );
  12058. }
  12059. // remove all webgl properties
  12060. properties.delete( texture );
  12061. }
  12062. function deallocateRenderTarget( renderTarget ) {
  12063. var renderTargetProperties = properties.get( renderTarget );
  12064. if ( ! renderTarget || renderTargetProperties.__webglTexture === undefined ) return;
  12065. _gl.deleteTexture( renderTargetProperties.__webglTexture );
  12066. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  12067. for ( var i = 0; i < 6; i ++ ) {
  12068. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12069. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  12070. }
  12071. } else {
  12072. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12073. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  12074. }
  12075. properties.delete( renderTarget );
  12076. }
  12077. function deallocateMaterial( material ) {
  12078. releaseMaterialProgramReference( material );
  12079. properties.delete( material );
  12080. }
  12081. function releaseMaterialProgramReference( material ) {
  12082. var program = properties.get( material ).program.program;
  12083. if ( program === undefined ) return;
  12084. material.program = undefined;
  12085. for ( var i = 0, n = _programs.length; i !== n; ++ i ) {
  12086. var programInfo = _programs[ i ];
  12087. if ( programInfo.program === program ) {
  12088. var newReferenceCount = -- programInfo.usedTimes;
  12089. if ( newReferenceCount === 0 ) {
  12090. // the last meterial that has been using the program let
  12091. // go of it, so remove it from the (unordered) _programs
  12092. // set and deallocate the GL resource
  12093. var newLength = n - 1;
  12094. _programs[ i ] = _programs[ newLength ];
  12095. _programs.pop();
  12096. _gl.deleteProgram( program );
  12097. _infoMemory.programs = newLength;
  12098. }
  12099. break;
  12100. }
  12101. }
  12102. }
  12103. // Buffer rendering
  12104. this.renderBufferImmediate = function ( object, program, material ) {
  12105. state.initAttributes();
  12106. var objectProperties = properties.get( object );
  12107. if ( object.hasPositions && ! objectProperties.__webglVertexBuffer ) objectProperties.__webglVertexBuffer = _gl.createBuffer();
  12108. if ( object.hasNormals && ! objectProperties.__webglNormalBuffer ) objectProperties.__webglNormalBuffer = _gl.createBuffer();
  12109. if ( object.hasUvs && ! objectProperties.__webglUvBuffer ) objectProperties.__webglUvBuffer = _gl.createBuffer();
  12110. if ( object.hasColors && ! objectProperties.__webglColorBuffer ) objectProperties.__webglColorBuffer = _gl.createBuffer();
  12111. var attributes = program.getAttributes();
  12112. if ( object.hasPositions ) {
  12113. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglVertexBuffer );
  12114. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  12115. state.enableAttribute( attributes.position );
  12116. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  12117. }
  12118. if ( object.hasNormals ) {
  12119. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglNormalBuffer );
  12120. if ( material instanceof THREE.MeshPhongMaterial === false && material.shading === THREE.FlatShading ) {
  12121. var nx, ny, nz,
  12122. nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
  12123. normalArray,
  12124. i, il = object.count * 3;
  12125. for ( i = 0; i < il; i += 9 ) {
  12126. normalArray = object.normalArray;
  12127. nax = normalArray[ i ];
  12128. nay = normalArray[ i + 1 ];
  12129. naz = normalArray[ i + 2 ];
  12130. nbx = normalArray[ i + 3 ];
  12131. nby = normalArray[ i + 4 ];
  12132. nbz = normalArray[ i + 5 ];
  12133. ncx = normalArray[ i + 6 ];
  12134. ncy = normalArray[ i + 7 ];
  12135. ncz = normalArray[ i + 8 ];
  12136. nx = ( nax + nbx + ncx ) / 3;
  12137. ny = ( nay + nby + ncy ) / 3;
  12138. nz = ( naz + nbz + ncz ) / 3;
  12139. normalArray[ i ] = nx;
  12140. normalArray[ i + 1 ] = ny;
  12141. normalArray[ i + 2 ] = nz;
  12142. normalArray[ i + 3 ] = nx;
  12143. normalArray[ i + 4 ] = ny;
  12144. normalArray[ i + 5 ] = nz;
  12145. normalArray[ i + 6 ] = nx;
  12146. normalArray[ i + 7 ] = ny;
  12147. normalArray[ i + 8 ] = nz;
  12148. }
  12149. }
  12150. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  12151. state.enableAttribute( attributes.normal );
  12152. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  12153. }
  12154. if ( object.hasUvs && material.map ) {
  12155. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglUvBuffer );
  12156. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  12157. state.enableAttribute( attributes.uv );
  12158. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  12159. }
  12160. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  12161. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglColorBuffer );
  12162. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  12163. state.enableAttribute( attributes.color );
  12164. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  12165. }
  12166. state.disableUnusedAttributes();
  12167. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  12168. object.count = 0;
  12169. };
  12170. this.renderBufferDirect = function ( camera, lights, fog, material, object, materialIndex ) {
  12171. if ( material instanceof THREE.MeshFaceMaterial ) {
  12172. var materials = material.materials;
  12173. for ( var i = 0, il = materials.length; i < il; i ++ ) {
  12174. material = materials[ i ];
  12175. if ( material === null || material.visible === false ) continue;
  12176. _this.renderBufferDirect( camera, lights, fog, material, object, i );
  12177. }
  12178. return;
  12179. }
  12180. setMaterial( material );
  12181. var geometry = objects.geometries.get( object );
  12182. var program = setProgram( camera, lights, fog, material, object );
  12183. var updateBuffers = false,
  12184. wireframeBit = material.wireframe ? 1 : 0,
  12185. geometryProgram = geometry.id + '_' + program.id + '_' + wireframeBit;
  12186. if ( geometryProgram !== _currentGeometryProgram ) {
  12187. _currentGeometryProgram = geometryProgram;
  12188. updateBuffers = true;
  12189. }
  12190. // morph targets
  12191. var morphTargetInfluences = object.morphTargetInfluences;
  12192. if ( morphTargetInfluences !== undefined ) {
  12193. var activeInfluences = [];
  12194. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  12195. var influence = morphTargetInfluences[ i ];
  12196. activeInfluences.push( [ influence, i ] );
  12197. }
  12198. activeInfluences.sort( numericalSort );
  12199. if ( activeInfluences.length > 8 ) {
  12200. activeInfluences.length = 8;
  12201. }
  12202. var morphAttributes = geometry.morphAttributes;
  12203. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  12204. var influence = activeInfluences[ i ];
  12205. morphInfluences[ i ] = influence[ 0 ];
  12206. if ( influence[ 0 ] !== 0 ) {
  12207. var index = influence[ 1 ];
  12208. if ( material.morphTargets === true ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  12209. if ( material.morphNormals === true ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  12210. } else {
  12211. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  12212. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  12213. }
  12214. }
  12215. var uniforms = program.getUniforms();
  12216. if ( uniforms.morphTargetInfluences !== null ) {
  12217. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  12218. }
  12219. updateBuffers = true;
  12220. }
  12221. if ( object instanceof THREE.Mesh ) {
  12222. renderMesh( material, geometry, object, program, updateBuffers, materialIndex );
  12223. } else if ( object instanceof THREE.Line ) {
  12224. renderLine( material, geometry, object, program, updateBuffers, materialIndex );
  12225. } else if ( object instanceof THREE.PointCloud ) {
  12226. renderPointCloud( material, geometry, object, program, updateBuffers, materialIndex );
  12227. }
  12228. };
  12229. function setupVertexAttributes( material, program, geometry, startIndex ) {
  12230. var extension;
  12231. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  12232. extension = extensions.get( 'ANGLE_instanced_arrays' );
  12233. if ( extension === null ) {
  12234. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12235. return;
  12236. }
  12237. }
  12238. state.initAttributes();
  12239. var geometryAttributes = geometry.attributes;
  12240. var programAttributes = program.getAttributes();
  12241. var materialDefaultAttributeValues = material.defaultAttributeValues;
  12242. for ( var name in programAttributes ) {
  12243. var programAttribute = programAttributes[ name ];
  12244. if ( programAttribute >= 0 ) {
  12245. var geometryAttribute = geometryAttributes[ name ];
  12246. if ( geometryAttribute !== undefined ) {
  12247. state.enableAttribute( programAttribute );
  12248. var size = geometryAttribute.itemSize;
  12249. var buffer = objects.getAttributeBuffer( geometryAttribute );
  12250. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  12251. var data = geometryAttribute.data;
  12252. var stride = data.stride;
  12253. var offset = geometryAttribute.offset;
  12254. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12255. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  12256. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  12257. if ( extension === null ) {
  12258. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  12259. return;
  12260. }
  12261. extension.vertexAttribDivisorANGLE( programAttribute, data.meshPerAttribute );
  12262. if ( geometry.maxInstancedCount === undefined ) {
  12263. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  12264. }
  12265. }
  12266. } else {
  12267. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12268. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  12269. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  12270. if ( extension === null ) {
  12271. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  12272. return;
  12273. }
  12274. extension.vertexAttribDivisorANGLE( programAttribute, geometryAttribute.meshPerAttribute );
  12275. if ( geometry.maxInstancedCount === undefined ) {
  12276. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  12277. }
  12278. }
  12279. }
  12280. } else if ( materialDefaultAttributeValues !== undefined ) {
  12281. var value = materialDefaultAttributeValues[ name ];
  12282. if ( value !== undefined ) {
  12283. switch ( value.length ) {
  12284. case 2:
  12285. _gl.vertexAttrib2fv( programAttribute, value );
  12286. break;
  12287. case 3:
  12288. _gl.vertexAttrib3fv( programAttribute, value );
  12289. break;
  12290. case 4:
  12291. _gl.vertexAttrib4fv( programAttribute, value );
  12292. break;
  12293. default:
  12294. _gl.vertexAttrib1fv( programAttribute, value );
  12295. }
  12296. }
  12297. }
  12298. }
  12299. }
  12300. state.disableUnusedAttributes();
  12301. }
  12302. function renderMesh( material, geometry, object, program, updateBuffers, materialIndex ) {
  12303. var mode = _gl.TRIANGLES;
  12304. if ( material.wireframe === true ) {
  12305. mode = _gl.LINES;
  12306. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  12307. }
  12308. var index = geometry.attributes.index;
  12309. if ( index ) {
  12310. // indexed triangles
  12311. var type, size;
  12312. var indexBuffer = objects.getAttributeBuffer( index );
  12313. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12314. type = _gl.UNSIGNED_INT;
  12315. size = 4;
  12316. } else {
  12317. type = _gl.UNSIGNED_SHORT;
  12318. size = 2;
  12319. }
  12320. var offsets = geometry.drawcalls;
  12321. if ( offsets.length === 0 ) {
  12322. if ( updateBuffers ) {
  12323. setupVertexAttributes( material, program, geometry, 0 );
  12324. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12325. }
  12326. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12327. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12328. if ( extension === null ) {
  12329. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12330. return;
  12331. }
  12332. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount ); // Draw the instanced meshes
  12333. } else {
  12334. _gl.drawElements( mode, index.array.length, type, 0 );
  12335. }
  12336. _infoRender.calls ++;
  12337. _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
  12338. _infoRender.faces += index.array.length / 3;
  12339. } else {
  12340. // if there is more than 1 chunk
  12341. // must set attribute pointers to use new offsets for each chunk
  12342. // even if geometry and materials didn't change
  12343. updateBuffers = true;
  12344. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12345. var startIndex = offsets[ i ].index;
  12346. if ( materialIndex !== undefined && offsets[ i ].materialIndex !== materialIndex ) continue;
  12347. if ( updateBuffers ) {
  12348. setupVertexAttributes( material, program, geometry, startIndex );
  12349. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12350. }
  12351. // render indexed triangles
  12352. if ( geometry instanceof THREE.InstancedBufferGeometry && offsets[ i ].instances > 0 ) {
  12353. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12354. if ( extension === null ) {
  12355. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12356. return;
  12357. }
  12358. extension.drawElementsInstancedANGLE( mode, offsets[ i ].count, type, offsets[ i ].start * size, offsets[ i ].count, type, offsets[ i ].instances ); // Draw the instanced meshes
  12359. } else {
  12360. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12361. }
  12362. _infoRender.calls ++;
  12363. _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12364. _infoRender.faces += offsets[ i ].count / 3;
  12365. }
  12366. }
  12367. } else {
  12368. // non-indexed triangles
  12369. var offsets = geometry.drawcalls;
  12370. if ( offsets.length === 0 ) {
  12371. if ( updateBuffers ) {
  12372. setupVertexAttributes( material, program, geometry, 0 );
  12373. }
  12374. var position = geometry.attributes.position;
  12375. // render non-indexed triangles
  12376. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12377. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12378. if ( extension === null ) {
  12379. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12380. return;
  12381. }
  12382. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12383. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount ); // Draw the instanced meshes
  12384. } else {
  12385. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount ); // Draw the instanced meshes
  12386. }
  12387. } else {
  12388. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12389. _gl.drawArrays( mode, 0, position.data.count );
  12390. } else {
  12391. _gl.drawArrays( mode, 0, position.count );
  12392. }
  12393. }
  12394. _infoRender.calls ++;
  12395. _infoRender.vertices += position.count;
  12396. _infoRender.faces += position.array.length / 3;
  12397. } else {
  12398. // if there is more than 1 chunk
  12399. // must set attribute pointers to use new offsets for each chunk
  12400. // even if geometry and materials didn't change
  12401. if ( updateBuffers ) {
  12402. setupVertexAttributes( material, program, geometry, 0 );
  12403. }
  12404. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12405. // render non-indexed triangles
  12406. if ( materialIndex !== undefined && offsets[ i ].materialIndex !== materialIndex ) continue;
  12407. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  12408. console.error( 'THREE.WebGLRenderer.renderMesh: cannot use drawCalls with THREE.InstancedBufferGeometry.' );
  12409. return;
  12410. } else {
  12411. _gl.drawArrays( mode, offsets[ i ].start, offsets[ i ].count );
  12412. }
  12413. _infoRender.calls ++;
  12414. _infoRender.vertices += offsets[ i ].count;
  12415. _infoRender.faces += ( offsets[ i ].count ) / 3;
  12416. }
  12417. }
  12418. }
  12419. }
  12420. function renderLine( material, geometry, object, program, updateBuffers, materialIndex ) {
  12421. var mode = object instanceof THREE.LineSegments ? _gl.LINES : _gl.LINE_STRIP;
  12422. // In case user is not using Line*Material by mistake
  12423. var lineWidth = material.linewidth !== undefined ? material.linewidth : 1;
  12424. state.setLineWidth( lineWidth * pixelRatio );
  12425. var index = geometry.attributes.index;
  12426. if ( index ) {
  12427. // indexed lines
  12428. var type, size;
  12429. var indexBuffer = objects.getAttributeBuffer( index );
  12430. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12431. type = _gl.UNSIGNED_INT;
  12432. size = 4;
  12433. } else {
  12434. type = _gl.UNSIGNED_SHORT;
  12435. size = 2;
  12436. }
  12437. var offsets = geometry.drawcalls;
  12438. if ( offsets.length === 0 ) {
  12439. if ( updateBuffers ) {
  12440. setupVertexAttributes( material, program, geometry, 0 );
  12441. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12442. }
  12443. _gl.drawElements( mode, index.array.length, type, 0 ); // 2 bytes per Uint16Array
  12444. _infoRender.calls ++;
  12445. _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
  12446. } else {
  12447. // if there is more than 1 chunk
  12448. // must set attribute pointers to use new offsets for each chunk
  12449. // even if geometry and materials didn't change
  12450. if ( offsets.length > 1 ) updateBuffers = true;
  12451. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12452. var startIndex = offsets[ i ].index;
  12453. if ( materialIndex !== undefined && offsets[ i ].materialIndex === materialIndex ) continue;
  12454. if ( updateBuffers ) {
  12455. setupVertexAttributes( material, program, geometry, startIndex );
  12456. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12457. }
  12458. // render indexed lines
  12459. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size ); // 2 bytes per Uint16Array
  12460. _infoRender.calls ++;
  12461. _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12462. }
  12463. }
  12464. } else {
  12465. // non-indexed lines
  12466. if ( updateBuffers ) {
  12467. setupVertexAttributes( material, program, geometry, 0 );
  12468. }
  12469. var position = geometry.attributes.position;
  12470. var offsets = geometry.drawcalls;
  12471. if ( offsets.length === 0 ) {
  12472. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12473. _infoRender.calls ++;
  12474. _infoRender.vertices += position.array.length / 3;
  12475. } else {
  12476. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12477. if ( materialIndex !== undefined && offsets[ i ].materialIndex !== materialIndex ) continue;
  12478. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12479. _infoRender.calls ++;
  12480. _infoRender.vertices += offsets[ i ].count;
  12481. }
  12482. }
  12483. }
  12484. }
  12485. function renderPointCloud( material, geometry, object, program, updateBuffers, materialIndex ) {
  12486. var mode = _gl.POINTS;
  12487. var index = geometry.attributes.index;
  12488. if ( index ) {
  12489. // indexed points
  12490. var type, size;
  12491. var indexBuffer = objects.getAttributeBuffer( index );
  12492. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12493. type = _gl.UNSIGNED_INT;
  12494. size = 4;
  12495. } else {
  12496. type = _gl.UNSIGNED_SHORT;
  12497. size = 2;
  12498. }
  12499. var offsets = geometry.drawcalls;
  12500. if ( offsets.length === 0 ) {
  12501. if ( updateBuffers ) {
  12502. setupVertexAttributes( material, program, geometry, 0 );
  12503. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12504. }
  12505. _gl.drawElements( mode, index.array.length, type, 0 );
  12506. _infoRender.calls ++;
  12507. _infoRender.points += index.array.length;
  12508. } else {
  12509. // if there is more than 1 chunk
  12510. // must set attribute pointers to use new offsets for each chunk
  12511. // even if geometry and materials didn't change
  12512. if ( offsets.length > 1 ) updateBuffers = true;
  12513. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12514. var startIndex = offsets[ i ].index;
  12515. if ( materialIndex !== undefined && offsets[ i ].materialIndex !== materialIndex ) continue;
  12516. if ( updateBuffers ) {
  12517. setupVertexAttributes( material, program, geometry, startIndex );
  12518. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12519. }
  12520. // render indexed points
  12521. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12522. _infoRender.calls ++;
  12523. _infoRender.points += offsets[ i ].count;
  12524. }
  12525. }
  12526. } else {
  12527. // non-indexed points
  12528. if ( updateBuffers ) {
  12529. setupVertexAttributes( material, program, geometry, 0 );
  12530. }
  12531. var position = geometry.attributes.position;
  12532. var offsets = geometry.drawcalls;
  12533. if ( offsets.length === 0 ) {
  12534. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12535. _infoRender.calls ++;
  12536. _infoRender.points += position.array.length / 3;
  12537. } else {
  12538. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12539. if ( materialIndex !== undefined && offsets[ i ].materialIndex !== materialIndex ) continue;
  12540. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12541. _infoRender.calls ++;
  12542. _infoRender.points += offsets[ i ].count;
  12543. }
  12544. }
  12545. }
  12546. }
  12547. // Sorting
  12548. function numericalSort ( a, b ) {
  12549. return b[ 0 ] - a[ 0 ];
  12550. }
  12551. function painterSortStable ( a, b ) {
  12552. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12553. return a.object.renderOrder - b.object.renderOrder;
  12554. } else if ( a.object.material.id !== b.object.material.id ) {
  12555. return a.object.material.id - b.object.material.id;
  12556. } else if ( a.z !== b.z ) {
  12557. return a.z - b.z;
  12558. } else {
  12559. return a.id - b.id;
  12560. }
  12561. }
  12562. function reversePainterSortStable ( a, b ) {
  12563. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12564. return a.object.renderOrder - b.object.renderOrder;
  12565. } if ( a.z !== b.z ) {
  12566. return b.z - a.z;
  12567. } else {
  12568. return a.id - b.id;
  12569. }
  12570. }
  12571. // Rendering
  12572. this.render = function ( scene, camera, renderTarget, forceClear ) {
  12573. if ( camera instanceof THREE.Camera === false ) {
  12574. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  12575. return;
  12576. }
  12577. var fog = scene.fog;
  12578. // reset caching for this frame
  12579. _currentGeometryProgram = '';
  12580. _currentMaterialId = - 1;
  12581. _currentCamera = null;
  12582. _lightsNeedUpdate = true;
  12583. // update scene graph
  12584. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  12585. // update camera matrices and frustum
  12586. if ( camera.parent === null ) camera.updateMatrixWorld();
  12587. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12588. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  12589. _frustum.setFromMatrix( _projScreenMatrix );
  12590. lights.length = 0;
  12591. opaqueObjects.length = 0;
  12592. transparentObjects.length = 0;
  12593. opaqueImmediateObjects.length = 0;
  12594. transparentImmediateObjects.length = 0;
  12595. sprites.length = 0;
  12596. lensFlares.length = 0;
  12597. projectObject( scene );
  12598. if ( _this.sortObjects === true ) {
  12599. opaqueObjects.sort( painterSortStable );
  12600. transparentObjects.sort( reversePainterSortStable );
  12601. }
  12602. objects.update( opaqueObjects );
  12603. objects.update( transparentObjects );
  12604. //
  12605. shadowMap.render( scene, camera );
  12606. //
  12607. _infoRender.calls = 0;
  12608. _infoRender.vertices = 0;
  12609. _infoRender.faces = 0;
  12610. _infoRender.points = 0;
  12611. this.setRenderTarget( renderTarget );
  12612. if ( this.autoClear || forceClear ) {
  12613. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  12614. }
  12615. //
  12616. if ( scene.overrideMaterial ) {
  12617. var overrideMaterial = scene.overrideMaterial;
  12618. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  12619. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  12620. renderObjectsImmediate( opaqueImmediateObjects, camera, lights, fog, overrideMaterial );
  12621. renderObjectsImmediate( transparentImmediateObjects, camera, lights, fog, overrideMaterial );
  12622. } else {
  12623. // opaque pass (front-to-back order)
  12624. state.setBlending( THREE.NoBlending );
  12625. renderObjects( opaqueObjects, camera, lights, fog, null );
  12626. renderObjectsImmediate( opaqueImmediateObjects, camera, lights, fog, null );
  12627. // transparent pass (back-to-front order)
  12628. renderObjects( transparentObjects, camera, lights, fog, null );
  12629. renderObjectsImmediate( transparentImmediateObjects, camera, lights, fog, null );
  12630. }
  12631. // custom render plugins (post pass)
  12632. spritePlugin.render( scene, camera );
  12633. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  12634. // Generate mipmap if we're using any kind of mipmap filtering
  12635. if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
  12636. updateRenderTargetMipmap( renderTarget );
  12637. }
  12638. // Ensure depth buffer writing is enabled so it can be cleared on next render
  12639. state.setDepthTest( true );
  12640. state.setDepthWrite( true );
  12641. state.setColorWrite( true );
  12642. // _gl.finish();
  12643. };
  12644. function projectObject( object ) {
  12645. if ( object.visible === false ) return;
  12646. if ( object instanceof THREE.Scene || object instanceof THREE.Group ) {
  12647. // skip
  12648. } else {
  12649. // update Skeleton objects
  12650. if ( object instanceof THREE.SkinnedMesh ) {
  12651. object.skeleton.update();
  12652. }
  12653. objects.init( object );
  12654. if ( object instanceof THREE.Light ) {
  12655. lights.push( object );
  12656. } else if ( object instanceof THREE.Sprite ) {
  12657. sprites.push( object );
  12658. } else if ( object instanceof THREE.LensFlare ) {
  12659. lensFlares.push( object );
  12660. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  12661. var material = object.material;
  12662. if ( material.transparent ) {
  12663. transparentImmediateObjects.push( object );
  12664. } else {
  12665. opaqueImmediateObjects.push( object );
  12666. }
  12667. } else {
  12668. var webglObject = objects.objects[ object.id ];
  12669. if ( webglObject && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  12670. var material = object.material;
  12671. if ( material !== null && material.visible === true ) {
  12672. if ( properties.get( material ) ) {
  12673. material.program = properties.get( material ).program;
  12674. }
  12675. if ( material.transparent ) {
  12676. transparentObjects.push( webglObject );
  12677. } else {
  12678. opaqueObjects.push( webglObject );
  12679. }
  12680. if ( _this.sortObjects === true ) {
  12681. _vector3.setFromMatrixPosition( object.matrixWorld );
  12682. _vector3.applyProjection( _projScreenMatrix );
  12683. webglObject.z = _vector3.z;
  12684. }
  12685. }
  12686. }
  12687. }
  12688. }
  12689. var children = object.children;
  12690. for ( var i = 0, l = children.length; i < l; i ++ ) {
  12691. projectObject( children[ i ] );
  12692. }
  12693. }
  12694. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  12695. var material = overrideMaterial;
  12696. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12697. var webglObject = renderList[ i ];
  12698. var object = webglObject.object;
  12699. setupMatrices( object, camera );
  12700. if ( overrideMaterial === null ) material = object.material;
  12701. _this.renderBufferDirect( camera, lights, fog, material, object );
  12702. }
  12703. }
  12704. function renderObjectsImmediate( renderList, camera, lights, fog, overrideMaterial ) {
  12705. var material = overrideMaterial;
  12706. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12707. var object = renderList[ i ];
  12708. setupMatrices( object, camera );
  12709. if ( object.visible === true ) {
  12710. if ( overrideMaterial === null ) material = object.material;
  12711. _this.renderImmediateObject( camera, lights, fog, material, object );
  12712. }
  12713. }
  12714. }
  12715. this.renderImmediateObject = function ( camera, lights, fog, material, object ) {
  12716. setMaterial( material );
  12717. var program = setProgram( camera, lights, fog, material, object );
  12718. _currentGeometryProgram = '';
  12719. object.render( function ( object ) {
  12720. _this.renderBufferImmediate( object, program, material );
  12721. } );
  12722. };
  12723. // Materials
  12724. var shaderIDs = {
  12725. MeshDepthMaterial: 'depth',
  12726. MeshNormalMaterial: 'normal',
  12727. MeshBasicMaterial: 'basic',
  12728. MeshLambertMaterial: 'lambert',
  12729. MeshPhongMaterial: 'phong',
  12730. LineBasicMaterial: 'basic',
  12731. LineDashedMaterial: 'dashed',
  12732. PointCloudMaterial: 'particle_basic'
  12733. };
  12734. function initMaterial( material, lights, fog, object ) {
  12735. var materialProperties = properties.get( material );
  12736. var shaderID = shaderIDs[ material.type ];
  12737. // heuristics to create shader parameters according to lights in the scene
  12738. // (not to blow over maxLights budget)
  12739. var maxLightCount = allocateLights( lights );
  12740. var maxShadows = allocateShadows( lights );
  12741. var maxBones = allocateBones( object );
  12742. var precision = _precision;
  12743. if ( material.precision !== null ) {
  12744. precision = state.getMaxPrecision( material.precision );
  12745. if ( precision !== material.precision ) {
  12746. console.warn( 'THREE.WebGLRenderer.initMaterial:', material.precision, 'not supported, using', precision, 'instead.' );
  12747. }
  12748. }
  12749. var parameters = {
  12750. precision: precision,
  12751. supportsVertexTextures: _supportsVertexTextures,
  12752. map: !! material.map,
  12753. envMap: !! material.envMap,
  12754. envMapMode: material.envMap && material.envMap.mapping,
  12755. lightMap: !! material.lightMap,
  12756. aoMap: !! material.aoMap,
  12757. emissiveMap: !! material.emissiveMap,
  12758. bumpMap: !! material.bumpMap,
  12759. normalMap: !! material.normalMap,
  12760. specularMap: !! material.specularMap,
  12761. alphaMap: !! material.alphaMap,
  12762. combine: material.combine,
  12763. vertexColors: material.vertexColors,
  12764. fog: fog,
  12765. useFog: material.fog,
  12766. fogExp: fog instanceof THREE.FogExp2,
  12767. flatShading: material.shading === THREE.FlatShading,
  12768. sizeAttenuation: material.sizeAttenuation,
  12769. logarithmicDepthBuffer: _logarithmicDepthBuffer,
  12770. skinning: material.skinning,
  12771. maxBones: maxBones,
  12772. useVertexTexture: _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  12773. morphTargets: material.morphTargets,
  12774. morphNormals: material.morphNormals,
  12775. maxMorphTargets: _this.maxMorphTargets,
  12776. maxMorphNormals: _this.maxMorphNormals,
  12777. maxDirLights: maxLightCount.directional,
  12778. maxPointLights: maxLightCount.point,
  12779. maxSpotLights: maxLightCount.spot,
  12780. maxHemiLights: maxLightCount.hemi,
  12781. maxShadows: maxShadows,
  12782. shadowMapEnabled: shadowMap.enabled && object.receiveShadow && maxShadows > 0,
  12783. shadowMapType: shadowMap.type,
  12784. shadowMapDebug: shadowMap.debug,
  12785. alphaTest: material.alphaTest,
  12786. metal: material.metal,
  12787. doubleSided: material.side === THREE.DoubleSide,
  12788. flipSided: material.side === THREE.BackSide
  12789. };
  12790. // Generate code
  12791. var chunks = [];
  12792. if ( shaderID ) {
  12793. chunks.push( shaderID );
  12794. } else {
  12795. chunks.push( material.fragmentShader );
  12796. chunks.push( material.vertexShader );
  12797. }
  12798. if ( material.defines !== undefined ) {
  12799. for ( var name in material.defines ) {
  12800. chunks.push( name );
  12801. chunks.push( material.defines[ name ] );
  12802. }
  12803. }
  12804. for ( var name in parameters ) {
  12805. chunks.push( name );
  12806. chunks.push( parameters[ name ] );
  12807. }
  12808. var code = chunks.join();
  12809. var programChange = true;
  12810. if ( ! materialProperties.program ) {
  12811. // new material
  12812. material.addEventListener( 'dispose', onMaterialDispose );
  12813. } else if ( materialProperties.program.code !== code ) {
  12814. // changed glsl or parameters
  12815. releaseMaterialProgramReference( material );
  12816. } else if ( shaderID !== undefined ) {
  12817. // same glsl and uniform list
  12818. return;
  12819. } else {
  12820. // only rebuild uniform list
  12821. programChange = false;
  12822. }
  12823. if ( shaderID ) {
  12824. var shader = THREE.ShaderLib[ shaderID ];
  12825. materialProperties.__webglShader = {
  12826. name: material.type,
  12827. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  12828. vertexShader: shader.vertexShader,
  12829. fragmentShader: shader.fragmentShader
  12830. };
  12831. } else {
  12832. materialProperties.__webglShader = {
  12833. name: material.type,
  12834. uniforms: material.uniforms,
  12835. vertexShader: material.vertexShader,
  12836. fragmentShader: material.fragmentShader
  12837. };
  12838. }
  12839. var program;
  12840. // Check if code has been already compiled
  12841. for ( var p = 0, pl = _programs.length; p < pl; p ++ ) {
  12842. var programInfo = _programs[ p ];
  12843. if ( programInfo.code === code ) {
  12844. program = programInfo;
  12845. if ( programChange ) {
  12846. program.usedTimes ++;
  12847. }
  12848. break;
  12849. }
  12850. }
  12851. if ( program === undefined ) {
  12852. material.__webglShader = materialProperties.__webglShader;
  12853. program = new THREE.WebGLProgram( _this, code, material, parameters );
  12854. _programs.push( program );
  12855. _infoMemory.programs = _programs.length;
  12856. }
  12857. materialProperties.program = program;
  12858. var attributes = program.getAttributes();
  12859. if ( material.morphTargets ) {
  12860. material.numSupportedMorphTargets = 0;
  12861. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  12862. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  12863. material.numSupportedMorphTargets ++;
  12864. }
  12865. }
  12866. }
  12867. if ( material.morphNormals ) {
  12868. material.numSupportedMorphNormals = 0;
  12869. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  12870. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  12871. material.numSupportedMorphNormals ++;
  12872. }
  12873. }
  12874. }
  12875. materialProperties.uniformsList = [];
  12876. var uniformLocations = materialProperties.program.getUniforms();
  12877. for ( var u in materialProperties.__webglShader.uniforms ) {
  12878. var location = uniformLocations[ u ];
  12879. if ( location ) {
  12880. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  12881. }
  12882. }
  12883. }
  12884. function setMaterial( material ) {
  12885. setMaterialFaces( material );
  12886. if ( material.transparent === true ) {
  12887. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  12888. } else {
  12889. state.setBlending( THREE.NoBlending );
  12890. }
  12891. state.setDepthFunc( material.depthFunc );
  12892. state.setDepthTest( material.depthTest );
  12893. state.setDepthWrite( material.depthWrite );
  12894. state.setColorWrite( material.colorWrite );
  12895. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12896. }
  12897. function setMaterialFaces( material ) {
  12898. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  12899. state.setFlipSided( material.side === THREE.BackSide );
  12900. }
  12901. function setProgram( camera, lights, fog, material, object ) {
  12902. _usedTextureUnits = 0;
  12903. var materialProperties = properties.get( material );
  12904. if ( material.needsUpdate || ! materialProperties.program ) {
  12905. initMaterial( material, lights, fog, object );
  12906. material.needsUpdate = false;
  12907. }
  12908. var refreshProgram = false;
  12909. var refreshMaterial = false;
  12910. var refreshLights = false;
  12911. var program = materialProperties.program,
  12912. p_uniforms = program.getUniforms(),
  12913. m_uniforms = materialProperties.__webglShader.uniforms;
  12914. if ( program.id !== _currentProgram ) {
  12915. _gl.useProgram( program.program );
  12916. _currentProgram = program.id;
  12917. refreshProgram = true;
  12918. refreshMaterial = true;
  12919. refreshLights = true;
  12920. }
  12921. if ( material.id !== _currentMaterialId ) {
  12922. if ( _currentMaterialId === - 1 ) refreshLights = true;
  12923. _currentMaterialId = material.id;
  12924. refreshMaterial = true;
  12925. }
  12926. if ( refreshProgram || camera !== _currentCamera ) {
  12927. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  12928. if ( _logarithmicDepthBuffer ) {
  12929. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  12930. }
  12931. if ( camera !== _currentCamera ) _currentCamera = camera;
  12932. // load material specific uniforms
  12933. // (shader material also gets them for the sake of genericity)
  12934. if ( material instanceof THREE.ShaderMaterial ||
  12935. material instanceof THREE.MeshPhongMaterial ||
  12936. material.envMap ) {
  12937. if ( p_uniforms.cameraPosition !== undefined ) {
  12938. _vector3.setFromMatrixPosition( camera.matrixWorld );
  12939. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  12940. }
  12941. }
  12942. if ( material instanceof THREE.MeshPhongMaterial ||
  12943. material instanceof THREE.MeshLambertMaterial ||
  12944. material instanceof THREE.MeshBasicMaterial ||
  12945. material instanceof THREE.ShaderMaterial ||
  12946. material.skinning ) {
  12947. if ( p_uniforms.viewMatrix !== undefined ) {
  12948. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  12949. }
  12950. }
  12951. }
  12952. // skinning uniforms must be set even if material didn't change
  12953. // auto-setting of texture unit for bone texture must go before other textures
  12954. // not sure why, but otherwise weird things happen
  12955. if ( material.skinning ) {
  12956. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  12957. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  12958. }
  12959. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  12960. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  12961. }
  12962. if ( _supportsBoneTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  12963. if ( p_uniforms.boneTexture !== undefined ) {
  12964. var textureUnit = getTextureUnit();
  12965. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  12966. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  12967. }
  12968. if ( p_uniforms.boneTextureWidth !== undefined ) {
  12969. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  12970. }
  12971. if ( p_uniforms.boneTextureHeight !== undefined ) {
  12972. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  12973. }
  12974. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  12975. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  12976. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  12977. }
  12978. }
  12979. }
  12980. if ( refreshMaterial ) {
  12981. // refresh uniforms common to several materials
  12982. if ( fog && material.fog ) {
  12983. refreshUniformsFog( m_uniforms, fog );
  12984. }
  12985. if ( material instanceof THREE.MeshPhongMaterial ||
  12986. material instanceof THREE.MeshLambertMaterial ||
  12987. material.lights ) {
  12988. if ( _lightsNeedUpdate ) {
  12989. refreshLights = true;
  12990. setupLights( lights );
  12991. _lightsNeedUpdate = false;
  12992. }
  12993. if ( refreshLights ) {
  12994. refreshUniformsLights( m_uniforms, _lights );
  12995. markUniformsLightsNeedsUpdate( m_uniforms, true );
  12996. } else {
  12997. markUniformsLightsNeedsUpdate( m_uniforms, false );
  12998. }
  12999. }
  13000. if ( material instanceof THREE.MeshBasicMaterial ||
  13001. material instanceof THREE.MeshLambertMaterial ||
  13002. material instanceof THREE.MeshPhongMaterial ) {
  13003. refreshUniformsCommon( m_uniforms, material );
  13004. }
  13005. // refresh single material specific uniforms
  13006. if ( material instanceof THREE.LineBasicMaterial ) {
  13007. refreshUniformsLine( m_uniforms, material );
  13008. } else if ( material instanceof THREE.LineDashedMaterial ) {
  13009. refreshUniformsLine( m_uniforms, material );
  13010. refreshUniformsDash( m_uniforms, material );
  13011. } else if ( material instanceof THREE.PointCloudMaterial ) {
  13012. refreshUniformsParticle( m_uniforms, material );
  13013. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  13014. refreshUniformsPhong( m_uniforms, material );
  13015. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  13016. refreshUniformsLambert( m_uniforms, material );
  13017. } else if ( material instanceof THREE.MeshBasicMaterial ) {
  13018. refreshUniformsBasic( m_uniforms, material );
  13019. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  13020. m_uniforms.mNear.value = camera.near;
  13021. m_uniforms.mFar.value = camera.far;
  13022. m_uniforms.opacity.value = material.opacity;
  13023. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  13024. m_uniforms.opacity.value = material.opacity;
  13025. }
  13026. if ( object.receiveShadow && ! material._shadowPass ) {
  13027. refreshUniformsShadow( m_uniforms, lights );
  13028. }
  13029. // load common uniforms
  13030. loadUniformsGeneric( materialProperties.uniformsList );
  13031. }
  13032. loadUniformsMatrices( p_uniforms, object );
  13033. if ( p_uniforms.modelMatrix !== undefined ) {
  13034. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  13035. }
  13036. return program;
  13037. }
  13038. // Uniforms (refresh uniforms objects)
  13039. function refreshUniformsCommon ( uniforms, material ) {
  13040. uniforms.opacity.value = material.opacity;
  13041. uniforms.diffuse.value = material.color;
  13042. uniforms.map.value = material.map;
  13043. uniforms.specularMap.value = material.specularMap;
  13044. uniforms.alphaMap.value = material.alphaMap;
  13045. if ( material.bumpMap ) {
  13046. uniforms.bumpMap.value = material.bumpMap;
  13047. uniforms.bumpScale.value = material.bumpScale;
  13048. }
  13049. if ( material.normalMap ) {
  13050. uniforms.normalMap.value = material.normalMap;
  13051. uniforms.normalScale.value.copy( material.normalScale );
  13052. }
  13053. // uv repeat and offset setting priorities
  13054. // 1. color map
  13055. // 2. specular map
  13056. // 3. normal map
  13057. // 4. bump map
  13058. // 5. alpha map
  13059. // 6. emissive map
  13060. var uvScaleMap;
  13061. if ( material.map ) {
  13062. uvScaleMap = material.map;
  13063. } else if ( material.specularMap ) {
  13064. uvScaleMap = material.specularMap;
  13065. } else if ( material.normalMap ) {
  13066. uvScaleMap = material.normalMap;
  13067. } else if ( material.bumpMap ) {
  13068. uvScaleMap = material.bumpMap;
  13069. } else if ( material.alphaMap ) {
  13070. uvScaleMap = material.alphaMap;
  13071. } else if ( material.emissiveMap ) {
  13072. uvScaleMap = material.emissiveMap;
  13073. }
  13074. if ( uvScaleMap !== undefined ) {
  13075. var offset = uvScaleMap.offset;
  13076. var repeat = uvScaleMap.repeat;
  13077. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13078. }
  13079. uniforms.envMap.value = material.envMap;
  13080. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  13081. uniforms.reflectivity.value = material.reflectivity;
  13082. uniforms.refractionRatio.value = material.refractionRatio;
  13083. }
  13084. function refreshUniformsLine ( uniforms, material ) {
  13085. uniforms.diffuse.value = material.color;
  13086. uniforms.opacity.value = material.opacity;
  13087. }
  13088. function refreshUniformsDash ( uniforms, material ) {
  13089. uniforms.dashSize.value = material.dashSize;
  13090. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13091. uniforms.scale.value = material.scale;
  13092. }
  13093. function refreshUniformsParticle ( uniforms, material ) {
  13094. uniforms.psColor.value = material.color;
  13095. uniforms.opacity.value = material.opacity;
  13096. uniforms.size.value = material.size;
  13097. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  13098. uniforms.map.value = material.map;
  13099. if ( material.map !== null ) {
  13100. var offset = material.map.offset;
  13101. var repeat = material.map.repeat;
  13102. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13103. }
  13104. }
  13105. function refreshUniformsFog ( uniforms, fog ) {
  13106. uniforms.fogColor.value = fog.color;
  13107. if ( fog instanceof THREE.Fog ) {
  13108. uniforms.fogNear.value = fog.near;
  13109. uniforms.fogFar.value = fog.far;
  13110. } else if ( fog instanceof THREE.FogExp2 ) {
  13111. uniforms.fogDensity.value = fog.density;
  13112. }
  13113. }
  13114. function refreshUniformsPhong ( uniforms, material ) {
  13115. uniforms.shininess.value = material.shininess;
  13116. uniforms.emissive.value = material.emissive;
  13117. uniforms.specular.value = material.specular;
  13118. uniforms.lightMap.value = material.lightMap;
  13119. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13120. uniforms.aoMap.value = material.aoMap;
  13121. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13122. uniforms.emissiveMap.value = material.emissiveMap;
  13123. }
  13124. function refreshUniformsLambert ( uniforms, material ) {
  13125. uniforms.emissive.value = material.emissive;
  13126. }
  13127. function refreshUniformsBasic ( uniforms, material ) {
  13128. uniforms.aoMap.value = material.aoMap;
  13129. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13130. }
  13131. function refreshUniformsLights ( uniforms, lights ) {
  13132. uniforms.ambientLightColor.value = lights.ambient;
  13133. uniforms.directionalLightColor.value = lights.directional.colors;
  13134. uniforms.directionalLightDirection.value = lights.directional.positions;
  13135. uniforms.pointLightColor.value = lights.point.colors;
  13136. uniforms.pointLightPosition.value = lights.point.positions;
  13137. uniforms.pointLightDistance.value = lights.point.distances;
  13138. uniforms.pointLightDecay.value = lights.point.decays;
  13139. uniforms.spotLightColor.value = lights.spot.colors;
  13140. uniforms.spotLightPosition.value = lights.spot.positions;
  13141. uniforms.spotLightDistance.value = lights.spot.distances;
  13142. uniforms.spotLightDirection.value = lights.spot.directions;
  13143. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  13144. uniforms.spotLightExponent.value = lights.spot.exponents;
  13145. uniforms.spotLightDecay.value = lights.spot.decays;
  13146. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  13147. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  13148. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  13149. }
  13150. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13151. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  13152. uniforms.ambientLightColor.needsUpdate = value;
  13153. uniforms.directionalLightColor.needsUpdate = value;
  13154. uniforms.directionalLightDirection.needsUpdate = value;
  13155. uniforms.pointLightColor.needsUpdate = value;
  13156. uniforms.pointLightPosition.needsUpdate = value;
  13157. uniforms.pointLightDistance.needsUpdate = value;
  13158. uniforms.pointLightDecay.needsUpdate = value;
  13159. uniforms.spotLightColor.needsUpdate = value;
  13160. uniforms.spotLightPosition.needsUpdate = value;
  13161. uniforms.spotLightDistance.needsUpdate = value;
  13162. uniforms.spotLightDirection.needsUpdate = value;
  13163. uniforms.spotLightAngleCos.needsUpdate = value;
  13164. uniforms.spotLightExponent.needsUpdate = value;
  13165. uniforms.spotLightDecay.needsUpdate = value;
  13166. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  13167. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  13168. uniforms.hemisphereLightDirection.needsUpdate = value;
  13169. }
  13170. function refreshUniformsShadow ( uniforms, lights ) {
  13171. if ( uniforms.shadowMatrix ) {
  13172. var j = 0;
  13173. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  13174. var light = lights[ i ];
  13175. if ( ! light.castShadow ) continue;
  13176. if ( light instanceof THREE.SpotLight || ( light instanceof THREE.DirectionalLight ) ) {
  13177. uniforms.shadowMap.value[ j ] = light.shadowMap;
  13178. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  13179. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  13180. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  13181. uniforms.shadowBias.value[ j ] = light.shadowBias;
  13182. j ++;
  13183. }
  13184. }
  13185. }
  13186. }
  13187. // Uniforms (load to GPU)
  13188. function loadUniformsMatrices ( uniforms, object ) {
  13189. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object._modelViewMatrix.elements );
  13190. if ( uniforms.normalMatrix ) {
  13191. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object._normalMatrix.elements );
  13192. }
  13193. }
  13194. function getTextureUnit() {
  13195. var textureUnit = _usedTextureUnits;
  13196. if ( textureUnit >= _maxTextures ) {
  13197. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + _maxTextures );
  13198. }
  13199. _usedTextureUnits += 1;
  13200. return textureUnit;
  13201. }
  13202. function loadUniformsGeneric ( uniforms ) {
  13203. var texture, textureUnit, offset;
  13204. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  13205. var uniform = uniforms[ j ][ 0 ];
  13206. // needsUpdate property is not added to all uniforms.
  13207. if ( uniform.needsUpdate === false ) continue;
  13208. var type = uniform.type;
  13209. var value = uniform.value;
  13210. var location = uniforms[ j ][ 1 ];
  13211. switch ( type ) {
  13212. case '1i':
  13213. _gl.uniform1i( location, value );
  13214. break;
  13215. case '1f':
  13216. _gl.uniform1f( location, value );
  13217. break;
  13218. case '2f':
  13219. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  13220. break;
  13221. case '3f':
  13222. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  13223. break;
  13224. case '4f':
  13225. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  13226. break;
  13227. case '1iv':
  13228. _gl.uniform1iv( location, value );
  13229. break;
  13230. case '3iv':
  13231. _gl.uniform3iv( location, value );
  13232. break;
  13233. case '1fv':
  13234. _gl.uniform1fv( location, value );
  13235. break;
  13236. case '2fv':
  13237. _gl.uniform2fv( location, value );
  13238. break;
  13239. case '3fv':
  13240. _gl.uniform3fv( location, value );
  13241. break;
  13242. case '4fv':
  13243. _gl.uniform4fv( location, value );
  13244. break;
  13245. case 'Matrix3fv':
  13246. _gl.uniformMatrix3fv( location, false, value );
  13247. break;
  13248. case 'Matrix4fv':
  13249. _gl.uniformMatrix4fv( location, false, value );
  13250. break;
  13251. //
  13252. case 'i':
  13253. // single integer
  13254. _gl.uniform1i( location, value );
  13255. break;
  13256. case 'f':
  13257. // single float
  13258. _gl.uniform1f( location, value );
  13259. break;
  13260. case 'v2':
  13261. // single THREE.Vector2
  13262. _gl.uniform2f( location, value.x, value.y );
  13263. break;
  13264. case 'v3':
  13265. // single THREE.Vector3
  13266. _gl.uniform3f( location, value.x, value.y, value.z );
  13267. break;
  13268. case 'v4':
  13269. // single THREE.Vector4
  13270. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  13271. break;
  13272. case 'c':
  13273. // single THREE.Color
  13274. _gl.uniform3f( location, value.r, value.g, value.b );
  13275. break;
  13276. case 'iv1':
  13277. // flat array of integers (JS or typed array)
  13278. _gl.uniform1iv( location, value );
  13279. break;
  13280. case 'iv':
  13281. // flat array of integers with 3 x N size (JS or typed array)
  13282. _gl.uniform3iv( location, value );
  13283. break;
  13284. case 'fv1':
  13285. // flat array of floats (JS or typed array)
  13286. _gl.uniform1fv( location, value );
  13287. break;
  13288. case 'fv':
  13289. // flat array of floats with 3 x N size (JS or typed array)
  13290. _gl.uniform3fv( location, value );
  13291. break;
  13292. case 'v2v':
  13293. // array of THREE.Vector2
  13294. if ( uniform._array === undefined ) {
  13295. uniform._array = new Float32Array( 2 * value.length );
  13296. }
  13297. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13298. offset = i * 2;
  13299. uniform._array[ offset + 0 ] = value[ i ].x;
  13300. uniform._array[ offset + 1 ] = value[ i ].y;
  13301. }
  13302. _gl.uniform2fv( location, uniform._array );
  13303. break;
  13304. case 'v3v':
  13305. // array of THREE.Vector3
  13306. if ( uniform._array === undefined ) {
  13307. uniform._array = new Float32Array( 3 * value.length );
  13308. }
  13309. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13310. offset = i * 3;
  13311. uniform._array[ offset + 0 ] = value[ i ].x;
  13312. uniform._array[ offset + 1 ] = value[ i ].y;
  13313. uniform._array[ offset + 2 ] = value[ i ].z;
  13314. }
  13315. _gl.uniform3fv( location, uniform._array );
  13316. break;
  13317. case 'v4v':
  13318. // array of THREE.Vector4
  13319. if ( uniform._array === undefined ) {
  13320. uniform._array = new Float32Array( 4 * value.length );
  13321. }
  13322. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13323. offset = i * 4;
  13324. uniform._array[ offset + 0 ] = value[ i ].x;
  13325. uniform._array[ offset + 1 ] = value[ i ].y;
  13326. uniform._array[ offset + 2 ] = value[ i ].z;
  13327. uniform._array[ offset + 3 ] = value[ i ].w;
  13328. }
  13329. _gl.uniform4fv( location, uniform._array );
  13330. break;
  13331. case 'm3':
  13332. // single THREE.Matrix3
  13333. _gl.uniformMatrix3fv( location, false, value.elements );
  13334. break;
  13335. case 'm3v':
  13336. // array of THREE.Matrix3
  13337. if ( uniform._array === undefined ) {
  13338. uniform._array = new Float32Array( 9 * value.length );
  13339. }
  13340. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13341. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  13342. }
  13343. _gl.uniformMatrix3fv( location, false, uniform._array );
  13344. break;
  13345. case 'm4':
  13346. // single THREE.Matrix4
  13347. _gl.uniformMatrix4fv( location, false, value.elements );
  13348. break;
  13349. case 'm4v':
  13350. // array of THREE.Matrix4
  13351. if ( uniform._array === undefined ) {
  13352. uniform._array = new Float32Array( 16 * value.length );
  13353. }
  13354. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13355. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  13356. }
  13357. _gl.uniformMatrix4fv( location, false, uniform._array );
  13358. break;
  13359. case 't':
  13360. // single THREE.Texture (2d or cube)
  13361. texture = value;
  13362. textureUnit = getTextureUnit();
  13363. _gl.uniform1i( location, textureUnit );
  13364. if ( ! texture ) continue;
  13365. if ( texture instanceof THREE.CubeTexture ||
  13366. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13367. // CompressedTexture can have Array in image :/
  13368. setCubeTexture( texture, textureUnit );
  13369. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  13370. setCubeTextureDynamic( texture, textureUnit );
  13371. } else {
  13372. _this.setTexture( texture, textureUnit );
  13373. }
  13374. break;
  13375. case 'tv':
  13376. // array of THREE.Texture (2d)
  13377. if ( uniform._array === undefined ) {
  13378. uniform._array = [];
  13379. }
  13380. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13381. uniform._array[ i ] = getTextureUnit();
  13382. }
  13383. _gl.uniform1iv( location, uniform._array );
  13384. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13385. texture = uniform.value[ i ];
  13386. textureUnit = uniform._array[ i ];
  13387. if ( ! texture ) continue;
  13388. _this.setTexture( texture, textureUnit );
  13389. }
  13390. break;
  13391. default:
  13392. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  13393. }
  13394. }
  13395. }
  13396. function setupMatrices( object, camera ) {
  13397. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13398. object._normalMatrix.getNormalMatrix( object._modelViewMatrix );
  13399. }
  13400. function setColorLinear( array, offset, color, intensity ) {
  13401. array[ offset + 0 ] = color.r * intensity;
  13402. array[ offset + 1 ] = color.g * intensity;
  13403. array[ offset + 2 ] = color.b * intensity;
  13404. }
  13405. function setupLights ( lights ) {
  13406. var l, ll, light,
  13407. r = 0, g = 0, b = 0,
  13408. color, skyColor, groundColor,
  13409. intensity,
  13410. distance,
  13411. zlights = _lights,
  13412. dirColors = zlights.directional.colors,
  13413. dirPositions = zlights.directional.positions,
  13414. pointColors = zlights.point.colors,
  13415. pointPositions = zlights.point.positions,
  13416. pointDistances = zlights.point.distances,
  13417. pointDecays = zlights.point.decays,
  13418. spotColors = zlights.spot.colors,
  13419. spotPositions = zlights.spot.positions,
  13420. spotDistances = zlights.spot.distances,
  13421. spotDirections = zlights.spot.directions,
  13422. spotAnglesCos = zlights.spot.anglesCos,
  13423. spotExponents = zlights.spot.exponents,
  13424. spotDecays = zlights.spot.decays,
  13425. hemiSkyColors = zlights.hemi.skyColors,
  13426. hemiGroundColors = zlights.hemi.groundColors,
  13427. hemiPositions = zlights.hemi.positions,
  13428. dirLength = 0,
  13429. pointLength = 0,
  13430. spotLength = 0,
  13431. hemiLength = 0,
  13432. dirCount = 0,
  13433. pointCount = 0,
  13434. spotCount = 0,
  13435. hemiCount = 0,
  13436. dirOffset = 0,
  13437. pointOffset = 0,
  13438. spotOffset = 0,
  13439. hemiOffset = 0;
  13440. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  13441. light = lights[ l ];
  13442. if ( light.onlyShadow ) continue;
  13443. color = light.color;
  13444. intensity = light.intensity;
  13445. distance = light.distance;
  13446. if ( light instanceof THREE.AmbientLight ) {
  13447. if ( ! light.visible ) continue;
  13448. r += color.r;
  13449. g += color.g;
  13450. b += color.b;
  13451. } else if ( light instanceof THREE.DirectionalLight ) {
  13452. dirCount += 1;
  13453. if ( ! light.visible ) continue;
  13454. _direction.setFromMatrixPosition( light.matrixWorld );
  13455. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13456. _direction.sub( _vector3 );
  13457. _direction.normalize();
  13458. dirOffset = dirLength * 3;
  13459. dirPositions[ dirOffset + 0 ] = _direction.x;
  13460. dirPositions[ dirOffset + 1 ] = _direction.y;
  13461. dirPositions[ dirOffset + 2 ] = _direction.z;
  13462. setColorLinear( dirColors, dirOffset, color, intensity );
  13463. dirLength += 1;
  13464. } else if ( light instanceof THREE.PointLight ) {
  13465. pointCount += 1;
  13466. if ( ! light.visible ) continue;
  13467. pointOffset = pointLength * 3;
  13468. setColorLinear( pointColors, pointOffset, color, intensity );
  13469. _vector3.setFromMatrixPosition( light.matrixWorld );
  13470. pointPositions[ pointOffset + 0 ] = _vector3.x;
  13471. pointPositions[ pointOffset + 1 ] = _vector3.y;
  13472. pointPositions[ pointOffset + 2 ] = _vector3.z;
  13473. // distance is 0 if decay is 0, because there is no attenuation at all.
  13474. pointDistances[ pointLength ] = distance;
  13475. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13476. pointLength += 1;
  13477. } else if ( light instanceof THREE.SpotLight ) {
  13478. spotCount += 1;
  13479. if ( ! light.visible ) continue;
  13480. spotOffset = spotLength * 3;
  13481. setColorLinear( spotColors, spotOffset, color, intensity );
  13482. _direction.setFromMatrixPosition( light.matrixWorld );
  13483. spotPositions[ spotOffset + 0 ] = _direction.x;
  13484. spotPositions[ spotOffset + 1 ] = _direction.y;
  13485. spotPositions[ spotOffset + 2 ] = _direction.z;
  13486. spotDistances[ spotLength ] = distance;
  13487. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13488. _direction.sub( _vector3 );
  13489. _direction.normalize();
  13490. spotDirections[ spotOffset + 0 ] = _direction.x;
  13491. spotDirections[ spotOffset + 1 ] = _direction.y;
  13492. spotDirections[ spotOffset + 2 ] = _direction.z;
  13493. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  13494. spotExponents[ spotLength ] = light.exponent;
  13495. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13496. spotLength += 1;
  13497. } else if ( light instanceof THREE.HemisphereLight ) {
  13498. hemiCount += 1;
  13499. if ( ! light.visible ) continue;
  13500. _direction.setFromMatrixPosition( light.matrixWorld );
  13501. _direction.normalize();
  13502. hemiOffset = hemiLength * 3;
  13503. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  13504. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  13505. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  13506. skyColor = light.color;
  13507. groundColor = light.groundColor;
  13508. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  13509. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  13510. hemiLength += 1;
  13511. }
  13512. }
  13513. // null eventual remains from removed lights
  13514. // (this is to avoid if in shader)
  13515. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  13516. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  13517. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  13518. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  13519. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  13520. zlights.directional.length = dirLength;
  13521. zlights.point.length = pointLength;
  13522. zlights.spot.length = spotLength;
  13523. zlights.hemi.length = hemiLength;
  13524. zlights.ambient[ 0 ] = r;
  13525. zlights.ambient[ 1 ] = g;
  13526. zlights.ambient[ 2 ] = b;
  13527. }
  13528. // GL state setting
  13529. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  13530. if ( cullFace === THREE.CullFaceNone ) {
  13531. state.disable( _gl.CULL_FACE );
  13532. } else {
  13533. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  13534. _gl.frontFace( _gl.CW );
  13535. } else {
  13536. _gl.frontFace( _gl.CCW );
  13537. }
  13538. if ( cullFace === THREE.CullFaceBack ) {
  13539. _gl.cullFace( _gl.BACK );
  13540. } else if ( cullFace === THREE.CullFaceFront ) {
  13541. _gl.cullFace( _gl.FRONT );
  13542. } else {
  13543. _gl.cullFace( _gl.FRONT_AND_BACK );
  13544. }
  13545. state.enable( _gl.CULL_FACE );
  13546. }
  13547. };
  13548. // Textures
  13549. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  13550. var extension;
  13551. if ( isImagePowerOfTwo ) {
  13552. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  13553. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  13554. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  13555. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  13556. } else {
  13557. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  13558. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  13559. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  13560. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. ( ' + texture.sourceFile + ' )' );
  13561. }
  13562. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  13563. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  13564. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  13565. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. ( ' + texture.sourceFile + ' )' );
  13566. }
  13567. }
  13568. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13569. if ( extension && texture.type !== THREE.FloatType && texture.type !== THREE.HalfFloatType ) {
  13570. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  13571. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  13572. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  13573. }
  13574. }
  13575. }
  13576. function uploadTexture( textureProperties, texture, slot ) {
  13577. if ( textureProperties.__webglInit === undefined ) {
  13578. textureProperties.__webglInit = true;
  13579. texture.__webglInit = true;
  13580. texture.addEventListener( 'dispose', onTextureDispose );
  13581. textureProperties.__webglTexture = _gl.createTexture();
  13582. _infoMemory.textures ++;
  13583. }
  13584. state.activeTexture( _gl.TEXTURE0 + slot );
  13585. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  13586. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13587. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  13588. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  13589. texture.image = clampToMaxSize( texture.image, _maxTextureSize );
  13590. var image = texture.image,
  13591. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13592. glFormat = paramThreeToGL( texture.format ),
  13593. glType = paramThreeToGL( texture.type );
  13594. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  13595. var mipmap, mipmaps = texture.mipmaps;
  13596. if ( texture instanceof THREE.DataTexture ) {
  13597. // use manually created mipmaps if available
  13598. // if there are no manual mipmaps
  13599. // set 0 level mipmap and then use GL to generate other mipmap levels
  13600. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13601. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13602. mipmap = mipmaps[ i ];
  13603. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13604. }
  13605. texture.generateMipmaps = false;
  13606. } else {
  13607. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13608. }
  13609. } else if ( texture instanceof THREE.CompressedTexture ) {
  13610. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13611. mipmap = mipmaps[ i ];
  13612. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13613. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  13614. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13615. } else {
  13616. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  13617. }
  13618. } else {
  13619. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13620. }
  13621. }
  13622. } else {
  13623. // regular Texture (image, video, canvas)
  13624. // use manually created mipmaps if available
  13625. // if there are no manual mipmaps
  13626. // set 0 level mipmap and then use GL to generate other mipmap levels
  13627. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13628. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13629. mipmap = mipmaps[ i ];
  13630. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  13631. }
  13632. texture.generateMipmaps = false;
  13633. } else {
  13634. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  13635. }
  13636. }
  13637. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13638. textureProperties.__version = texture.version;
  13639. if ( texture.onUpdate ) texture.onUpdate( texture );
  13640. }
  13641. this.setTexture = function ( texture, slot ) {
  13642. var textureProperties = properties.get( texture );
  13643. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13644. var image = texture.image;
  13645. if ( image === undefined ) {
  13646. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  13647. return;
  13648. }
  13649. if ( image.complete === false ) {
  13650. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  13651. return;
  13652. }
  13653. uploadTexture( textureProperties, texture, slot );
  13654. return;
  13655. }
  13656. state.activeTexture( _gl.TEXTURE0 + slot );
  13657. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  13658. };
  13659. function clampToMaxSize ( image, maxSize ) {
  13660. if ( image.width > maxSize || image.height > maxSize ) {
  13661. // Warning: Scaling through the canvas will only work with images that use
  13662. // premultiplied alpha.
  13663. var scale = maxSize / Math.max( image.width, image.height );
  13664. var canvas = document.createElement( 'canvas' );
  13665. canvas.width = Math.floor( image.width * scale );
  13666. canvas.height = Math.floor( image.height * scale );
  13667. var context = canvas.getContext( '2d' );
  13668. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  13669. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  13670. return canvas;
  13671. }
  13672. return image;
  13673. }
  13674. function setCubeTexture ( texture, slot ) {
  13675. var textureProperties = properties.get( texture );
  13676. if ( texture.image.length === 6 ) {
  13677. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13678. if ( ! textureProperties.__image__webglTextureCube ) {
  13679. texture.addEventListener( 'dispose', onTextureDispose );
  13680. textureProperties.__image__webglTextureCube = _gl.createTexture();
  13681. _infoMemory.textures ++;
  13682. }
  13683. state.activeTexture( _gl.TEXTURE0 + slot );
  13684. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13685. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13686. var isCompressed = texture instanceof THREE.CompressedTexture;
  13687. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  13688. var cubeImage = [];
  13689. for ( var i = 0; i < 6; i ++ ) {
  13690. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  13691. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], _maxCubemapSize );
  13692. } else {
  13693. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13694. }
  13695. }
  13696. var image = cubeImage[ 0 ],
  13697. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13698. glFormat = paramThreeToGL( texture.format ),
  13699. glType = paramThreeToGL( texture.type );
  13700. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  13701. for ( var i = 0; i < 6; i ++ ) {
  13702. if ( ! isCompressed ) {
  13703. if ( isDataTexture ) {
  13704. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  13705. } else {
  13706. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  13707. }
  13708. } else {
  13709. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  13710. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  13711. mipmap = mipmaps[ j ];
  13712. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13713. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  13714. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13715. } else {
  13716. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  13717. }
  13718. } else {
  13719. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13720. }
  13721. }
  13722. }
  13723. }
  13724. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  13725. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13726. }
  13727. textureProperties.__version = texture.version;
  13728. if ( texture.onUpdate ) texture.onUpdate( texture );
  13729. } else {
  13730. state.activeTexture( _gl.TEXTURE0 + slot );
  13731. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13732. }
  13733. }
  13734. }
  13735. function setCubeTextureDynamic ( texture, slot ) {
  13736. state.activeTexture( _gl.TEXTURE0 + slot );
  13737. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  13738. }
  13739. // Render targets
  13740. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  13741. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13742. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget ).__webglTexture, 0 );
  13743. }
  13744. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  13745. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  13746. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13747. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  13748. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13749. /* For some reason this is not working. Defaulting to RGBA4.
  13750. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13751. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  13752. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13753. */
  13754. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13755. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  13756. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13757. } else {
  13758. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  13759. }
  13760. }
  13761. this.setRenderTarget = function ( renderTarget ) {
  13762. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  13763. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  13764. var renderTargetProperties = properties.get( renderTarget );
  13765. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  13766. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  13767. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13768. renderTargetProperties.__webglTexture = _gl.createTexture();
  13769. _infoMemory.textures ++;
  13770. // Setup texture, create render and frame buffers
  13771. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
  13772. glFormat = paramThreeToGL( renderTarget.format ),
  13773. glType = paramThreeToGL( renderTarget.type );
  13774. if ( isCube ) {
  13775. renderTargetProperties.__webglFramebuffer = [];
  13776. renderTargetProperties.__webglRenderbuffer = [];
  13777. state.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTargetProperties.__webglTexture );
  13778. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
  13779. for ( var i = 0; i < 6; i ++ ) {
  13780. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13781. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  13782. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13783. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  13784. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  13785. }
  13786. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13787. } else {
  13788. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13789. if ( renderTarget.shareDepthFrom ) {
  13790. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  13791. } else {
  13792. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  13793. }
  13794. state.bindTexture( _gl.TEXTURE_2D, renderTargetProperties.__webglTexture );
  13795. setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
  13796. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13797. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  13798. if ( renderTarget.shareDepthFrom ) {
  13799. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13800. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13801. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13802. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13803. }
  13804. } else {
  13805. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  13806. }
  13807. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13808. }
  13809. // Release everything
  13810. if ( isCube ) {
  13811. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13812. } else {
  13813. state.bindTexture( _gl.TEXTURE_2D, null );
  13814. }
  13815. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  13816. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  13817. }
  13818. var framebuffer, width, height, vx, vy;
  13819. if ( renderTarget ) {
  13820. var renderTargetProperties = properties.get( renderTarget );
  13821. if ( isCube ) {
  13822. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  13823. } else {
  13824. framebuffer = renderTargetProperties.__webglFramebuffer;
  13825. }
  13826. width = renderTarget.width;
  13827. height = renderTarget.height;
  13828. vx = 0;
  13829. vy = 0;
  13830. } else {
  13831. framebuffer = null;
  13832. width = _viewportWidth;
  13833. height = _viewportHeight;
  13834. vx = _viewportX;
  13835. vy = _viewportY;
  13836. }
  13837. if ( framebuffer !== _currentFramebuffer ) {
  13838. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13839. _gl.viewport( vx, vy, width, height );
  13840. _currentFramebuffer = framebuffer;
  13841. }
  13842. _currentWidth = width;
  13843. _currentHeight = height;
  13844. };
  13845. this.readRenderTargetPixels = function( renderTarget, x, y, width, height, buffer ) {
  13846. if ( ! ( renderTarget instanceof THREE.WebGLRenderTarget ) ) {
  13847. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  13848. return;
  13849. }
  13850. if ( properties.get( renderTarget ).__webglFramebuffer ) {
  13851. if ( renderTarget.format !== THREE.RGBAFormat ) {
  13852. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA format. readPixels can read only RGBA format.' );
  13853. return;
  13854. }
  13855. var restore = false;
  13856. if ( properties.get( renderTarget ).__webglFramebuffer !== _currentFramebuffer ) {
  13857. _gl.bindFramebuffer( _gl.FRAMEBUFFER, properties.get( renderTarget ).__webglFramebuffer );
  13858. restore = true;
  13859. }
  13860. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  13861. _gl.readPixels( x, y, width, height, _gl.RGBA, _gl.UNSIGNED_BYTE, buffer );
  13862. } else {
  13863. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  13864. }
  13865. if ( restore ) {
  13866. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  13867. }
  13868. }
  13869. };
  13870. function updateRenderTargetMipmap ( renderTarget ) {
  13871. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  13872. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( renderTarget ).__webglTexture );
  13873. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13874. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13875. } else {
  13876. state.bindTexture( _gl.TEXTURE_2D, properties.get( renderTarget ).__webglTexture );
  13877. _gl.generateMipmap( _gl.TEXTURE_2D );
  13878. state.bindTexture( _gl.TEXTURE_2D, null );
  13879. }
  13880. }
  13881. // Fallback filters for non-power-of-2 textures
  13882. function filterFallback ( f ) {
  13883. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  13884. return _gl.NEAREST;
  13885. }
  13886. return _gl.LINEAR;
  13887. }
  13888. // Map three.js constants to WebGL constants
  13889. function paramThreeToGL ( p ) {
  13890. var extension;
  13891. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  13892. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  13893. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  13894. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  13895. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  13896. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  13897. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  13898. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  13899. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  13900. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  13901. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  13902. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  13903. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  13904. if ( p === THREE.ByteType ) return _gl.BYTE;
  13905. if ( p === THREE.ShortType ) return _gl.SHORT;
  13906. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  13907. if ( p === THREE.IntType ) return _gl.INT;
  13908. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  13909. if ( p === THREE.FloatType ) return _gl.FLOAT;
  13910. extension = extensions.get( 'OES_texture_half_float' );
  13911. if ( extension !== null ) {
  13912. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  13913. }
  13914. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  13915. if ( p === THREE.RGBFormat ) return _gl.RGB;
  13916. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  13917. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  13918. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  13919. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  13920. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  13921. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  13922. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  13923. if ( p === THREE.OneFactor ) return _gl.ONE;
  13924. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  13925. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  13926. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  13927. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  13928. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  13929. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  13930. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  13931. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  13932. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  13933. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13934. if ( extension !== null ) {
  13935. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13936. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13937. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13938. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13939. }
  13940. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13941. if ( extension !== null ) {
  13942. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13943. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13944. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13945. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13946. }
  13947. extension = extensions.get( 'EXT_blend_minmax' );
  13948. if ( extension !== null ) {
  13949. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  13950. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  13951. }
  13952. return 0;
  13953. }
  13954. // Allocations
  13955. function allocateBones ( object ) {
  13956. if ( _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  13957. return 1024;
  13958. } else {
  13959. // default for when object is not specified
  13960. // ( for example when prebuilding shader to be used with multiple objects )
  13961. //
  13962. // - leave some extra space for other uniforms
  13963. // - limit here is ANGLE's 254 max uniform vectors
  13964. // (up to 54 should be safe)
  13965. var nVertexUniforms = _gl.getParameter( _gl.MAX_VERTEX_UNIFORM_VECTORS );
  13966. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  13967. var maxBones = nVertexMatrices;
  13968. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  13969. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  13970. if ( maxBones < object.skeleton.bones.length ) {
  13971. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  13972. }
  13973. }
  13974. return maxBones;
  13975. }
  13976. }
  13977. function allocateLights( lights ) {
  13978. var dirLights = 0;
  13979. var pointLights = 0;
  13980. var spotLights = 0;
  13981. var hemiLights = 0;
  13982. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13983. var light = lights[ l ];
  13984. if ( light.onlyShadow || light.visible === false ) continue;
  13985. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  13986. if ( light instanceof THREE.PointLight ) pointLights ++;
  13987. if ( light instanceof THREE.SpotLight ) spotLights ++;
  13988. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  13989. }
  13990. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  13991. }
  13992. function allocateShadows( lights ) {
  13993. var maxShadows = 0;
  13994. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13995. var light = lights[ l ];
  13996. if ( ! light.castShadow ) continue;
  13997. if ( light instanceof THREE.SpotLight ) maxShadows ++;
  13998. if ( light instanceof THREE.DirectionalLight ) maxShadows ++;
  13999. }
  14000. return maxShadows;
  14001. }
  14002. // DEPRECATED
  14003. this.supportsFloatTextures = function () {
  14004. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  14005. return extensions.get( 'OES_texture_float' );
  14006. };
  14007. this.supportsHalfFloatTextures = function () {
  14008. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  14009. return extensions.get( 'OES_texture_half_float' );
  14010. };
  14011. this.supportsStandardDerivatives = function () {
  14012. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  14013. return extensions.get( 'OES_standard_derivatives' );
  14014. };
  14015. this.supportsCompressedTextureS3TC = function () {
  14016. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  14017. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14018. };
  14019. this.supportsCompressedTexturePVRTC = function () {
  14020. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  14021. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14022. };
  14023. this.supportsBlendMinMax = function () {
  14024. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  14025. return extensions.get( 'EXT_blend_minmax' );
  14026. };
  14027. this.initMaterial = function () {
  14028. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  14029. };
  14030. this.addPrePlugin = function () {
  14031. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  14032. };
  14033. this.addPostPlugin = function () {
  14034. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  14035. };
  14036. this.updateShadowMap = function () {
  14037. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  14038. };
  14039. Object.defineProperties( this, {
  14040. shadowMapEnabled: {
  14041. get: function () {
  14042. return shadowMap.enabled;
  14043. },
  14044. set: function ( value ) {
  14045. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  14046. shadowMap.enabled = value;
  14047. }
  14048. },
  14049. shadowMapType: {
  14050. get: function () {
  14051. return shadowMap.type;
  14052. },
  14053. set: function ( value ) {
  14054. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  14055. shadowMap.type = value;
  14056. }
  14057. },
  14058. shadowMapCullFace: {
  14059. get: function () {
  14060. return shadowMap.cullFace;
  14061. },
  14062. set: function ( value ) {
  14063. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  14064. shadowMap.cullFace = value;
  14065. }
  14066. },
  14067. shadowMapDebug: {
  14068. get: function () {
  14069. return shadowMap.debug;
  14070. },
  14071. set: function ( value ) {
  14072. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  14073. shadowMap.debug = value;
  14074. }
  14075. }
  14076. } );
  14077. };
  14078. // File:src/renderers/WebGLRenderTarget.js
  14079. /**
  14080. * @author szimek / https://github.com/szimek/
  14081. * @author alteredq / http://alteredqualia.com/
  14082. */
  14083. THREE.WebGLRenderTarget = function ( width, height, options ) {
  14084. this.uuid = THREE.Math.generateUUID();
  14085. this.width = width;
  14086. this.height = height;
  14087. options = options || {};
  14088. this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
  14089. this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
  14090. this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
  14091. this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
  14092. this.anisotropy = options.anisotropy !== undefined ? options.anisotropy : 1;
  14093. this.offset = new THREE.Vector2( 0, 0 );
  14094. this.repeat = new THREE.Vector2( 1, 1 );
  14095. this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
  14096. this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
  14097. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  14098. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  14099. this.generateMipmaps = true;
  14100. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  14101. };
  14102. THREE.WebGLRenderTarget.prototype = {
  14103. constructor: THREE.WebGLRenderTarget,
  14104. setSize: function ( width, height ) {
  14105. if ( this.width !== width || this.height !== height ) {
  14106. this.width = width;
  14107. this.height = height;
  14108. this.dispose();
  14109. }
  14110. },
  14111. copy: function ( source ) {
  14112. this.width = source.width;
  14113. this.height = source.height;
  14114. this.wrapS = source.wrapS;
  14115. this.wrapT = source.wrapT;
  14116. this.magFilter = source.magFilter;
  14117. this.minFilter = source.minFilter;
  14118. this.anisotropy = source.anisotropy;
  14119. this.offset.copy( source.offset );
  14120. this.repeat.copy( source.repeat );
  14121. this.format = source.format;
  14122. this.type = source.type;
  14123. this.depthBuffer = source.depthBuffer;
  14124. this.stencilBuffer = source.stencilBuffer;
  14125. this.generateMipmaps = source.generateMipmaps;
  14126. this.shareDepthFrom = source.shareDepthFrom;
  14127. return this;
  14128. },
  14129. clone: function () {
  14130. return new THREE.WebGLRenderTarget().copy( this );
  14131. },
  14132. dispose: function () {
  14133. this.dispatchEvent( { type: 'dispose' } );
  14134. }
  14135. };
  14136. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  14137. // File:src/renderers/WebGLRenderTargetCube.js
  14138. /**
  14139. * @author alteredq / http://alteredqualia.com
  14140. */
  14141. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  14142. THREE.WebGLRenderTarget.call( this, width, height, options );
  14143. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  14144. };
  14145. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  14146. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  14147. // File:src/renderers/webgl/WebGLExtensions.js
  14148. /**
  14149. * @author mrdoob / http://mrdoob.com/
  14150. */
  14151. THREE.WebGLExtensions = function ( gl ) {
  14152. var extensions = {};
  14153. this.get = function ( name ) {
  14154. if ( extensions[ name ] !== undefined ) {
  14155. return extensions[ name ];
  14156. }
  14157. var extension;
  14158. switch ( name ) {
  14159. case 'EXT_texture_filter_anisotropic':
  14160. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  14161. break;
  14162. case 'WEBGL_compressed_texture_s3tc':
  14163. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  14164. break;
  14165. case 'WEBGL_compressed_texture_pvrtc':
  14166. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  14167. break;
  14168. default:
  14169. extension = gl.getExtension( name );
  14170. }
  14171. if ( extension === null ) {
  14172. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  14173. }
  14174. extensions[ name ] = extension;
  14175. return extension;
  14176. };
  14177. };
  14178. // File:src/renderers/webgl/WebGLGeometries.js
  14179. /**
  14180. * @author mrdoob / http://mrdoob.com/
  14181. */
  14182. THREE.WebGLGeometries = function ( gl, properties, info ) {
  14183. var geometries = {};
  14184. this.get = function ( object ) {
  14185. var geometry = object.geometry;
  14186. if ( geometries[ geometry.id ] !== undefined ) {
  14187. return geometries[ geometry.id ];
  14188. }
  14189. geometry.addEventListener( 'dispose', onGeometryDispose );
  14190. if ( geometry instanceof THREE.BufferGeometry ) {
  14191. geometries[ geometry.id ] = geometry;
  14192. } else if ( geometry instanceof THREE.Geometry ) {
  14193. if ( geometry._bufferGeometry === undefined ) {
  14194. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  14195. }
  14196. geometries[ geometry.id ] = geometry._bufferGeometry;
  14197. }
  14198. info.memory.geometries ++;
  14199. return geometries[ geometry.id ];
  14200. };
  14201. function onGeometryDispose( event ) {
  14202. var geometry = event.target;
  14203. var buffergeometry = geometries[ geometry.id ];
  14204. for ( var name in buffergeometry.attributes ) {
  14205. var attribute = buffergeometry.attributes[ name ];
  14206. var buffer = getAttributeBuffer( attribute );
  14207. if ( buffer !== undefined ) {
  14208. gl.deleteBuffer( buffer );
  14209. removeAttributeBuffer( attribute );
  14210. }
  14211. }
  14212. geometry.removeEventListener( 'dispose', onGeometryDispose );
  14213. delete geometries[ geometry.id ];
  14214. info.memory.geometries --;
  14215. }
  14216. function getAttributeBuffer( attribute ) {
  14217. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14218. return properties.get( attribute.data ).__webglBuffer;
  14219. }
  14220. return properties.get( attribute ).__webglBuffer;
  14221. }
  14222. function removeAttributeBuffer( attribute ) {
  14223. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14224. properties.delete( attribute.data );
  14225. } else {
  14226. properties.delete( attribute );
  14227. }
  14228. }
  14229. };
  14230. // File:src/renderers/webgl/WebGLObjects.js
  14231. /**
  14232. * @author mrdoob / http://mrdoob.com/
  14233. */
  14234. THREE.WebGLObjects = function ( gl, properties, info ) {
  14235. var objects = {};
  14236. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  14237. //
  14238. function onObjectRemoved( event ) {
  14239. var object = event.target;
  14240. object.traverse( function ( child ) {
  14241. child.removeEventListener( 'remove', onObjectRemoved );
  14242. removeObject( child );
  14243. } );
  14244. }
  14245. function removeObject( object ) {
  14246. if ( object instanceof THREE.Mesh ||
  14247. object instanceof THREE.PointCloud ||
  14248. object instanceof THREE.Line ) {
  14249. delete objects[ object.id ];
  14250. }
  14251. delete object._modelViewMatrix;
  14252. delete object._normalMatrix;
  14253. properties.delete( object );
  14254. }
  14255. //
  14256. this.objects = objects;
  14257. this.geometries = geometries;
  14258. this.init = function ( object ) {
  14259. var objectProperties = properties.get( object );
  14260. if ( objectProperties.__webglInit === undefined ) {
  14261. objectProperties.__webglInit = true;
  14262. object._modelViewMatrix = new THREE.Matrix4();
  14263. object._normalMatrix = new THREE.Matrix3();
  14264. object.addEventListener( 'removed', onObjectRemoved );
  14265. }
  14266. if ( objectProperties.__webglActive === undefined ) {
  14267. objectProperties.__webglActive = true;
  14268. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.PointCloud ) {
  14269. objects[ object.id ] = {
  14270. id: object.id,
  14271. object: object,
  14272. z: 0
  14273. };
  14274. }
  14275. }
  14276. };
  14277. function updateObject( object ) {
  14278. var geometry = geometries.get( object );
  14279. if ( object.geometry instanceof THREE.Geometry ) {
  14280. geometry.updateFromObject( object );
  14281. }
  14282. var attributes = geometry.attributes;
  14283. for ( var name in attributes ) {
  14284. updateAttribute( attributes[ name ], name );
  14285. }
  14286. // morph targets
  14287. var morphAttributes = geometry.morphAttributes;
  14288. for ( var name in morphAttributes ) {
  14289. var array = morphAttributes[ name ];
  14290. for ( var i = 0, l = array.length; i < l; i ++ ) {
  14291. updateAttribute( array[ i ], i );
  14292. }
  14293. }
  14294. }
  14295. function updateAttribute( attribute, name ) {
  14296. var bufferType = ( name === 'index' ) ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
  14297. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  14298. var attributeProperties = properties.get( data );
  14299. if ( attributeProperties.__webglBuffer === undefined ) {
  14300. createBuffer( attributeProperties, data, bufferType );
  14301. } else if ( attributeProperties.version !== data.version ) {
  14302. updateBuffer( attributeProperties, data, bufferType );
  14303. }
  14304. }
  14305. function createBuffer( attributeProperties, data, bufferType ) {
  14306. attributeProperties.__webglBuffer = gl.createBuffer();
  14307. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  14308. var usage = gl.STATIC_DRAW;
  14309. if ( data instanceof THREE.DynamicBufferAttribute
  14310. || ( data instanceof THREE.InstancedBufferAttribute && data.dynamic === true )
  14311. || ( data instanceof THREE.InterleavedBuffer && data.dynamic === true ) ) {
  14312. usage = gl.DYNAMIC_DRAW;
  14313. }
  14314. gl.bufferData( bufferType, data.array, usage );
  14315. attributeProperties.version = data.version;
  14316. }
  14317. function updateBuffer( attributeProperties, data, bufferType ) {
  14318. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  14319. if ( data.updateRange === undefined || data.updateRange.count === - 1 ) {
  14320. // Not using update ranges
  14321. gl.bufferSubData( bufferType, 0, data.array );
  14322. } else if ( data.updateRange.count === 0 ) {
  14323. 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.' );
  14324. } else {
  14325. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  14326. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  14327. data.updateRange.count = 0; // reset range
  14328. }
  14329. attributeProperties.version = data.version;
  14330. }
  14331. // returns the webgl buffer for a specified attribute
  14332. this.getAttributeBuffer = function ( attribute ) {
  14333. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14334. return properties.get( attribute.data ).__webglBuffer;
  14335. }
  14336. return properties.get( attribute ).__webglBuffer;
  14337. };
  14338. this.update = function ( renderList ) {
  14339. for ( var i = 0, ul = renderList.length; i < ul; i ++ ) {
  14340. updateObject( renderList[ i ].object );
  14341. }
  14342. };
  14343. this.clear = function () {
  14344. objects = {};
  14345. };
  14346. };
  14347. // File:src/renderers/webgl/WebGLProgram.js
  14348. THREE.WebGLProgram = ( function () {
  14349. var programIdCount = 0;
  14350. function generateDefines( defines ) {
  14351. var chunks = [];
  14352. for ( var name in defines ) {
  14353. var value = defines[ name ];
  14354. if ( value === false ) continue;
  14355. chunks.push( '#define ' + name + ' ' + value );
  14356. }
  14357. return chunks.join( '\n' );
  14358. }
  14359. function fetchUniformLocations( gl, program, identifiers ) {
  14360. var uniforms = {};
  14361. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  14362. for ( var i = 0; i < n; i ++ ) {
  14363. var info = gl.getActiveUniform( program, i );
  14364. var name = info.name;
  14365. var location = gl.getUniformLocation( program, name );
  14366. // console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  14367. var suffixPos = name.lastIndexOf( '[0]' );
  14368. if ( suffixPos !== - 1 && suffixPos === name.length - 3 ) {
  14369. uniforms[ name.substr( 0, suffixPos ) ] = location;
  14370. }
  14371. uniforms[ name ] = location;
  14372. }
  14373. return uniforms;
  14374. }
  14375. function fetchAttributeLocations( gl, program, identifiers ) {
  14376. var attributes = {};
  14377. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  14378. for ( var i = 0; i < n; i ++ ) {
  14379. var info = gl.getActiveAttrib( program, i );
  14380. var name = info.name;
  14381. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  14382. attributes[ name ] = gl.getAttribLocation( program, name );
  14383. }
  14384. return attributes;
  14385. }
  14386. function filterEmptyLine( string ) {
  14387. return string !== '';
  14388. }
  14389. return function WebGLProgram( renderer, code, material, parameters ) {
  14390. var gl = renderer.context;
  14391. var defines = material.defines;
  14392. var vertexShader = material.__webglShader.vertexShader;
  14393. var fragmentShader = material.__webglShader.fragmentShader;
  14394. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  14395. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  14396. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  14397. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  14398. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  14399. }
  14400. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14401. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  14402. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14403. if ( parameters.envMap ) {
  14404. switch ( material.envMap.mapping ) {
  14405. case THREE.CubeReflectionMapping:
  14406. case THREE.CubeRefractionMapping:
  14407. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14408. break;
  14409. case THREE.EquirectangularReflectionMapping:
  14410. case THREE.EquirectangularRefractionMapping:
  14411. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  14412. break;
  14413. case THREE.SphericalReflectionMapping:
  14414. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  14415. break;
  14416. }
  14417. switch ( material.envMap.mapping ) {
  14418. case THREE.CubeRefractionMapping:
  14419. case THREE.EquirectangularRefractionMapping:
  14420. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  14421. break;
  14422. }
  14423. switch ( material.combine ) {
  14424. case THREE.MultiplyOperation:
  14425. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14426. break;
  14427. case THREE.MixOperation:
  14428. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  14429. break;
  14430. case THREE.AddOperation:
  14431. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  14432. break;
  14433. }
  14434. }
  14435. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  14436. // console.log( 'building new program ' );
  14437. //
  14438. var customDefines = generateDefines( defines );
  14439. //
  14440. var program = gl.createProgram();
  14441. var prefixVertex, prefixFragment;
  14442. if ( material instanceof THREE.RawShaderMaterial ) {
  14443. prefixVertex = '';
  14444. prefixFragment = '';
  14445. } else {
  14446. prefixVertex = [
  14447. 'precision ' + parameters.precision + ' float;',
  14448. 'precision ' + parameters.precision + ' int;',
  14449. '#define SHADER_NAME ' + material.__webglShader.name,
  14450. customDefines,
  14451. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  14452. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14453. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14454. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14455. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14456. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14457. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14458. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14459. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14460. '#define MAX_BONES ' + parameters.maxBones,
  14461. parameters.map ? '#define USE_MAP' : '',
  14462. parameters.envMap ? '#define USE_ENVMAP' : '',
  14463. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14464. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14465. parameters.aoMap ? '#define USE_AOMAP' : '',
  14466. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14467. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14468. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14469. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14470. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14471. parameters.vertexColors ? '#define USE_COLOR' : '',
  14472. parameters.flatShading ? '#define FLAT_SHADED' : '',
  14473. parameters.skinning ? '#define USE_SKINNING' : '',
  14474. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  14475. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  14476. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  14477. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14478. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14479. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14480. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14481. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14482. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  14483. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14484. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14485. 'uniform mat4 modelMatrix;',
  14486. 'uniform mat4 modelViewMatrix;',
  14487. 'uniform mat4 projectionMatrix;',
  14488. 'uniform mat4 viewMatrix;',
  14489. 'uniform mat3 normalMatrix;',
  14490. 'uniform vec3 cameraPosition;',
  14491. 'attribute vec3 position;',
  14492. 'attribute vec3 normal;',
  14493. 'attribute vec2 uv;',
  14494. '#ifdef USE_COLOR',
  14495. ' attribute vec3 color;',
  14496. '#endif',
  14497. '#ifdef USE_MORPHTARGETS',
  14498. ' attribute vec3 morphTarget0;',
  14499. ' attribute vec3 morphTarget1;',
  14500. ' attribute vec3 morphTarget2;',
  14501. ' attribute vec3 morphTarget3;',
  14502. ' #ifdef USE_MORPHNORMALS',
  14503. ' attribute vec3 morphNormal0;',
  14504. ' attribute vec3 morphNormal1;',
  14505. ' attribute vec3 morphNormal2;',
  14506. ' attribute vec3 morphNormal3;',
  14507. ' #else',
  14508. ' attribute vec3 morphTarget4;',
  14509. ' attribute vec3 morphTarget5;',
  14510. ' attribute vec3 morphTarget6;',
  14511. ' attribute vec3 morphTarget7;',
  14512. ' #endif',
  14513. '#endif',
  14514. '#ifdef USE_SKINNING',
  14515. ' attribute vec4 skinIndex;',
  14516. ' attribute vec4 skinWeight;',
  14517. '#endif',
  14518. '\n'
  14519. ].filter( filterEmptyLine ).join( '\n' );
  14520. prefixFragment = [
  14521. parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ? '#extension GL_OES_standard_derivatives : enable' : '',
  14522. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  14523. 'precision ' + parameters.precision + ' float;',
  14524. 'precision ' + parameters.precision + ' int;',
  14525. '#define SHADER_NAME ' + material.__webglShader.name,
  14526. customDefines,
  14527. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14528. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14529. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14530. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14531. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14532. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  14533. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14534. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14535. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14536. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  14537. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  14538. parameters.map ? '#define USE_MAP' : '',
  14539. parameters.envMap ? '#define USE_ENVMAP' : '',
  14540. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  14541. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14542. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  14543. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14544. parameters.aoMap ? '#define USE_AOMAP' : '',
  14545. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14546. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14547. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14548. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14549. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14550. parameters.vertexColors ? '#define USE_COLOR' : '',
  14551. parameters.flatShading ? '#define FLAT_SHADED' : '',
  14552. parameters.metal ? '#define METAL' : '',
  14553. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14554. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14555. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14556. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14557. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14558. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14559. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14560. 'uniform mat4 viewMatrix;',
  14561. 'uniform vec3 cameraPosition;',
  14562. '\n'
  14563. ].filter( filterEmptyLine ).join( '\n' );
  14564. }
  14565. var vertexGlsl = prefixVertex + vertexShader;
  14566. var fragmentGlsl = prefixFragment + fragmentShader;
  14567. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  14568. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  14569. gl.attachShader( program, glVertexShader );
  14570. gl.attachShader( program, glFragmentShader );
  14571. // Force a particular attribute to index 0.
  14572. if ( material.index0AttributeName !== undefined ) {
  14573. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  14574. } else if ( parameters.morphTargets === true ) {
  14575. // programs with morphTargets displace position out of attribute 0
  14576. gl.bindAttribLocation( program, 0, 'position' );
  14577. }
  14578. gl.linkProgram( program );
  14579. var programLog = gl.getProgramInfoLog( program );
  14580. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  14581. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  14582. var runnable = true;
  14583. var haveDiagnostics = true;
  14584. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  14585. runnable = false;
  14586. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  14587. } else if ( programLog !== '' ) {
  14588. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  14589. } else if ( vertexLog === '' || fragmentLog === '' ) {
  14590. haveDiagnostics = false;
  14591. }
  14592. if ( haveDiagnostics ) {
  14593. this.diagnostics = {
  14594. runnable: runnable,
  14595. material: material,
  14596. programLog: programLog,
  14597. vertexShader: {
  14598. log: vertexLog,
  14599. prefix: prefixVertex
  14600. },
  14601. fragmentShader: {
  14602. log: fragmentLog,
  14603. prefix: prefixFragment
  14604. }
  14605. };
  14606. }
  14607. // clean up
  14608. gl.deleteShader( glVertexShader );
  14609. gl.deleteShader( glFragmentShader );
  14610. // set up caching for uniform locations
  14611. var cachedUniforms;
  14612. this.getUniforms = function() {
  14613. if ( cachedUniforms === undefined ) {
  14614. cachedUniforms = fetchUniformLocations( gl, program );
  14615. }
  14616. return cachedUniforms;
  14617. };
  14618. // set up caching for attribute locations
  14619. var cachedAttributes;
  14620. this.getAttributes = function() {
  14621. if ( cachedAttributes === undefined ) {
  14622. cachedAttributes = fetchAttributeLocations( gl, program );
  14623. }
  14624. return cachedAttributes;
  14625. };
  14626. // DEPRECATED
  14627. Object.defineProperties( this, {
  14628. uniforms: {
  14629. get: function() {
  14630. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  14631. return this.getUniforms();
  14632. }
  14633. },
  14634. attributes: {
  14635. get: function() {
  14636. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  14637. return this.getAttributes();
  14638. }
  14639. }
  14640. } );
  14641. //
  14642. this.id = programIdCount ++;
  14643. this.code = code;
  14644. this.usedTimes = 1;
  14645. this.program = program;
  14646. this.vertexShader = glVertexShader;
  14647. this.fragmentShader = glFragmentShader;
  14648. return this;
  14649. };
  14650. } )();
  14651. // File:src/renderers/webgl/WebGLProperties.js
  14652. /**
  14653. * @author fordacious / fordacious.github.io
  14654. */
  14655. THREE.WebGLProperties = function () {
  14656. var properties = {};
  14657. this.get = function ( object ) {
  14658. var uuid = object.uuid;
  14659. var map = properties[ uuid ];
  14660. if ( map === undefined ) {
  14661. map = {};
  14662. properties[ uuid ] = map;
  14663. }
  14664. return map;
  14665. };
  14666. this.delete = function ( object ) {
  14667. delete properties[ object.uuid ];
  14668. };
  14669. this.clear = function () {
  14670. properties = {};
  14671. };
  14672. };
  14673. // File:src/renderers/webgl/WebGLShader.js
  14674. THREE.WebGLShader = ( function () {
  14675. var addLineNumbers = function ( string ) {
  14676. var lines = string.split( '\n' );
  14677. for ( var i = 0; i < lines.length; i ++ ) {
  14678. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  14679. }
  14680. return lines.join( '\n' );
  14681. };
  14682. return function WebGLShader( gl, type, string ) {
  14683. var shader = gl.createShader( type );
  14684. gl.shaderSource( shader, string );
  14685. gl.compileShader( shader );
  14686. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  14687. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  14688. }
  14689. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  14690. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  14691. }
  14692. // --enable-privileged-webgl-extension
  14693. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  14694. return shader;
  14695. };
  14696. } )();
  14697. // File:src/renderers/webgl/WebGLShadowMap.js
  14698. /**
  14699. * @author alteredq / http://alteredqualia.com/
  14700. * @author mrdoob / http://mrdoob.com/
  14701. */
  14702. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  14703. var _gl = _renderer.context,
  14704. _state = _renderer.state,
  14705. _frustum = new THREE.Frustum(),
  14706. _projScreenMatrix = new THREE.Matrix4(),
  14707. _min = new THREE.Vector3(),
  14708. _max = new THREE.Vector3(),
  14709. _matrixPosition = new THREE.Vector3(),
  14710. _renderList = [];
  14711. // init
  14712. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  14713. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  14714. var _depthMaterial = new THREE.ShaderMaterial( {
  14715. uniforms: depthUniforms,
  14716. vertexShader: depthShader.vertexShader,
  14717. fragmentShader: depthShader.fragmentShader
  14718. } );
  14719. var _depthMaterialMorph = new THREE.ShaderMaterial( {
  14720. uniforms: depthUniforms,
  14721. vertexShader: depthShader.vertexShader,
  14722. fragmentShader: depthShader.fragmentShader,
  14723. morphTargets: true
  14724. } );
  14725. var _depthMaterialSkin = new THREE.ShaderMaterial( {
  14726. uniforms: depthUniforms,
  14727. vertexShader: depthShader.vertexShader,
  14728. fragmentShader: depthShader.fragmentShader,
  14729. skinning: true
  14730. } );
  14731. var _depthMaterialMorphSkin = new THREE.ShaderMaterial( {
  14732. uniforms: depthUniforms,
  14733. vertexShader: depthShader.vertexShader,
  14734. fragmentShader: depthShader.fragmentShader,
  14735. morphTargets: true,
  14736. skinning: true
  14737. } );
  14738. _depthMaterial._shadowPass = true;
  14739. _depthMaterialMorph._shadowPass = true;
  14740. _depthMaterialSkin._shadowPass = true;
  14741. _depthMaterialMorphSkin._shadowPass = true;
  14742. //
  14743. var scope = this;
  14744. this.enabled = false;
  14745. this.autoUpdate = true;
  14746. this.needsUpdate = false;
  14747. this.type = THREE.PCFShadowMap;
  14748. this.cullFace = THREE.CullFaceFront;
  14749. this.render = function ( scene, camera ) {
  14750. if ( scope.enabled === false ) return;
  14751. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  14752. // set GL state for depth map
  14753. _gl.clearColor( 1, 1, 1, 1 );
  14754. _state.disable( _gl.BLEND );
  14755. _state.enable( _gl.CULL_FACE );
  14756. _gl.frontFace( _gl.CCW );
  14757. if ( scope.cullFace === THREE.CullFaceFront ) {
  14758. _gl.cullFace( _gl.FRONT );
  14759. } else {
  14760. _gl.cullFace( _gl.BACK );
  14761. }
  14762. _state.setDepthTest( true );
  14763. // render depth map
  14764. for ( var i = 0, il = _lights.length; i < il; i ++ ) {
  14765. var light = _lights[ i ];
  14766. if ( ! light.castShadow ) continue;
  14767. if ( ! light.shadowMap ) {
  14768. var shadowFilter = THREE.LinearFilter;
  14769. if ( scope.type === THREE.PCFSoftShadowMap ) {
  14770. shadowFilter = THREE.NearestFilter;
  14771. }
  14772. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  14773. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  14774. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  14775. light.shadowMatrix = new THREE.Matrix4();
  14776. }
  14777. if ( ! light.shadowCamera ) {
  14778. if ( light instanceof THREE.SpotLight ) {
  14779. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  14780. } else if ( light instanceof THREE.DirectionalLight ) {
  14781. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  14782. } else {
  14783. console.error( "THREE.ShadowMapPlugin: Unsupported light type for shadow", light );
  14784. continue;
  14785. }
  14786. scene.add( light.shadowCamera );
  14787. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14788. }
  14789. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  14790. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  14791. scene.add( light.cameraHelper );
  14792. }
  14793. var shadowMap = light.shadowMap;
  14794. var shadowMatrix = light.shadowMatrix;
  14795. var shadowCamera = light.shadowCamera;
  14796. //
  14797. shadowCamera.position.setFromMatrixPosition( light.matrixWorld );
  14798. _matrixPosition.setFromMatrixPosition( light.target.matrixWorld );
  14799. shadowCamera.lookAt( _matrixPosition );
  14800. shadowCamera.updateMatrixWorld();
  14801. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  14802. //
  14803. if ( light.cameraHelper ) light.cameraHelper.visible = light.shadowCameraVisible;
  14804. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  14805. // compute shadow matrix
  14806. shadowMatrix.set(
  14807. 0.5, 0.0, 0.0, 0.5,
  14808. 0.0, 0.5, 0.0, 0.5,
  14809. 0.0, 0.0, 0.5, 0.5,
  14810. 0.0, 0.0, 0.0, 1.0
  14811. );
  14812. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  14813. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  14814. // update camera matrices and frustum
  14815. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  14816. _frustum.setFromMatrix( _projScreenMatrix );
  14817. // render shadow map
  14818. _renderer.setRenderTarget( shadowMap );
  14819. _renderer.clear();
  14820. // set object matrices & frustum culling
  14821. _renderList.length = 0;
  14822. projectObject( scene, shadowCamera );
  14823. // render regular objects
  14824. var webglObject, object, material;
  14825. var objectMaterial, useMorphing, useSkinning;
  14826. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  14827. webglObject = _renderList[ j ];
  14828. object = webglObject.object;
  14829. objectMaterial = object.material;
  14830. if ( objectMaterial instanceof THREE.MeshFaceMaterial ) {
  14831. // For the moment just ignore objects that have multiple materials with different animation methods
  14832. // Only the first material will be taken into account for deciding which depth material to use for shadow maps
  14833. objectMaterial = object.material.materials[ 0 ];
  14834. if ( objectMaterial === null || objectMaterial.visible === false ) continue;
  14835. }
  14836. useMorphing = object.geometry.morphTargets !== undefined && object.geometry.morphTargets.length > 0 && objectMaterial.morphTargets;
  14837. useSkinning = object instanceof THREE.SkinnedMesh && objectMaterial.skinning;
  14838. if ( object.customDepthMaterial ) {
  14839. material = object.customDepthMaterial;
  14840. } else if ( useSkinning ) {
  14841. material = useMorphing ? _depthMaterialMorphSkin : _depthMaterialSkin;
  14842. } else if ( useMorphing ) {
  14843. material = _depthMaterialMorph;
  14844. } else {
  14845. material = _depthMaterial;
  14846. }
  14847. _renderer.renderBufferDirect( shadowCamera, _lights, null, material, object );
  14848. }
  14849. }
  14850. // restore GL state
  14851. var clearColor = _renderer.getClearColor(),
  14852. clearAlpha = _renderer.getClearAlpha();
  14853. _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
  14854. _state.enable( _gl.BLEND );
  14855. if ( scope.cullFace === THREE.CullFaceFront ) {
  14856. _gl.cullFace( _gl.BACK );
  14857. }
  14858. _renderer.resetGLState();
  14859. scope.needsUpdate = false;
  14860. };
  14861. function projectObject( object, camera ) {
  14862. if ( object.visible === false ) return;
  14863. var webglObject = _objects.objects[ object.id ];
  14864. if ( webglObject && object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  14865. var material = object.material;
  14866. if ( material !== null && material.visible === true ) {
  14867. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14868. _renderList.push( webglObject );
  14869. }
  14870. }
  14871. var children = object.children;
  14872. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14873. projectObject( children[ i ], camera );
  14874. }
  14875. }
  14876. };
  14877. // File:src/renderers/webgl/WebGLState.js
  14878. /**
  14879. * @author mrdoob / http://mrdoob.com/
  14880. */
  14881. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  14882. var _this = this;
  14883. var newAttributes = new Uint8Array( 16 );
  14884. var enabledAttributes = new Uint8Array( 16 );
  14885. var capabilities = {};
  14886. var compressedTextureFormats = null;
  14887. var currentBlending = null;
  14888. var currentBlendEquation = null;
  14889. var currentBlendSrc = null;
  14890. var currentBlendDst = null;
  14891. var currentBlendEquationAlpha = null;
  14892. var currentBlendSrcAlpha = null;
  14893. var currentBlendDstAlpha = null;
  14894. var currentDepthFunc = null;
  14895. var currentDepthWrite = null;
  14896. var currentColorWrite = null;
  14897. var currentFlipSided = null;
  14898. var currentLineWidth = null;
  14899. var currentPolygonOffsetFactor = null;
  14900. var currentPolygonOffsetUnits = null;
  14901. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14902. var currentTextureSlot = undefined;
  14903. var currentBoundTextures = {};
  14904. this.init = function () {
  14905. gl.clearColor( 0, 0, 0, 1 );
  14906. gl.clearDepth( 1 );
  14907. gl.clearStencil( 0 );
  14908. this.enable( gl.DEPTH_TEST );
  14909. gl.depthFunc( gl.LEQUAL );
  14910. gl.frontFace( gl.CCW );
  14911. gl.cullFace( gl.BACK );
  14912. this.enable( gl.CULL_FACE );
  14913. this.enable( gl.BLEND );
  14914. gl.blendEquation( gl.FUNC_ADD );
  14915. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  14916. };
  14917. this.initAttributes = function () {
  14918. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  14919. newAttributes[ i ] = 0;
  14920. }
  14921. };
  14922. this.enableAttribute = function ( attribute ) {
  14923. newAttributes[ attribute ] = 1;
  14924. if ( enabledAttributes[ attribute ] === 0 ) {
  14925. gl.enableVertexAttribArray( attribute );
  14926. enabledAttributes[ attribute ] = 1;
  14927. }
  14928. };
  14929. this.disableUnusedAttributes = function () {
  14930. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  14931. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  14932. gl.disableVertexAttribArray( i );
  14933. enabledAttributes[ i ] = 0;
  14934. }
  14935. }
  14936. };
  14937. this.enable = function ( id ) {
  14938. if ( capabilities[ id ] !== true ) {
  14939. gl.enable( id );
  14940. capabilities[ id ] = true;
  14941. }
  14942. };
  14943. this.disable = function ( id ) {
  14944. if ( capabilities[ id ] !== false ) {
  14945. gl.disable( id );
  14946. capabilities[ id ] = false;
  14947. }
  14948. };
  14949. this.getCompressedTextureFormats = function () {
  14950. if ( compressedTextureFormats === null ) {
  14951. compressedTextureFormats = [];
  14952. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  14953. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  14954. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  14955. for ( var i = 0; i < formats.length; i ++ ) {
  14956. compressedTextureFormats.push( formats[ i ] );
  14957. }
  14958. }
  14959. }
  14960. return compressedTextureFormats;
  14961. };
  14962. this.getMaxPrecision = function ( precision ) {
  14963. if ( precision === 'highp' ) {
  14964. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  14965. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  14966. return 'highp';
  14967. }
  14968. precision = 'mediump';
  14969. }
  14970. if ( precision === 'mediump' ) {
  14971. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  14972. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  14973. return 'mediump';
  14974. }
  14975. }
  14976. return 'lowp';
  14977. };
  14978. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  14979. if ( blending !== currentBlending ) {
  14980. if ( blending === THREE.NoBlending ) {
  14981. this.disable( gl.BLEND );
  14982. } else if ( blending === THREE.AdditiveBlending ) {
  14983. this.enable( gl.BLEND );
  14984. gl.blendEquation( gl.FUNC_ADD );
  14985. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  14986. } else if ( blending === THREE.SubtractiveBlending ) {
  14987. // TODO: Find blendFuncSeparate() combination
  14988. this.enable( gl.BLEND );
  14989. gl.blendEquation( gl.FUNC_ADD );
  14990. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  14991. } else if ( blending === THREE.MultiplyBlending ) {
  14992. // TODO: Find blendFuncSeparate() combination
  14993. this.enable( gl.BLEND );
  14994. gl.blendEquation( gl.FUNC_ADD );
  14995. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  14996. } else if ( blending === THREE.CustomBlending ) {
  14997. this.enable( gl.BLEND );
  14998. } else {
  14999. this.enable( gl.BLEND );
  15000. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  15001. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  15002. }
  15003. currentBlending = blending;
  15004. }
  15005. if ( blending === THREE.CustomBlending ) {
  15006. blendEquationAlpha = blendEquationAlpha || blendEquation;
  15007. blendSrcAlpha = blendSrcAlpha || blendSrc;
  15008. blendDstAlpha = blendDstAlpha || blendDst;
  15009. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  15010. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  15011. currentBlendEquation = blendEquation;
  15012. currentBlendEquationAlpha = blendEquationAlpha;
  15013. }
  15014. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  15015. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  15016. currentBlendSrc = blendSrc;
  15017. currentBlendDst = blendDst;
  15018. currentBlendSrcAlpha = blendSrcAlpha;
  15019. currentBlendDstAlpha = blendDstAlpha;
  15020. }
  15021. } else {
  15022. currentBlendEquation = null;
  15023. currentBlendSrc = null;
  15024. currentBlendDst = null;
  15025. currentBlendEquationAlpha = null;
  15026. currentBlendSrcAlpha = null;
  15027. currentBlendDstAlpha = null;
  15028. }
  15029. };
  15030. this.setDepthFunc = function ( depthFunc ) {
  15031. if ( currentDepthFunc !== depthFunc ) {
  15032. if ( depthFunc ) {
  15033. switch ( depthFunc ) {
  15034. case THREE.NeverDepth:
  15035. gl.depthFunc( gl.NEVER );
  15036. break;
  15037. case THREE.AlwaysDepth:
  15038. gl.depthFunc( gl.ALWAYS );
  15039. break;
  15040. case THREE.LessDepth:
  15041. gl.depthFunc( gl.LESS );
  15042. break;
  15043. case THREE.LessEqualDepth:
  15044. gl.depthFunc( gl.LEQUAL );
  15045. break;
  15046. case THREE.EqualDepth:
  15047. gl.depthFunc( gl.EQUAL );
  15048. break;
  15049. case THREE.GreaterEqualDepth:
  15050. gl.depthFunc( gl.GEQUAL );
  15051. break;
  15052. case THREE.GreaterDepth:
  15053. gl.depthFunc( gl.GREATER );
  15054. break;
  15055. case THREE.NotEqualDepth:
  15056. gl.depthFunc( gl.NOTEQUAL );
  15057. break;
  15058. default:
  15059. gl.depthFunc( gl.LEQUAL );
  15060. }
  15061. } else {
  15062. gl.depthFunc( gl.LEQUAL );
  15063. }
  15064. currentDepthFunc = depthFunc;
  15065. }
  15066. };
  15067. this.setDepthTest = function ( depthTest ) {
  15068. if ( depthTest ) {
  15069. this.enable( gl.DEPTH_TEST );
  15070. } else {
  15071. this.disable( gl.DEPTH_TEST );
  15072. }
  15073. };
  15074. this.setDepthWrite = function ( depthWrite ) {
  15075. if ( currentDepthWrite !== depthWrite ) {
  15076. gl.depthMask( depthWrite );
  15077. currentDepthWrite = depthWrite;
  15078. }
  15079. };
  15080. this.setColorWrite = function ( colorWrite ) {
  15081. if ( currentColorWrite !== colorWrite ) {
  15082. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  15083. currentColorWrite = colorWrite;
  15084. }
  15085. };
  15086. this.setFlipSided = function ( flipSided ) {
  15087. if ( currentFlipSided !== flipSided ) {
  15088. if ( flipSided ) {
  15089. gl.frontFace( gl.CW );
  15090. } else {
  15091. gl.frontFace( gl.CCW );
  15092. }
  15093. currentFlipSided = flipSided;
  15094. }
  15095. };
  15096. this.setLineWidth = function ( width ) {
  15097. if ( width !== currentLineWidth ) {
  15098. gl.lineWidth( width );
  15099. currentLineWidth = width;
  15100. }
  15101. };
  15102. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  15103. if ( polygonOffset ) {
  15104. this.enable( gl.POLYGON_OFFSET_FILL );
  15105. } else {
  15106. this.disable( gl.POLYGON_OFFSET_FILL );
  15107. }
  15108. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  15109. gl.polygonOffset( factor, units );
  15110. currentPolygonOffsetFactor = factor;
  15111. currentPolygonOffsetUnits = units;
  15112. }
  15113. };
  15114. this.setScissorTest = function ( scissorTest ) {
  15115. if ( scissorTest ) {
  15116. this.enable( gl.SCISSOR_TEST );
  15117. } else {
  15118. this.disable( gl.SCISSOR_TEST );
  15119. }
  15120. };
  15121. // texture
  15122. this.activeTexture = function ( webglSlot ) {
  15123. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  15124. if ( currentTextureSlot !== webglSlot ) {
  15125. gl.activeTexture( webglSlot );
  15126. currentTextureSlot = webglSlot;
  15127. }
  15128. }
  15129. this.bindTexture = function ( webglType, webglTexture ) {
  15130. if ( currentTextureSlot === undefined ) {
  15131. _this.activeTexture();
  15132. }
  15133. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  15134. if ( boundTexture === undefined ) {
  15135. boundTexture = { type: undefined, texture: undefined };
  15136. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  15137. }
  15138. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  15139. gl.bindTexture( webglType, webglTexture );
  15140. boundTexture.type = webglType;
  15141. boundTexture.texture = webglTexture;
  15142. }
  15143. };
  15144. this.compressedTexImage2D = function () {
  15145. try {
  15146. gl.compressedTexImage2D.apply( gl, arguments );
  15147. } catch ( error ) {
  15148. console.error( error );
  15149. }
  15150. };
  15151. this.texImage2D = function () {
  15152. try {
  15153. gl.texImage2D.apply( gl, arguments );
  15154. } catch ( error ) {
  15155. console.error( error );
  15156. }
  15157. };
  15158. //
  15159. this.reset = function () {
  15160. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  15161. if ( enabledAttributes[ i ] === 1 ) {
  15162. gl.disableVertexAttribArray( i );
  15163. enabledAttributes[ i ] = 0;
  15164. }
  15165. }
  15166. capabilities = {};
  15167. compressedTextureFormats = null;
  15168. currentBlending = null;
  15169. currentDepthWrite = null;
  15170. currentColorWrite = null;
  15171. currentFlipSided = null;
  15172. };
  15173. };
  15174. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  15175. /**
  15176. * @author mikael emtinger / http://gomo.se/
  15177. * @author alteredq / http://alteredqualia.com/
  15178. */
  15179. THREE.LensFlarePlugin = function ( renderer, flares ) {
  15180. var gl = renderer.context;
  15181. var state = renderer.state;
  15182. var vertexBuffer, elementBuffer;
  15183. var program, attributes, uniforms;
  15184. var hasVertexTexture;
  15185. var tempTexture, occlusionTexture;
  15186. var init = function () {
  15187. var vertices = new Float32Array( [
  15188. - 1, - 1, 0, 0,
  15189. 1, - 1, 1, 0,
  15190. 1, 1, 1, 1,
  15191. - 1, 1, 0, 1
  15192. ] );
  15193. var faces = new Uint16Array( [
  15194. 0, 1, 2,
  15195. 0, 2, 3
  15196. ] );
  15197. // buffers
  15198. vertexBuffer = gl.createBuffer();
  15199. elementBuffer = gl.createBuffer();
  15200. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15201. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15202. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15203. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15204. // textures
  15205. tempTexture = gl.createTexture();
  15206. occlusionTexture = gl.createTexture();
  15207. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15208. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  15209. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15210. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15211. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15212. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15213. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15214. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  15215. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15216. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15217. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15218. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15219. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  15220. var shader;
  15221. if ( hasVertexTexture ) {
  15222. shader = {
  15223. vertexShader: [
  15224. "uniform lowp int renderType;",
  15225. "uniform vec3 screenPosition;",
  15226. "uniform vec2 scale;",
  15227. "uniform float rotation;",
  15228. "uniform sampler2D occlusionMap;",
  15229. "attribute vec2 position;",
  15230. "attribute vec2 uv;",
  15231. "varying vec2 vUV;",
  15232. "varying float vVisibility;",
  15233. "void main() {",
  15234. "vUV = uv;",
  15235. "vec2 pos = position;",
  15236. "if( renderType == 2 ) {",
  15237. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  15238. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  15239. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  15240. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  15241. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  15242. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  15243. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  15244. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  15245. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  15246. "vVisibility = visibility.r / 9.0;",
  15247. "vVisibility *= 1.0 - visibility.g / 9.0;",
  15248. "vVisibility *= visibility.b / 9.0;",
  15249. "vVisibility *= 1.0 - visibility.a / 9.0;",
  15250. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15251. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15252. "}",
  15253. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15254. "}"
  15255. ].join( "\n" ),
  15256. fragmentShader: [
  15257. "uniform lowp int renderType;",
  15258. "uniform sampler2D map;",
  15259. "uniform float opacity;",
  15260. "uniform vec3 color;",
  15261. "varying vec2 vUV;",
  15262. "varying float vVisibility;",
  15263. "void main() {",
  15264. // pink square
  15265. "if( renderType == 0 ) {",
  15266. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  15267. // restore
  15268. "} else if( renderType == 1 ) {",
  15269. "gl_FragColor = texture2D( map, vUV );",
  15270. // flare
  15271. "} else {",
  15272. "vec4 texture = texture2D( map, vUV );",
  15273. "texture.a *= opacity * vVisibility;",
  15274. "gl_FragColor = texture;",
  15275. "gl_FragColor.rgb *= color;",
  15276. "}",
  15277. "}"
  15278. ].join( "\n" )
  15279. };
  15280. } else {
  15281. shader = {
  15282. vertexShader: [
  15283. "uniform lowp int renderType;",
  15284. "uniform vec3 screenPosition;",
  15285. "uniform vec2 scale;",
  15286. "uniform float rotation;",
  15287. "attribute vec2 position;",
  15288. "attribute vec2 uv;",
  15289. "varying vec2 vUV;",
  15290. "void main() {",
  15291. "vUV = uv;",
  15292. "vec2 pos = position;",
  15293. "if( renderType == 2 ) {",
  15294. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15295. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15296. "}",
  15297. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15298. "}"
  15299. ].join( "\n" ),
  15300. fragmentShader: [
  15301. "precision mediump float;",
  15302. "uniform lowp int renderType;",
  15303. "uniform sampler2D map;",
  15304. "uniform sampler2D occlusionMap;",
  15305. "uniform float opacity;",
  15306. "uniform vec3 color;",
  15307. "varying vec2 vUV;",
  15308. "void main() {",
  15309. // pink square
  15310. "if( renderType == 0 ) {",
  15311. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  15312. // restore
  15313. "} else if( renderType == 1 ) {",
  15314. "gl_FragColor = texture2D( map, vUV );",
  15315. // flare
  15316. "} else {",
  15317. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  15318. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  15319. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  15320. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  15321. "visibility = ( 1.0 - visibility / 4.0 );",
  15322. "vec4 texture = texture2D( map, vUV );",
  15323. "texture.a *= opacity * visibility;",
  15324. "gl_FragColor = texture;",
  15325. "gl_FragColor.rgb *= color;",
  15326. "}",
  15327. "}"
  15328. ].join( "\n" )
  15329. };
  15330. }
  15331. program = createProgram( shader );
  15332. attributes = {
  15333. vertex: gl.getAttribLocation ( program, "position" ),
  15334. uv: gl.getAttribLocation ( program, "uv" )
  15335. };
  15336. uniforms = {
  15337. renderType: gl.getUniformLocation( program, "renderType" ),
  15338. map: gl.getUniformLocation( program, "map" ),
  15339. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  15340. opacity: gl.getUniformLocation( program, "opacity" ),
  15341. color: gl.getUniformLocation( program, "color" ),
  15342. scale: gl.getUniformLocation( program, "scale" ),
  15343. rotation: gl.getUniformLocation( program, "rotation" ),
  15344. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  15345. };
  15346. };
  15347. /*
  15348. * Render lens flares
  15349. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  15350. * reads these back and calculates occlusion.
  15351. */
  15352. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  15353. if ( flares.length === 0 ) return;
  15354. var tempPosition = new THREE.Vector3();
  15355. var invAspect = viewportHeight / viewportWidth,
  15356. halfViewportWidth = viewportWidth * 0.5,
  15357. halfViewportHeight = viewportHeight * 0.5;
  15358. var size = 16 / viewportHeight,
  15359. scale = new THREE.Vector2( size * invAspect, size );
  15360. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  15361. screenPositionPixels = new THREE.Vector2( 1, 1 );
  15362. if ( program === undefined ) {
  15363. init();
  15364. }
  15365. gl.useProgram( program );
  15366. state.initAttributes();
  15367. state.enableAttribute( attributes.vertex );
  15368. state.enableAttribute( attributes.uv );
  15369. state.disableUnusedAttributes();
  15370. // loop through all lens flares to update their occlusion and positions
  15371. // setup gl and common used attribs/uniforms
  15372. gl.uniform1i( uniforms.occlusionMap, 0 );
  15373. gl.uniform1i( uniforms.map, 1 );
  15374. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15375. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  15376. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15377. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15378. state.disable( gl.CULL_FACE );
  15379. gl.depthMask( false );
  15380. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  15381. size = 16 / viewportHeight;
  15382. scale.set( size * invAspect, size );
  15383. // calc object screen position
  15384. var flare = flares[ i ];
  15385. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  15386. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  15387. tempPosition.applyProjection( camera.projectionMatrix );
  15388. // setup arrays for gl programs
  15389. screenPosition.copy( tempPosition );
  15390. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  15391. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  15392. // screen cull
  15393. if ( hasVertexTexture || (
  15394. screenPositionPixels.x > 0 &&
  15395. screenPositionPixels.x < viewportWidth &&
  15396. screenPositionPixels.y > 0 &&
  15397. screenPositionPixels.y < viewportHeight ) ) {
  15398. // save current RGB to temp texture
  15399. state.activeTexture( gl.TEXTURE0 );
  15400. state.bindTexture( gl.TEXTURE_2D, null );
  15401. state.activeTexture( gl.TEXTURE1 );
  15402. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15403. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15404. // render pink quad
  15405. gl.uniform1i( uniforms.renderType, 0 );
  15406. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15407. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15408. state.disable( gl.BLEND );
  15409. state.enable( gl.DEPTH_TEST );
  15410. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15411. // copy result to occlusionMap
  15412. state.activeTexture( gl.TEXTURE0 );
  15413. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15414. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15415. // restore graphics
  15416. gl.uniform1i( uniforms.renderType, 1 );
  15417. state.disable( gl.DEPTH_TEST );
  15418. state.activeTexture( gl.TEXTURE1 );
  15419. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15420. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15421. // update object positions
  15422. flare.positionScreen.copy( screenPosition );
  15423. if ( flare.customUpdateCallback ) {
  15424. flare.customUpdateCallback( flare );
  15425. } else {
  15426. flare.updateLensFlares();
  15427. }
  15428. // render flares
  15429. gl.uniform1i( uniforms.renderType, 2 );
  15430. state.enable( gl.BLEND );
  15431. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  15432. var sprite = flare.lensFlares[ j ];
  15433. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  15434. screenPosition.x = sprite.x;
  15435. screenPosition.y = sprite.y;
  15436. screenPosition.z = sprite.z;
  15437. size = sprite.size * sprite.scale / viewportHeight;
  15438. scale.x = size * invAspect;
  15439. scale.y = size;
  15440. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15441. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15442. gl.uniform1f( uniforms.rotation, sprite.rotation );
  15443. gl.uniform1f( uniforms.opacity, sprite.opacity );
  15444. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  15445. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  15446. renderer.setTexture( sprite.texture, 1 );
  15447. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15448. }
  15449. }
  15450. }
  15451. }
  15452. // restore gl
  15453. state.enable( gl.CULL_FACE );
  15454. state.enable( gl.DEPTH_TEST );
  15455. gl.depthMask( true );
  15456. renderer.resetGLState();
  15457. };
  15458. function createProgram ( shader ) {
  15459. var program = gl.createProgram();
  15460. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15461. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15462. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  15463. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  15464. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  15465. gl.compileShader( fragmentShader );
  15466. gl.compileShader( vertexShader );
  15467. gl.attachShader( program, fragmentShader );
  15468. gl.attachShader( program, vertexShader );
  15469. gl.linkProgram( program );
  15470. return program;
  15471. }
  15472. };
  15473. // File:src/renderers/webgl/plugins/SpritePlugin.js
  15474. /**
  15475. * @author mikael emtinger / http://gomo.se/
  15476. * @author alteredq / http://alteredqualia.com/
  15477. */
  15478. THREE.SpritePlugin = function ( renderer, sprites ) {
  15479. var gl = renderer.context;
  15480. var state = renderer.state;
  15481. var vertexBuffer, elementBuffer;
  15482. var program, attributes, uniforms;
  15483. var texture;
  15484. // decompose matrixWorld
  15485. var spritePosition = new THREE.Vector3();
  15486. var spriteRotation = new THREE.Quaternion();
  15487. var spriteScale = new THREE.Vector3();
  15488. var init = function () {
  15489. var vertices = new Float32Array( [
  15490. - 0.5, - 0.5, 0, 0,
  15491. 0.5, - 0.5, 1, 0,
  15492. 0.5, 0.5, 1, 1,
  15493. - 0.5, 0.5, 0, 1
  15494. ] );
  15495. var faces = new Uint16Array( [
  15496. 0, 1, 2,
  15497. 0, 2, 3
  15498. ] );
  15499. vertexBuffer = gl.createBuffer();
  15500. elementBuffer = gl.createBuffer();
  15501. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15502. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15503. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15504. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15505. program = createProgram();
  15506. attributes = {
  15507. position: gl.getAttribLocation ( program, 'position' ),
  15508. uv: gl.getAttribLocation ( program, 'uv' )
  15509. };
  15510. uniforms = {
  15511. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  15512. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  15513. rotation: gl.getUniformLocation( program, 'rotation' ),
  15514. scale: gl.getUniformLocation( program, 'scale' ),
  15515. color: gl.getUniformLocation( program, 'color' ),
  15516. map: gl.getUniformLocation( program, 'map' ),
  15517. opacity: gl.getUniformLocation( program, 'opacity' ),
  15518. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  15519. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  15520. fogType: gl.getUniformLocation( program, 'fogType' ),
  15521. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  15522. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  15523. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  15524. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  15525. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  15526. };
  15527. var canvas = document.createElement( 'canvas' );
  15528. canvas.width = 8;
  15529. canvas.height = 8;
  15530. var context = canvas.getContext( '2d' );
  15531. context.fillStyle = 'white';
  15532. context.fillRect( 0, 0, 8, 8 );
  15533. texture = new THREE.Texture( canvas );
  15534. texture.needsUpdate = true;
  15535. };
  15536. this.render = function ( scene, camera ) {
  15537. if ( sprites.length === 0 ) return;
  15538. // setup gl
  15539. if ( program === undefined ) {
  15540. init();
  15541. }
  15542. gl.useProgram( program );
  15543. state.initAttributes();
  15544. state.enableAttribute( attributes.position );
  15545. state.enableAttribute( attributes.uv );
  15546. state.disableUnusedAttributes();
  15547. state.disable( gl.CULL_FACE );
  15548. state.enable( gl.BLEND );
  15549. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15550. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  15551. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15552. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15553. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15554. state.activeTexture( gl.TEXTURE0 );
  15555. gl.uniform1i( uniforms.map, 0 );
  15556. var oldFogType = 0;
  15557. var sceneFogType = 0;
  15558. var fog = scene.fog;
  15559. if ( fog ) {
  15560. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  15561. if ( fog instanceof THREE.Fog ) {
  15562. gl.uniform1f( uniforms.fogNear, fog.near );
  15563. gl.uniform1f( uniforms.fogFar, fog.far );
  15564. gl.uniform1i( uniforms.fogType, 1 );
  15565. oldFogType = 1;
  15566. sceneFogType = 1;
  15567. } else if ( fog instanceof THREE.FogExp2 ) {
  15568. gl.uniform1f( uniforms.fogDensity, fog.density );
  15569. gl.uniform1i( uniforms.fogType, 2 );
  15570. oldFogType = 2;
  15571. sceneFogType = 2;
  15572. }
  15573. } else {
  15574. gl.uniform1i( uniforms.fogType, 0 );
  15575. oldFogType = 0;
  15576. sceneFogType = 0;
  15577. }
  15578. // update positions and sort
  15579. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15580. var sprite = sprites[ i ];
  15581. sprite._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  15582. sprite.z = - sprite._modelViewMatrix.elements[ 14 ];
  15583. }
  15584. sprites.sort( painterSortStable );
  15585. // render all sprites
  15586. var scale = [];
  15587. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15588. var sprite = sprites[ i ];
  15589. var material = sprite.material;
  15590. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  15591. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements );
  15592. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  15593. scale[ 0 ] = spriteScale.x;
  15594. scale[ 1 ] = spriteScale.y;
  15595. var fogType = 0;
  15596. if ( scene.fog && material.fog ) {
  15597. fogType = sceneFogType;
  15598. }
  15599. if ( oldFogType !== fogType ) {
  15600. gl.uniform1i( uniforms.fogType, fogType );
  15601. oldFogType = fogType;
  15602. }
  15603. if ( material.map !== null ) {
  15604. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  15605. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  15606. } else {
  15607. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  15608. gl.uniform2f( uniforms.uvScale, 1, 1 );
  15609. }
  15610. gl.uniform1f( uniforms.opacity, material.opacity );
  15611. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  15612. gl.uniform1f( uniforms.rotation, material.rotation );
  15613. gl.uniform2fv( uniforms.scale, scale );
  15614. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  15615. state.setDepthTest( material.depthTest );
  15616. state.setDepthWrite( material.depthWrite );
  15617. if ( material.map && material.map.image && material.map.image.width ) {
  15618. renderer.setTexture( material.map, 0 );
  15619. } else {
  15620. renderer.setTexture( texture, 0 );
  15621. }
  15622. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15623. }
  15624. // restore gl
  15625. state.enable( gl.CULL_FACE );
  15626. renderer.resetGLState();
  15627. };
  15628. function createProgram () {
  15629. var program = gl.createProgram();
  15630. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15631. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15632. gl.shaderSource( vertexShader, [
  15633. 'precision ' + renderer.getPrecision() + ' float;',
  15634. 'uniform mat4 modelViewMatrix;',
  15635. 'uniform mat4 projectionMatrix;',
  15636. 'uniform float rotation;',
  15637. 'uniform vec2 scale;',
  15638. 'uniform vec2 uvOffset;',
  15639. 'uniform vec2 uvScale;',
  15640. 'attribute vec2 position;',
  15641. 'attribute vec2 uv;',
  15642. 'varying vec2 vUV;',
  15643. 'void main() {',
  15644. 'vUV = uvOffset + uv * uvScale;',
  15645. 'vec2 alignedPosition = position * scale;',
  15646. 'vec2 rotatedPosition;',
  15647. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  15648. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  15649. 'vec4 finalPosition;',
  15650. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  15651. 'finalPosition.xy += rotatedPosition;',
  15652. 'finalPosition = projectionMatrix * finalPosition;',
  15653. 'gl_Position = finalPosition;',
  15654. '}'
  15655. ].join( '\n' ) );
  15656. gl.shaderSource( fragmentShader, [
  15657. 'precision ' + renderer.getPrecision() + ' float;',
  15658. 'uniform vec3 color;',
  15659. 'uniform sampler2D map;',
  15660. 'uniform float opacity;',
  15661. 'uniform int fogType;',
  15662. 'uniform vec3 fogColor;',
  15663. 'uniform float fogDensity;',
  15664. 'uniform float fogNear;',
  15665. 'uniform float fogFar;',
  15666. 'uniform float alphaTest;',
  15667. 'varying vec2 vUV;',
  15668. 'void main() {',
  15669. 'vec4 texture = texture2D( map, vUV );',
  15670. 'if ( texture.a < alphaTest ) discard;',
  15671. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  15672. 'if ( fogType > 0 ) {',
  15673. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  15674. 'float fogFactor = 0.0;',
  15675. 'if ( fogType == 1 ) {',
  15676. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  15677. '} else {',
  15678. 'const float LOG2 = 1.442695;',
  15679. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  15680. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  15681. '}',
  15682. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  15683. '}',
  15684. '}'
  15685. ].join( '\n' ) );
  15686. gl.compileShader( vertexShader );
  15687. gl.compileShader( fragmentShader );
  15688. gl.attachShader( program, vertexShader );
  15689. gl.attachShader( program, fragmentShader );
  15690. gl.linkProgram( program );
  15691. return program;
  15692. }
  15693. function painterSortStable ( a, b ) {
  15694. if ( a.z !== b.z ) {
  15695. return b.z - a.z;
  15696. } else {
  15697. return b.id - a.id;
  15698. }
  15699. }
  15700. };
  15701. // File:src/extras/GeometryUtils.js
  15702. /**
  15703. * @author mrdoob / http://mrdoob.com/
  15704. */
  15705. THREE.GeometryUtils = {
  15706. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  15707. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  15708. var matrix;
  15709. if ( geometry2 instanceof THREE.Mesh ) {
  15710. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  15711. matrix = geometry2.matrix;
  15712. geometry2 = geometry2.geometry;
  15713. }
  15714. geometry1.merge( geometry2, matrix, materialIndexOffset );
  15715. },
  15716. center: function ( geometry ) {
  15717. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  15718. return geometry.center();
  15719. }
  15720. };
  15721. // File:src/extras/ImageUtils.js
  15722. /**
  15723. * @author alteredq / http://alteredqualia.com/
  15724. * @author mrdoob / http://mrdoob.com/
  15725. * @author Daosheng Mu / https://github.com/DaoshengMu/
  15726. */
  15727. THREE.ImageUtils = {
  15728. crossOrigin: undefined,
  15729. loadTexture: function ( url, mapping, onLoad, onError ) {
  15730. var loader = new THREE.ImageLoader();
  15731. loader.crossOrigin = this.crossOrigin;
  15732. var texture = new THREE.Texture( undefined, mapping );
  15733. loader.load( url, function ( image ) {
  15734. texture.image = image;
  15735. texture.needsUpdate = true;
  15736. if ( onLoad ) onLoad( texture );
  15737. }, undefined, function ( event ) {
  15738. if ( onError ) onError( event );
  15739. } );
  15740. texture.sourceFile = url;
  15741. return texture;
  15742. },
  15743. loadTextureCube: function ( array, mapping, onLoad, onError ) {
  15744. var images = [];
  15745. var loader = new THREE.ImageLoader();
  15746. loader.crossOrigin = this.crossOrigin;
  15747. var texture = new THREE.CubeTexture( images, mapping );
  15748. var loaded = 0;
  15749. var loadTexture = function ( i ) {
  15750. loader.load( array[ i ], function ( image ) {
  15751. texture.images[ i ] = image;
  15752. loaded += 1;
  15753. if ( loaded === 6 ) {
  15754. texture.needsUpdate = true;
  15755. if ( onLoad ) onLoad( texture );
  15756. }
  15757. }, undefined, onError );
  15758. };
  15759. for ( var i = 0, il = array.length; i < il; ++ i ) {
  15760. loadTexture( i );
  15761. }
  15762. return texture;
  15763. },
  15764. loadCompressedTexture: function () {
  15765. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  15766. },
  15767. loadCompressedTextureCube: function () {
  15768. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  15769. },
  15770. getNormalMap: function ( image, depth ) {
  15771. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  15772. var cross = function ( a, b ) {
  15773. 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 ] ];
  15774. };
  15775. var subtract = function ( a, b ) {
  15776. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  15777. };
  15778. var normalize = function ( a ) {
  15779. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  15780. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  15781. };
  15782. depth = depth | 1;
  15783. var width = image.width;
  15784. var height = image.height;
  15785. var canvas = document.createElement( 'canvas' );
  15786. canvas.width = width;
  15787. canvas.height = height;
  15788. var context = canvas.getContext( '2d' );
  15789. context.drawImage( image, 0, 0 );
  15790. var data = context.getImageData( 0, 0, width, height ).data;
  15791. var imageData = context.createImageData( width, height );
  15792. var output = imageData.data;
  15793. for ( var x = 0; x < width; x ++ ) {
  15794. for ( var y = 0; y < height; y ++ ) {
  15795. var ly = y - 1 < 0 ? 0 : y - 1;
  15796. var uy = y + 1 > height - 1 ? height - 1 : y + 1;
  15797. var lx = x - 1 < 0 ? 0 : x - 1;
  15798. var ux = x + 1 > width - 1 ? width - 1 : x + 1;
  15799. var points = [];
  15800. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  15801. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  15802. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  15803. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  15804. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  15805. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  15806. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  15807. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  15808. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  15809. var normals = [];
  15810. var num_points = points.length;
  15811. for ( var i = 0; i < num_points; i ++ ) {
  15812. var v1 = points[ i ];
  15813. var v2 = points[ ( i + 1 ) % num_points ];
  15814. v1 = subtract( v1, origin );
  15815. v2 = subtract( v2, origin );
  15816. normals.push( normalize( cross( v1, v2 ) ) );
  15817. }
  15818. var normal = [ 0, 0, 0 ];
  15819. for ( var i = 0; i < normals.length; i ++ ) {
  15820. normal[ 0 ] += normals[ i ][ 0 ];
  15821. normal[ 1 ] += normals[ i ][ 1 ];
  15822. normal[ 2 ] += normals[ i ][ 2 ];
  15823. }
  15824. normal[ 0 ] /= normals.length;
  15825. normal[ 1 ] /= normals.length;
  15826. normal[ 2 ] /= normals.length;
  15827. var idx = ( y * width + x ) * 4;
  15828. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15829. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15830. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  15831. output[ idx + 3 ] = 255;
  15832. }
  15833. }
  15834. context.putImageData( imageData, 0, 0 );
  15835. return canvas;
  15836. },
  15837. generateDataTexture: function ( width, height, color ) {
  15838. var size = width * height;
  15839. var data = new Uint8Array( 3 * size );
  15840. var r = Math.floor( color.r * 255 );
  15841. var g = Math.floor( color.g * 255 );
  15842. var b = Math.floor( color.b * 255 );
  15843. for ( var i = 0; i < size; i ++ ) {
  15844. data[ i * 3 ] = r;
  15845. data[ i * 3 + 1 ] = g;
  15846. data[ i * 3 + 2 ] = b;
  15847. }
  15848. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  15849. texture.needsUpdate = true;
  15850. return texture;
  15851. }
  15852. };
  15853. // File:src/extras/SceneUtils.js
  15854. /**
  15855. * @author alteredq / http://alteredqualia.com/
  15856. */
  15857. THREE.SceneUtils = {
  15858. createMultiMaterialObject: function ( geometry, materials ) {
  15859. var group = new THREE.Object3D();
  15860. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  15861. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  15862. }
  15863. return group;
  15864. },
  15865. detach: function ( child, parent, scene ) {
  15866. child.applyMatrix( parent.matrixWorld );
  15867. parent.remove( child );
  15868. scene.add( child );
  15869. },
  15870. attach: function ( child, scene, parent ) {
  15871. var matrixWorldInverse = new THREE.Matrix4();
  15872. matrixWorldInverse.getInverse( parent.matrixWorld );
  15873. child.applyMatrix( matrixWorldInverse );
  15874. scene.remove( child );
  15875. parent.add( child );
  15876. }
  15877. };
  15878. // File:src/extras/FontUtils.js
  15879. /**
  15880. * @author zz85 / http://www.lab4games.net/zz85/blog
  15881. * @author alteredq / http://alteredqualia.com/
  15882. *
  15883. * For Text operations in three.js (See TextGeometry)
  15884. *
  15885. * It uses techniques used in:
  15886. *
  15887. * Triangulation ported from AS3
  15888. * Simple Polygon Triangulation
  15889. * http://actionsnippet.com/?p=1462
  15890. *
  15891. * A Method to triangulate shapes with holes
  15892. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  15893. *
  15894. */
  15895. THREE.FontUtils = {
  15896. faces: {},
  15897. // Just for now. face[weight][style]
  15898. face: 'helvetiker',
  15899. weight: 'normal',
  15900. style: 'normal',
  15901. size: 150,
  15902. divisions: 10,
  15903. getFace: function () {
  15904. try {
  15905. return this.faces[ this.face.toLowerCase() ][ this.weight ][ this.style ];
  15906. } catch ( e ) {
  15907. throw "The font " + this.face + " with " + this.weight + " weight and " + this.style + " style is missing."
  15908. }
  15909. },
  15910. loadFace: function ( data ) {
  15911. var family = data.familyName.toLowerCase();
  15912. var ThreeFont = this;
  15913. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  15914. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  15915. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15916. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15917. return data;
  15918. },
  15919. drawText: function ( text ) {
  15920. // RenderText
  15921. var i,
  15922. face = this.getFace(),
  15923. scale = this.size / face.resolution,
  15924. offset = 0,
  15925. chars = String( text ).split( '' ),
  15926. length = chars.length;
  15927. var fontPaths = [];
  15928. for ( i = 0; i < length; i ++ ) {
  15929. var path = new THREE.Path();
  15930. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  15931. offset += ret.offset;
  15932. fontPaths.push( ret.path );
  15933. }
  15934. // get the width
  15935. var width = offset / 2;
  15936. //
  15937. // for ( p = 0; p < allPts.length; p++ ) {
  15938. //
  15939. // allPts[ p ].x -= width;
  15940. //
  15941. // }
  15942. //var extract = this.extractPoints( allPts, characterPts );
  15943. //extract.contour = allPts;
  15944. //extract.paths = fontPaths;
  15945. //extract.offset = width;
  15946. return { paths: fontPaths, offset: width };
  15947. },
  15948. extractGlyphPoints: function ( c, face, scale, offset, path ) {
  15949. var pts = [];
  15950. var i, i2, divisions,
  15951. outline, action, length,
  15952. scaleX, scaleY,
  15953. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  15954. laste,
  15955. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  15956. if ( ! glyph ) return;
  15957. if ( glyph.o ) {
  15958. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  15959. length = outline.length;
  15960. scaleX = scale;
  15961. scaleY = scale;
  15962. for ( i = 0; i < length; ) {
  15963. action = outline[ i ++ ];
  15964. //console.log( action );
  15965. switch ( action ) {
  15966. case 'm':
  15967. // Move To
  15968. x = outline[ i ++ ] * scaleX + offset;
  15969. y = outline[ i ++ ] * scaleY;
  15970. path.moveTo( x, y );
  15971. break;
  15972. case 'l':
  15973. // Line To
  15974. x = outline[ i ++ ] * scaleX + offset;
  15975. y = outline[ i ++ ] * scaleY;
  15976. path.lineTo( x, y );
  15977. break;
  15978. case 'q':
  15979. // QuadraticCurveTo
  15980. cpx = outline[ i ++ ] * scaleX + offset;
  15981. cpy = outline[ i ++ ] * scaleY;
  15982. cpx1 = outline[ i ++ ] * scaleX + offset;
  15983. cpy1 = outline[ i ++ ] * scaleY;
  15984. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  15985. laste = pts[ pts.length - 1 ];
  15986. if ( laste ) {
  15987. cpx0 = laste.x;
  15988. cpy0 = laste.y;
  15989. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15990. var t = i2 / divisions;
  15991. THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  15992. THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  15993. }
  15994. }
  15995. break;
  15996. case 'b':
  15997. // Cubic Bezier Curve
  15998. cpx = outline[ i ++ ] * scaleX + offset;
  15999. cpy = outline[ i ++ ] * scaleY;
  16000. cpx1 = outline[ i ++ ] * scaleX + offset;
  16001. cpy1 = outline[ i ++ ] * scaleY;
  16002. cpx2 = outline[ i ++ ] * scaleX + offset;
  16003. cpy2 = outline[ i ++ ] * scaleY;
  16004. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  16005. laste = pts[ pts.length - 1 ];
  16006. if ( laste ) {
  16007. cpx0 = laste.x;
  16008. cpy0 = laste.y;
  16009. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  16010. var t = i2 / divisions;
  16011. THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  16012. THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  16013. }
  16014. }
  16015. break;
  16016. }
  16017. }
  16018. }
  16019. return { offset: glyph.ha * scale, path: path };
  16020. }
  16021. };
  16022. THREE.FontUtils.generateShapes = function ( text, parameters ) {
  16023. // Parameters
  16024. parameters = parameters || {};
  16025. var size = parameters.size !== undefined ? parameters.size : 100;
  16026. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments : 4;
  16027. var font = parameters.font !== undefined ? parameters.font : 'helvetiker';
  16028. var weight = parameters.weight !== undefined ? parameters.weight : 'normal';
  16029. var style = parameters.style !== undefined ? parameters.style : 'normal';
  16030. THREE.FontUtils.size = size;
  16031. THREE.FontUtils.divisions = curveSegments;
  16032. THREE.FontUtils.face = font;
  16033. THREE.FontUtils.weight = weight;
  16034. THREE.FontUtils.style = style;
  16035. // Get a Font data json object
  16036. var data = THREE.FontUtils.drawText( text );
  16037. var paths = data.paths;
  16038. var shapes = [];
  16039. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  16040. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  16041. }
  16042. return shapes;
  16043. };
  16044. /**
  16045. * This code is a quick port of code written in C++ which was submitted to
  16046. * flipcode.com by John W. Ratcliff // July 22, 2000
  16047. * See original code and more information here:
  16048. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  16049. *
  16050. * ported to actionscript by Zevan Rosser
  16051. * www.actionsnippet.com
  16052. *
  16053. * ported to javascript by Joshua Koo
  16054. * http://www.lab4games.net/zz85/blog
  16055. *
  16056. */
  16057. ( function ( namespace ) {
  16058. var EPSILON = 0.0000000001;
  16059. // takes in an contour array and returns
  16060. var process = function ( contour, indices ) {
  16061. var n = contour.length;
  16062. if ( n < 3 ) return null;
  16063. var result = [],
  16064. verts = [],
  16065. vertIndices = [];
  16066. /* we want a counter-clockwise polygon in verts */
  16067. var u, v, w;
  16068. if ( area( contour ) > 0.0 ) {
  16069. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  16070. } else {
  16071. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  16072. }
  16073. var nv = n;
  16074. /* remove nv - 2 vertices, creating 1 triangle every time */
  16075. var count = 2 * nv; /* error detection */
  16076. for ( v = nv - 1; nv > 2; ) {
  16077. /* if we loop, it is probably a non-simple polygon */
  16078. if ( ( count -- ) <= 0 ) {
  16079. //** Triangulate: ERROR - probable bad polygon!
  16080. //throw ( "Warning, unable to triangulate polygon!" );
  16081. //return null;
  16082. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  16083. console.warn( 'THREE.FontUtils: Warning, unable to triangulate polygon! in Triangulate.process()' );
  16084. if ( indices ) return vertIndices;
  16085. return result;
  16086. }
  16087. /* three consecutive vertices in current polygon, <u,v,w> */
  16088. u = v; if ( nv <= u ) u = 0; /* previous */
  16089. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  16090. w = v + 1; if ( nv <= w ) w = 0; /* next */
  16091. if ( snip( contour, u, v, w, nv, verts ) ) {
  16092. var a, b, c, s, t;
  16093. /* true names of the vertices */
  16094. a = verts[ u ];
  16095. b = verts[ v ];
  16096. c = verts[ w ];
  16097. /* output Triangle */
  16098. result.push( [ contour[ a ],
  16099. contour[ b ],
  16100. contour[ c ] ] );
  16101. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  16102. /* remove v from the remaining polygon */
  16103. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  16104. verts[ s ] = verts[ t ];
  16105. }
  16106. nv --;
  16107. /* reset error detection counter */
  16108. count = 2 * nv;
  16109. }
  16110. }
  16111. if ( indices ) return vertIndices;
  16112. return result;
  16113. };
  16114. // calculate area of the contour polygon
  16115. var area = function ( contour ) {
  16116. var n = contour.length;
  16117. var a = 0.0;
  16118. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  16119. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  16120. }
  16121. return a * 0.5;
  16122. };
  16123. var snip = function ( contour, u, v, w, n, verts ) {
  16124. var p;
  16125. var ax, ay, bx, by;
  16126. var cx, cy, px, py;
  16127. ax = contour[ verts[ u ] ].x;
  16128. ay = contour[ verts[ u ] ].y;
  16129. bx = contour[ verts[ v ] ].x;
  16130. by = contour[ verts[ v ] ].y;
  16131. cx = contour[ verts[ w ] ].x;
  16132. cy = contour[ verts[ w ] ].y;
  16133. if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  16134. var aX, aY, bX, bY, cX, cY;
  16135. var apx, apy, bpx, bpy, cpx, cpy;
  16136. var cCROSSap, bCROSScp, aCROSSbp;
  16137. aX = cx - bx; aY = cy - by;
  16138. bX = ax - cx; bY = ay - cy;
  16139. cX = bx - ax; cY = by - ay;
  16140. for ( p = 0; p < n; p ++ ) {
  16141. px = contour[ verts[ p ] ].x;
  16142. py = contour[ verts[ p ] ].y;
  16143. if ( ( ( px === ax ) && ( py === ay ) ) ||
  16144. ( ( px === bx ) && ( py === by ) ) ||
  16145. ( ( px === cx ) && ( py === cy ) ) ) continue;
  16146. apx = px - ax; apy = py - ay;
  16147. bpx = px - bx; bpy = py - by;
  16148. cpx = px - cx; cpy = py - cy;
  16149. // see if p is inside triangle abc
  16150. aCROSSbp = aX * bpy - aY * bpx;
  16151. cCROSSap = cX * apy - cY * apx;
  16152. bCROSScp = bX * cpy - bY * cpx;
  16153. if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
  16154. }
  16155. return true;
  16156. };
  16157. namespace.Triangulate = process;
  16158. namespace.Triangulate.area = area;
  16159. return namespace;
  16160. } )( THREE.FontUtils );
  16161. // To use the typeface.js face files, hook up the API
  16162. THREE.typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  16163. if ( typeof self !== 'undefined' ) self._typeface_js = THREE.typeface_js;
  16164. // File:src/extras/audio/Audio.js
  16165. /**
  16166. * @author mrdoob / http://mrdoob.com/
  16167. */
  16168. THREE.Audio = function ( listener ) {
  16169. THREE.Object3D.call( this );
  16170. this.type = 'Audio';
  16171. this.context = listener.context;
  16172. this.source = this.context.createBufferSource();
  16173. this.source.onended = this.onEnded.bind( this );
  16174. this.gain = this.context.createGain();
  16175. this.gain.connect( this.context.destination );
  16176. this.panner = this.context.createPanner();
  16177. this.panner.connect( this.gain );
  16178. this.autoplay = false;
  16179. this.startTime = 0;
  16180. this.playbackRate = 1;
  16181. this.isPlaying = false;
  16182. };
  16183. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  16184. THREE.Audio.prototype.constructor = THREE.Audio;
  16185. THREE.Audio.prototype.load = function ( file ) {
  16186. var scope = this;
  16187. var request = new XMLHttpRequest();
  16188. request.open( 'GET', file, true );
  16189. request.responseType = 'arraybuffer';
  16190. request.onload = function ( e ) {
  16191. scope.context.decodeAudioData( this.response, function ( buffer ) {
  16192. scope.source.buffer = buffer;
  16193. if ( scope.autoplay ) scope.play();
  16194. } );
  16195. };
  16196. request.send();
  16197. return this;
  16198. };
  16199. THREE.Audio.prototype.play = function () {
  16200. if ( this.isPlaying === true ) {
  16201. console.warn( 'THREE.Audio: Audio is already playing.' );
  16202. return;
  16203. }
  16204. var source = this.context.createBufferSource();
  16205. source.buffer = this.source.buffer;
  16206. source.loop = this.source.loop;
  16207. source.onended = this.source.onended;
  16208. source.start( 0, this.startTime );
  16209. source.playbackRate.value = this.playbackRate;
  16210. this.isPlaying = true;
  16211. this.source = source;
  16212. this.connect();
  16213. };
  16214. THREE.Audio.prototype.pause = function () {
  16215. this.source.stop();
  16216. this.startTime = this.context.currentTime;
  16217. };
  16218. THREE.Audio.prototype.stop = function () {
  16219. this.source.stop();
  16220. this.startTime = 0;
  16221. };
  16222. THREE.Audio.prototype.connect = function () {
  16223. if ( this.filter !== undefined ) {
  16224. this.source.connect( this.filter );
  16225. this.filter.connect( this.panner );
  16226. } else {
  16227. this.source.connect( this.panner );
  16228. }
  16229. };
  16230. THREE.Audio.prototype.disconnect = function () {
  16231. if ( this.filter !== undefined ) {
  16232. this.source.disconnect( this.filter );
  16233. this.filter.disconnect( this.panner );
  16234. } else {
  16235. this.source.disconnect( this.panner );
  16236. }
  16237. };
  16238. THREE.Audio.prototype.setFilter = function ( value ) {
  16239. if ( this.isPlaying === true ) {
  16240. this.disconnect();
  16241. this.filter = value;
  16242. this.connect();
  16243. } else {
  16244. this.filter = value;
  16245. }
  16246. };
  16247. THREE.Audio.prototype.getFilter = function () {
  16248. return this.filter;
  16249. };
  16250. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  16251. this.playbackRate = value;
  16252. if ( this.isPlaying === true ) {
  16253. this.source.playbackRate.value = this.playbackRate;
  16254. }
  16255. };
  16256. THREE.Audio.prototype.getPlaybackRate = function () {
  16257. return this.playbackRate;
  16258. };
  16259. THREE.Audio.prototype.onEnded = function() {
  16260. this.isPlaying = false;
  16261. };
  16262. THREE.Audio.prototype.setLoop = function ( value ) {
  16263. this.source.loop = value;
  16264. };
  16265. THREE.Audio.prototype.getLoop = function () {
  16266. return this.source.loop;
  16267. };
  16268. THREE.Audio.prototype.setRefDistance = function ( value ) {
  16269. this.panner.refDistance = value;
  16270. };
  16271. THREE.Audio.prototype.getRefDistance = function () {
  16272. return this.panner.refDistance;
  16273. };
  16274. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  16275. this.panner.rolloffFactor = value;
  16276. };
  16277. THREE.Audio.prototype.getRolloffFactor = function () {
  16278. return this.panner.rolloffFactor;
  16279. };
  16280. THREE.Audio.prototype.setVolume = function ( value ) {
  16281. this.gain.gain.value = value;
  16282. };
  16283. THREE.Audio.prototype.getVolume = function () {
  16284. return this.gain.gain.value;
  16285. };
  16286. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  16287. var position = new THREE.Vector3();
  16288. return function updateMatrixWorld( force ) {
  16289. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16290. position.setFromMatrixPosition( this.matrixWorld );
  16291. this.panner.setPosition( position.x, position.y, position.z );
  16292. };
  16293. } )();
  16294. // File:src/extras/audio/AudioListener.js
  16295. /**
  16296. * @author mrdoob / http://mrdoob.com/
  16297. */
  16298. THREE.AudioListener = function () {
  16299. THREE.Object3D.call( this );
  16300. this.type = 'AudioListener';
  16301. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  16302. };
  16303. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  16304. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  16305. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  16306. var position = new THREE.Vector3();
  16307. var quaternion = new THREE.Quaternion();
  16308. var scale = new THREE.Vector3();
  16309. var orientation = new THREE.Vector3();
  16310. return function updateMatrixWorld( force ) {
  16311. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16312. var listener = this.context.listener;
  16313. var up = this.up;
  16314. this.matrixWorld.decompose( position, quaternion, scale );
  16315. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  16316. listener.setPosition( position.x, position.y, position.z );
  16317. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  16318. };
  16319. } )();
  16320. // File:src/extras/core/Curve.js
  16321. /**
  16322. * @author zz85 / http://www.lab4games.net/zz85/blog
  16323. * Extensible curve object
  16324. *
  16325. * Some common of Curve methods
  16326. * .getPoint(t), getTangent(t)
  16327. * .getPointAt(u), getTagentAt(u)
  16328. * .getPoints(), .getSpacedPoints()
  16329. * .getLength()
  16330. * .updateArcLengths()
  16331. *
  16332. * This following classes subclasses THREE.Curve:
  16333. *
  16334. * -- 2d classes --
  16335. * THREE.LineCurve
  16336. * THREE.QuadraticBezierCurve
  16337. * THREE.CubicBezierCurve
  16338. * THREE.SplineCurve
  16339. * THREE.ArcCurve
  16340. * THREE.EllipseCurve
  16341. *
  16342. * -- 3d classes --
  16343. * THREE.LineCurve3
  16344. * THREE.QuadraticBezierCurve3
  16345. * THREE.CubicBezierCurve3
  16346. * THREE.SplineCurve3
  16347. * THREE.ClosedSplineCurve3
  16348. *
  16349. * A series of curves can be represented as a THREE.CurvePath
  16350. *
  16351. **/
  16352. /**************************************************************
  16353. * Abstract Curve base class
  16354. **************************************************************/
  16355. THREE.Curve = function () {
  16356. };
  16357. // Virtual base class method to overwrite and implement in subclasses
  16358. // - t [0 .. 1]
  16359. THREE.Curve.prototype.getPoint = function ( t ) {
  16360. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  16361. return null;
  16362. };
  16363. // Get point at relative position in curve according to arc length
  16364. // - u [0 .. 1]
  16365. THREE.Curve.prototype.getPointAt = function ( u ) {
  16366. var t = this.getUtoTmapping( u );
  16367. return this.getPoint( t );
  16368. };
  16369. // Get sequence of points using getPoint( t )
  16370. THREE.Curve.prototype.getPoints = function ( divisions ) {
  16371. if ( ! divisions ) divisions = 5;
  16372. var d, pts = [];
  16373. for ( d = 0; d <= divisions; d ++ ) {
  16374. pts.push( this.getPoint( d / divisions ) );
  16375. }
  16376. return pts;
  16377. };
  16378. // Get sequence of points using getPointAt( u )
  16379. THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
  16380. if ( ! divisions ) divisions = 5;
  16381. var d, pts = [];
  16382. for ( d = 0; d <= divisions; d ++ ) {
  16383. pts.push( this.getPointAt( d / divisions ) );
  16384. }
  16385. return pts;
  16386. };
  16387. // Get total curve arc length
  16388. THREE.Curve.prototype.getLength = function () {
  16389. var lengths = this.getLengths();
  16390. return lengths[ lengths.length - 1 ];
  16391. };
  16392. // Get list of cumulative segment lengths
  16393. THREE.Curve.prototype.getLengths = function ( divisions ) {
  16394. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  16395. if ( this.cacheArcLengths
  16396. && ( this.cacheArcLengths.length === divisions + 1 )
  16397. && ! this.needsUpdate ) {
  16398. //console.log( "cached", this.cacheArcLengths );
  16399. return this.cacheArcLengths;
  16400. }
  16401. this.needsUpdate = false;
  16402. var cache = [];
  16403. var current, last = this.getPoint( 0 );
  16404. var p, sum = 0;
  16405. cache.push( 0 );
  16406. for ( p = 1; p <= divisions; p ++ ) {
  16407. current = this.getPoint ( p / divisions );
  16408. sum += current.distanceTo( last );
  16409. cache.push( sum );
  16410. last = current;
  16411. }
  16412. this.cacheArcLengths = cache;
  16413. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  16414. };
  16415. THREE.Curve.prototype.updateArcLengths = function() {
  16416. this.needsUpdate = true;
  16417. this.getLengths();
  16418. };
  16419. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  16420. THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
  16421. var arcLengths = this.getLengths();
  16422. var i = 0, il = arcLengths.length;
  16423. var targetArcLength; // The targeted u distance value to get
  16424. if ( distance ) {
  16425. targetArcLength = distance;
  16426. } else {
  16427. targetArcLength = u * arcLengths[ il - 1 ];
  16428. }
  16429. //var time = Date.now();
  16430. // binary search for the index with largest value smaller than target u distance
  16431. var low = 0, high = il - 1, comparison;
  16432. while ( low <= high ) {
  16433. 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
  16434. comparison = arcLengths[ i ] - targetArcLength;
  16435. if ( comparison < 0 ) {
  16436. low = i + 1;
  16437. } else if ( comparison > 0 ) {
  16438. high = i - 1;
  16439. } else {
  16440. high = i;
  16441. break;
  16442. // DONE
  16443. }
  16444. }
  16445. i = high;
  16446. //console.log('b' , i, low, high, Date.now()- time);
  16447. if ( arcLengths[ i ] === targetArcLength ) {
  16448. var t = i / ( il - 1 );
  16449. return t;
  16450. }
  16451. // we could get finer grain at lengths, or use simple interpolation between two points
  16452. var lengthBefore = arcLengths[ i ];
  16453. var lengthAfter = arcLengths[ i + 1 ];
  16454. var segmentLength = lengthAfter - lengthBefore;
  16455. // determine where we are between the 'before' and 'after' points
  16456. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  16457. // add that fractional amount to t
  16458. var t = ( i + segmentFraction ) / ( il - 1 );
  16459. return t;
  16460. };
  16461. // Returns a unit vector tangent at t
  16462. // In case any sub curve does not implement its tangent derivation,
  16463. // 2 points a small delta apart will be used to find its gradient
  16464. // which seems to give a reasonable approximation
  16465. THREE.Curve.prototype.getTangent = function( t ) {
  16466. var delta = 0.0001;
  16467. var t1 = t - delta;
  16468. var t2 = t + delta;
  16469. // Capping in case of danger
  16470. if ( t1 < 0 ) t1 = 0;
  16471. if ( t2 > 1 ) t2 = 1;
  16472. var pt1 = this.getPoint( t1 );
  16473. var pt2 = this.getPoint( t2 );
  16474. var vec = pt2.clone().sub( pt1 );
  16475. return vec.normalize();
  16476. };
  16477. THREE.Curve.prototype.getTangentAt = function ( u ) {
  16478. var t = this.getUtoTmapping( u );
  16479. return this.getTangent( t );
  16480. };
  16481. /**************************************************************
  16482. * Utils
  16483. **************************************************************/
  16484. THREE.Curve.Utils = {
  16485. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  16486. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  16487. },
  16488. // Puay Bing, thanks for helping with this derivative!
  16489. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  16490. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  16491. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  16492. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  16493. 3 * t * t * p3;
  16494. },
  16495. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  16496. // To check if my formulas are correct
  16497. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  16498. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  16499. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  16500. var h11 = 3 * t * t - 2 * t; // t3 − t2
  16501. return h00 + h10 + h01 + h11;
  16502. },
  16503. // Catmull-Rom
  16504. interpolate: function( p0, p1, p2, p3, t ) {
  16505. var v0 = ( p2 - p0 ) * 0.5;
  16506. var v1 = ( p3 - p1 ) * 0.5;
  16507. var t2 = t * t;
  16508. var t3 = t * t2;
  16509. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  16510. }
  16511. };
  16512. // TODO: Transformation for Curves?
  16513. /**************************************************************
  16514. * 3D Curves
  16515. **************************************************************/
  16516. // A Factory method for creating new curve subclasses
  16517. THREE.Curve.create = function ( constructor, getPointFunc ) {
  16518. constructor.prototype = Object.create( THREE.Curve.prototype );
  16519. constructor.prototype.constructor = constructor;
  16520. constructor.prototype.getPoint = getPointFunc;
  16521. return constructor;
  16522. };
  16523. // File:src/extras/core/CurvePath.js
  16524. /**
  16525. * @author zz85 / http://www.lab4games.net/zz85/blog
  16526. *
  16527. **/
  16528. /**************************************************************
  16529. * Curved Path - a curve path is simply a array of connected
  16530. * curves, but retains the api of a curve
  16531. **************************************************************/
  16532. THREE.CurvePath = function () {
  16533. this.curves = [];
  16534. this.bends = [];
  16535. this.autoClose = false; // Automatically closes the path
  16536. };
  16537. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  16538. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  16539. THREE.CurvePath.prototype.add = function ( curve ) {
  16540. this.curves.push( curve );
  16541. };
  16542. THREE.CurvePath.prototype.checkConnection = function() {
  16543. // TODO
  16544. // If the ending of curve is not connected to the starting
  16545. // or the next curve, then, this is not a real path
  16546. };
  16547. THREE.CurvePath.prototype.closePath = function() {
  16548. // TODO Test
  16549. // and verify for vector3 (needs to implement equals)
  16550. // Add a line curve if start and end of lines are not connected
  16551. var startPoint = this.curves[ 0 ].getPoint( 0 );
  16552. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  16553. if ( ! startPoint.equals( endPoint ) ) {
  16554. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  16555. }
  16556. };
  16557. // To get accurate point with reference to
  16558. // entire path distance at time t,
  16559. // following has to be done:
  16560. // 1. Length of each sub path have to be known
  16561. // 2. Locate and identify type of curve
  16562. // 3. Get t for the curve
  16563. // 4. Return curve.getPointAt(t')
  16564. THREE.CurvePath.prototype.getPoint = function( t ) {
  16565. var d = t * this.getLength();
  16566. var curveLengths = this.getCurveLengths();
  16567. var i = 0, diff, curve;
  16568. // To think about boundaries points.
  16569. while ( i < curveLengths.length ) {
  16570. if ( curveLengths[ i ] >= d ) {
  16571. diff = curveLengths[ i ] - d;
  16572. curve = this.curves[ i ];
  16573. var u = 1 - diff / curve.getLength();
  16574. return curve.getPointAt( u );
  16575. }
  16576. i ++;
  16577. }
  16578. return null;
  16579. // loop where sum != 0, sum > d , sum+1 <d
  16580. };
  16581. /*
  16582. THREE.CurvePath.prototype.getTangent = function( t ) {
  16583. };*/
  16584. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  16585. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  16586. // getPoint() depends on getLength
  16587. THREE.CurvePath.prototype.getLength = function() {
  16588. var lens = this.getCurveLengths();
  16589. return lens[ lens.length - 1 ];
  16590. };
  16591. // Compute lengths and cache them
  16592. // We cannot overwrite getLengths() because UtoT mapping uses it.
  16593. THREE.CurvePath.prototype.getCurveLengths = function() {
  16594. // We use cache values if curves and cache array are same length
  16595. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  16596. return this.cacheLengths;
  16597. }
  16598. // Get length of sub-curve
  16599. // Push sums into cached array
  16600. var lengths = [], sums = 0;
  16601. var i, il = this.curves.length;
  16602. for ( i = 0; i < il; i ++ ) {
  16603. sums += this.curves[ i ].getLength();
  16604. lengths.push( sums );
  16605. }
  16606. this.cacheLengths = lengths;
  16607. return lengths;
  16608. };
  16609. // Returns min and max coordinates
  16610. THREE.CurvePath.prototype.getBoundingBox = function () {
  16611. var points = this.getPoints();
  16612. var maxX, maxY, maxZ;
  16613. var minX, minY, minZ;
  16614. maxX = maxY = Number.NEGATIVE_INFINITY;
  16615. minX = minY = Number.POSITIVE_INFINITY;
  16616. var p, i, il, sum;
  16617. var v3 = points[ 0 ] instanceof THREE.Vector3;
  16618. sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
  16619. for ( i = 0, il = points.length; i < il; i ++ ) {
  16620. p = points[ i ];
  16621. if ( p.x > maxX ) maxX = p.x;
  16622. else if ( p.x < minX ) minX = p.x;
  16623. if ( p.y > maxY ) maxY = p.y;
  16624. else if ( p.y < minY ) minY = p.y;
  16625. if ( v3 ) {
  16626. if ( p.z > maxZ ) maxZ = p.z;
  16627. else if ( p.z < minZ ) minZ = p.z;
  16628. }
  16629. sum.add( p );
  16630. }
  16631. var ret = {
  16632. minX: minX,
  16633. minY: minY,
  16634. maxX: maxX,
  16635. maxY: maxY
  16636. };
  16637. if ( v3 ) {
  16638. ret.maxZ = maxZ;
  16639. ret.minZ = minZ;
  16640. }
  16641. return ret;
  16642. };
  16643. /**************************************************************
  16644. * Create Geometries Helpers
  16645. **************************************************************/
  16646. /// Generate geometry from path points (for Line or Points objects)
  16647. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  16648. var pts = this.getPoints( divisions, true );
  16649. return this.createGeometry( pts );
  16650. };
  16651. // Generate geometry from equidistant sampling along the path
  16652. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  16653. var pts = this.getSpacedPoints( divisions, true );
  16654. return this.createGeometry( pts );
  16655. };
  16656. THREE.CurvePath.prototype.createGeometry = function( points ) {
  16657. var geometry = new THREE.Geometry();
  16658. for ( var i = 0; i < points.length; i ++ ) {
  16659. geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, points[ i ].z || 0 ) );
  16660. }
  16661. return geometry;
  16662. };
  16663. /**************************************************************
  16664. * Bend / Wrap Helper Methods
  16665. **************************************************************/
  16666. // Wrap path / Bend modifiers?
  16667. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  16668. this.bends.push( bendpath );
  16669. };
  16670. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  16671. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  16672. var i, il;
  16673. if ( ! bends ) {
  16674. bends = this.bends;
  16675. }
  16676. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16677. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16678. }
  16679. return oldPts;
  16680. };
  16681. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  16682. var oldPts = this.getSpacedPoints( segments );
  16683. var i, il;
  16684. if ( ! bends ) {
  16685. bends = this.bends;
  16686. }
  16687. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16688. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16689. }
  16690. return oldPts;
  16691. };
  16692. // This returns getPoints() bend/wrapped around the contour of a path.
  16693. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  16694. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  16695. var bounds = this.getBoundingBox();
  16696. var i, il, p, oldX, oldY, xNorm;
  16697. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  16698. p = oldPts[ i ];
  16699. oldX = p.x;
  16700. oldY = p.y;
  16701. xNorm = oldX / bounds.maxX;
  16702. // If using actual distance, for length > path, requires line extrusions
  16703. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  16704. xNorm = path.getUtoTmapping( xNorm, oldX );
  16705. // check for out of bounds?
  16706. var pathPt = path.getPoint( xNorm );
  16707. var normal = path.getTangent( xNorm );
  16708. normal.set( - normal.y, normal.x ).multiplyScalar( oldY );
  16709. p.x = pathPt.x + normal.x;
  16710. p.y = pathPt.y + normal.y;
  16711. }
  16712. return oldPts;
  16713. };
  16714. // File:src/extras/core/Path.js
  16715. /**
  16716. * @author zz85 / http://www.lab4games.net/zz85/blog
  16717. * Creates free form 2d path using series of points, lines or curves.
  16718. *
  16719. **/
  16720. THREE.Path = function ( points ) {
  16721. THREE.CurvePath.call( this );
  16722. this.actions = [];
  16723. if ( points ) {
  16724. this.fromPoints( points );
  16725. }
  16726. };
  16727. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  16728. THREE.Path.prototype.constructor = THREE.Path;
  16729. THREE.PathActions = {
  16730. MOVE_TO: 'moveTo',
  16731. LINE_TO: 'lineTo',
  16732. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  16733. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  16734. CSPLINE_THRU: 'splineThru', // Catmull-Rom spline
  16735. ARC: 'arc', // Circle
  16736. ELLIPSE: 'ellipse'
  16737. };
  16738. // TODO Clean up PATH API
  16739. // Create path using straight lines to connect all points
  16740. // - vectors: array of Vector2
  16741. THREE.Path.prototype.fromPoints = function ( vectors ) {
  16742. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  16743. for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
  16744. this.lineTo( vectors[ v ].x, vectors[ v ].y );
  16745. }
  16746. };
  16747. // startPath() endPath()?
  16748. THREE.Path.prototype.moveTo = function ( x, y ) {
  16749. var args = Array.prototype.slice.call( arguments );
  16750. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  16751. };
  16752. THREE.Path.prototype.lineTo = function ( x, y ) {
  16753. var args = Array.prototype.slice.call( arguments );
  16754. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16755. var x0 = lastargs[ lastargs.length - 2 ];
  16756. var y0 = lastargs[ lastargs.length - 1 ];
  16757. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  16758. this.curves.push( curve );
  16759. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  16760. };
  16761. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  16762. var args = Array.prototype.slice.call( arguments );
  16763. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16764. var x0 = lastargs[ lastargs.length - 2 ];
  16765. var y0 = lastargs[ lastargs.length - 1 ];
  16766. var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
  16767. new THREE.Vector2( aCPx, aCPy ),
  16768. new THREE.Vector2( aX, aY ) );
  16769. this.curves.push( curve );
  16770. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  16771. };
  16772. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
  16773. aCP2x, aCP2y,
  16774. aX, aY ) {
  16775. var args = Array.prototype.slice.call( arguments );
  16776. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16777. var x0 = lastargs[ lastargs.length - 2 ];
  16778. var y0 = lastargs[ lastargs.length - 1 ];
  16779. var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
  16780. new THREE.Vector2( aCP1x, aCP1y ),
  16781. new THREE.Vector2( aCP2x, aCP2y ),
  16782. new THREE.Vector2( aX, aY ) );
  16783. this.curves.push( curve );
  16784. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  16785. };
  16786. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  16787. var args = Array.prototype.slice.call( arguments );
  16788. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16789. var x0 = lastargs[ lastargs.length - 2 ];
  16790. var y0 = lastargs[ lastargs.length - 1 ];
  16791. //---
  16792. var npts = [ new THREE.Vector2( x0, y0 ) ];
  16793. Array.prototype.push.apply( npts, pts );
  16794. var curve = new THREE.SplineCurve( npts );
  16795. this.curves.push( curve );
  16796. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  16797. };
  16798. // FUTURE: Change the API or follow canvas API?
  16799. THREE.Path.prototype.arc = function ( aX, aY, aRadius,
  16800. aStartAngle, aEndAngle, aClockwise ) {
  16801. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16802. var x0 = lastargs[ lastargs.length - 2 ];
  16803. var y0 = lastargs[ lastargs.length - 1 ];
  16804. this.absarc( aX + x0, aY + y0, aRadius,
  16805. aStartAngle, aEndAngle, aClockwise );
  16806. };
  16807. THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
  16808. aStartAngle, aEndAngle, aClockwise ) {
  16809. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  16810. };
  16811. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
  16812. aStartAngle, aEndAngle, aClockwise, aRotation ) {
  16813. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16814. var x0 = lastargs[ lastargs.length - 2 ];
  16815. var y0 = lastargs[ lastargs.length - 1 ];
  16816. this.absellipse( aX + x0, aY + y0, xRadius, yRadius,
  16817. aStartAngle, aEndAngle, aClockwise, aRotation );
  16818. };
  16819. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
  16820. aStartAngle, aEndAngle, aClockwise, aRotation ) {
  16821. var args = [
  16822. aX, aY,
  16823. xRadius, yRadius,
  16824. aStartAngle, aEndAngle,
  16825. aClockwise,
  16826. aRotation || 0 // aRotation is optional.
  16827. ];
  16828. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
  16829. aStartAngle, aEndAngle, aClockwise, aRotation );
  16830. this.curves.push( curve );
  16831. var lastPoint = curve.getPoint( 1 );
  16832. args.push( lastPoint.x );
  16833. args.push( lastPoint.y );
  16834. this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
  16835. };
  16836. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  16837. if ( ! divisions ) divisions = 40;
  16838. var points = [];
  16839. for ( var i = 0; i < divisions; i ++ ) {
  16840. points.push( this.getPoint( i / divisions ) );
  16841. //if( !this.getPoint( i / divisions ) ) throw "DIE";
  16842. }
  16843. // if ( closedPath ) {
  16844. //
  16845. // points.push( points[ 0 ] );
  16846. //
  16847. // }
  16848. return points;
  16849. };
  16850. /* Return an array of vectors based on contour of the path */
  16851. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  16852. if ( this.useSpacedPoints ) {
  16853. return this.getSpacedPoints( divisions, closedPath );
  16854. }
  16855. divisions = divisions || 12;
  16856. var points = [];
  16857. var i, il, item, action, args;
  16858. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  16859. laste, j,
  16860. t, tx, ty;
  16861. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  16862. item = this.actions[ i ];
  16863. action = item.action;
  16864. args = item.args;
  16865. switch ( action ) {
  16866. case THREE.PathActions.MOVE_TO:
  16867. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16868. break;
  16869. case THREE.PathActions.LINE_TO:
  16870. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16871. break;
  16872. case THREE.PathActions.QUADRATIC_CURVE_TO:
  16873. cpx = args[ 2 ];
  16874. cpy = args[ 3 ];
  16875. cpx1 = args[ 0 ];
  16876. cpy1 = args[ 1 ];
  16877. if ( points.length > 0 ) {
  16878. laste = points[ points.length - 1 ];
  16879. cpx0 = laste.x;
  16880. cpy0 = laste.y;
  16881. } else {
  16882. laste = this.actions[ i - 1 ].args;
  16883. cpx0 = laste[ laste.length - 2 ];
  16884. cpy0 = laste[ laste.length - 1 ];
  16885. }
  16886. for ( j = 1; j <= divisions; j ++ ) {
  16887. t = j / divisions;
  16888. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  16889. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  16890. points.push( new THREE.Vector2( tx, ty ) );
  16891. }
  16892. break;
  16893. case THREE.PathActions.BEZIER_CURVE_TO:
  16894. cpx = args[ 4 ];
  16895. cpy = args[ 5 ];
  16896. cpx1 = args[ 0 ];
  16897. cpy1 = args[ 1 ];
  16898. cpx2 = args[ 2 ];
  16899. cpy2 = args[ 3 ];
  16900. if ( points.length > 0 ) {
  16901. laste = points[ points.length - 1 ];
  16902. cpx0 = laste.x;
  16903. cpy0 = laste.y;
  16904. } else {
  16905. laste = this.actions[ i - 1 ].args;
  16906. cpx0 = laste[ laste.length - 2 ];
  16907. cpy0 = laste[ laste.length - 1 ];
  16908. }
  16909. for ( j = 1; j <= divisions; j ++ ) {
  16910. t = j / divisions;
  16911. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  16912. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  16913. points.push( new THREE.Vector2( tx, ty ) );
  16914. }
  16915. break;
  16916. case THREE.PathActions.CSPLINE_THRU:
  16917. laste = this.actions[ i - 1 ].args;
  16918. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  16919. var spts = [ last ];
  16920. var n = divisions * args[ 0 ].length;
  16921. spts = spts.concat( args[ 0 ] );
  16922. var spline = new THREE.SplineCurve( spts );
  16923. for ( j = 1; j <= n; j ++ ) {
  16924. points.push( spline.getPointAt( j / n ) );
  16925. }
  16926. break;
  16927. case THREE.PathActions.ARC:
  16928. var aX = args[ 0 ], aY = args[ 1 ],
  16929. aRadius = args[ 2 ],
  16930. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  16931. aClockwise = !! args[ 5 ];
  16932. var deltaAngle = aEndAngle - aStartAngle;
  16933. var angle;
  16934. var tdivisions = divisions * 2;
  16935. for ( j = 1; j <= tdivisions; j ++ ) {
  16936. t = j / tdivisions;
  16937. if ( ! aClockwise ) {
  16938. t = 1 - t;
  16939. }
  16940. angle = aStartAngle + t * deltaAngle;
  16941. tx = aX + aRadius * Math.cos( angle );
  16942. ty = aY + aRadius * Math.sin( angle );
  16943. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16944. points.push( new THREE.Vector2( tx, ty ) );
  16945. }
  16946. //console.log(points);
  16947. break;
  16948. case THREE.PathActions.ELLIPSE:
  16949. var aX = args[ 0 ], aY = args[ 1 ],
  16950. xRadius = args[ 2 ],
  16951. yRadius = args[ 3 ],
  16952. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  16953. aClockwise = !! args[ 6 ],
  16954. aRotation = args[ 7 ];
  16955. var deltaAngle = aEndAngle - aStartAngle;
  16956. var angle;
  16957. var tdivisions = divisions * 2;
  16958. var cos, sin;
  16959. if ( aRotation !== 0 ) {
  16960. cos = Math.cos( aRotation );
  16961. sin = Math.sin( aRotation );
  16962. }
  16963. for ( j = 1; j <= tdivisions; j ++ ) {
  16964. t = j / tdivisions;
  16965. if ( ! aClockwise ) {
  16966. t = 1 - t;
  16967. }
  16968. angle = aStartAngle + t * deltaAngle;
  16969. tx = aX + xRadius * Math.cos( angle );
  16970. ty = aY + yRadius * Math.sin( angle );
  16971. if ( aRotation !== 0 ) {
  16972. var x = tx, y = ty;
  16973. // Rotate the point about the center of the ellipse.
  16974. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  16975. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  16976. }
  16977. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16978. points.push( new THREE.Vector2( tx, ty ) );
  16979. }
  16980. //console.log(points);
  16981. break;
  16982. } // end switch
  16983. }
  16984. // Normalize to remove the closing point by default.
  16985. var lastPoint = points[ points.length - 1 ];
  16986. var EPSILON = 0.0000000001;
  16987. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < EPSILON &&
  16988. Math.abs( lastPoint.y - points[ 0 ].y ) < EPSILON )
  16989. points.splice( points.length - 1, 1 );
  16990. if ( closedPath ) {
  16991. points.push( points[ 0 ] );
  16992. }
  16993. return points;
  16994. };
  16995. //
  16996. // Breaks path into shapes
  16997. //
  16998. // Assumptions (if parameter isCCW==true the opposite holds):
  16999. // - solid shapes are defined clockwise (CW)
  17000. // - holes are defined counterclockwise (CCW)
  17001. //
  17002. // If parameter noHoles==true:
  17003. // - all subPaths are regarded as solid shapes
  17004. // - definition order CW/CCW has no relevance
  17005. //
  17006. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  17007. function extractSubpaths( inActions ) {
  17008. var i, il, item, action, args;
  17009. var subPaths = [], lastPath = new THREE.Path();
  17010. for ( i = 0, il = inActions.length; i < il; i ++ ) {
  17011. item = inActions[ i ];
  17012. args = item.args;
  17013. action = item.action;
  17014. if ( action === THREE.PathActions.MOVE_TO ) {
  17015. if ( lastPath.actions.length !== 0 ) {
  17016. subPaths.push( lastPath );
  17017. lastPath = new THREE.Path();
  17018. }
  17019. }
  17020. lastPath[ action ].apply( lastPath, args );
  17021. }
  17022. if ( lastPath.actions.length !== 0 ) {
  17023. subPaths.push( lastPath );
  17024. }
  17025. // console.log(subPaths);
  17026. return subPaths;
  17027. }
  17028. function toShapesNoHoles( inSubpaths ) {
  17029. var shapes = [];
  17030. for ( var i = 0, il = inSubpaths.length; i < il; i ++ ) {
  17031. var tmpPath = inSubpaths[ i ];
  17032. var tmpShape = new THREE.Shape();
  17033. tmpShape.actions = tmpPath.actions;
  17034. tmpShape.curves = tmpPath.curves;
  17035. shapes.push( tmpShape );
  17036. }
  17037. //console.log("shape", shapes);
  17038. return shapes;
  17039. }
  17040. function isPointInsidePolygon( inPt, inPolygon ) {
  17041. var EPSILON = 0.0000000001;
  17042. var polyLen = inPolygon.length;
  17043. // inPt on polygon contour => immediate success or
  17044. // toggling of inside/outside at every single! intersection point of an edge
  17045. // with the horizontal line through inPt, left of inPt
  17046. // not counting lowerY endpoints of edges and whole edges on that line
  17047. var inside = false;
  17048. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  17049. var edgeLowPt = inPolygon[ p ];
  17050. var edgeHighPt = inPolygon[ q ];
  17051. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  17052. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  17053. if ( Math.abs( edgeDy ) > EPSILON ) {
  17054. // not parallel
  17055. if ( edgeDy < 0 ) {
  17056. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  17057. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  17058. }
  17059. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  17060. if ( inPt.y === edgeLowPt.y ) {
  17061. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  17062. // continue; // no intersection or edgeLowPt => doesn't count !!!
  17063. } else {
  17064. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  17065. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  17066. if ( perpEdge < 0 ) continue;
  17067. inside = ! inside; // true intersection left of inPt
  17068. }
  17069. } else {
  17070. // parallel or collinear
  17071. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  17072. // edge lies on the same horizontal line as inPt
  17073. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  17074. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  17075. // continue;
  17076. }
  17077. }
  17078. return inside;
  17079. }
  17080. var subPaths = extractSubpaths( this.actions );
  17081. if ( subPaths.length === 0 ) return [];
  17082. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  17083. var solid, tmpPath, tmpShape, shapes = [];
  17084. if ( subPaths.length === 1 ) {
  17085. tmpPath = subPaths[ 0 ];
  17086. tmpShape = new THREE.Shape();
  17087. tmpShape.actions = tmpPath.actions;
  17088. tmpShape.curves = tmpPath.curves;
  17089. shapes.push( tmpShape );
  17090. return shapes;
  17091. }
  17092. var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  17093. holesFirst = isCCW ? ! holesFirst : holesFirst;
  17094. // console.log("Holes first", holesFirst);
  17095. var betterShapeHoles = [];
  17096. var newShapes = [];
  17097. var newShapeHoles = [];
  17098. var mainIdx = 0;
  17099. var tmpPoints;
  17100. newShapes[ mainIdx ] = undefined;
  17101. newShapeHoles[ mainIdx ] = [];
  17102. var i, il;
  17103. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  17104. tmpPath = subPaths[ i ];
  17105. tmpPoints = tmpPath.getPoints();
  17106. solid = THREE.Shape.Utils.isClockWise( tmpPoints );
  17107. solid = isCCW ? ! solid : solid;
  17108. if ( solid ) {
  17109. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  17110. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  17111. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  17112. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  17113. if ( holesFirst ) mainIdx ++;
  17114. newShapeHoles[ mainIdx ] = [];
  17115. //console.log('cw', i);
  17116. } else {
  17117. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  17118. //console.log('ccw', i);
  17119. }
  17120. }
  17121. // only Holes? -> probably all Shapes with wrong orientation
  17122. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  17123. if ( newShapes.length > 1 ) {
  17124. var ambiguous = false;
  17125. var toChange = [];
  17126. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  17127. betterShapeHoles[ sIdx ] = [];
  17128. }
  17129. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  17130. var sho = newShapeHoles[ sIdx ];
  17131. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  17132. var ho = sho[ hIdx ];
  17133. var hole_unassigned = true;
  17134. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  17135. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  17136. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  17137. if ( hole_unassigned ) {
  17138. hole_unassigned = false;
  17139. betterShapeHoles[ s2Idx ].push( ho );
  17140. } else {
  17141. ambiguous = true;
  17142. }
  17143. }
  17144. }
  17145. if ( hole_unassigned ) {
  17146. betterShapeHoles[ sIdx ].push( ho );
  17147. }
  17148. }
  17149. }
  17150. // console.log("ambiguous: ", ambiguous);
  17151. if ( toChange.length > 0 ) {
  17152. // console.log("to change: ", toChange);
  17153. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  17154. }
  17155. }
  17156. var tmpHoles, j, jl;
  17157. for ( i = 0, il = newShapes.length; i < il; i ++ ) {
  17158. tmpShape = newShapes[ i ].s;
  17159. shapes.push( tmpShape );
  17160. tmpHoles = newShapeHoles[ i ];
  17161. for ( j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  17162. tmpShape.holes.push( tmpHoles[ j ].h );
  17163. }
  17164. }
  17165. //console.log("shape", shapes);
  17166. return shapes;
  17167. };
  17168. // File:src/extras/core/Shape.js
  17169. /**
  17170. * @author zz85 / http://www.lab4games.net/zz85/blog
  17171. * Defines a 2d shape plane using paths.
  17172. **/
  17173. // STEP 1 Create a path.
  17174. // STEP 2 Turn path into shape.
  17175. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  17176. // STEP 3a - Extract points from each shape, turn to vertices
  17177. // STEP 3b - Triangulate each shape, add faces.
  17178. THREE.Shape = function () {
  17179. THREE.Path.apply( this, arguments );
  17180. this.holes = [];
  17181. };
  17182. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  17183. THREE.Shape.prototype.constructor = THREE.Shape;
  17184. // Convenience method to return ExtrudeGeometry
  17185. THREE.Shape.prototype.extrude = function ( options ) {
  17186. var extruded = new THREE.ExtrudeGeometry( this, options );
  17187. return extruded;
  17188. };
  17189. // Convenience method to return ShapeGeometry
  17190. THREE.Shape.prototype.makeGeometry = function ( options ) {
  17191. var geometry = new THREE.ShapeGeometry( this, options );
  17192. return geometry;
  17193. };
  17194. // Get points of holes
  17195. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  17196. var i, il = this.holes.length, holesPts = [];
  17197. for ( i = 0; i < il; i ++ ) {
  17198. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  17199. }
  17200. return holesPts;
  17201. };
  17202. // Get points of holes (spaced by regular distance)
  17203. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  17204. var i, il = this.holes.length, holesPts = [];
  17205. for ( i = 0; i < il; i ++ ) {
  17206. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  17207. }
  17208. return holesPts;
  17209. };
  17210. // Get points of shape and holes (keypoints based on segments parameter)
  17211. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  17212. return {
  17213. shape: this.getTransformedPoints( divisions ),
  17214. holes: this.getPointsHoles( divisions )
  17215. };
  17216. };
  17217. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  17218. if ( this.useSpacedPoints ) {
  17219. return this.extractAllSpacedPoints( divisions );
  17220. }
  17221. return this.extractAllPoints( divisions );
  17222. };
  17223. //
  17224. // THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  17225. //
  17226. // return {
  17227. //
  17228. // shape: this.transform( bend, divisions ),
  17229. // holes: this.getPointsHoles( divisions, bend )
  17230. //
  17231. // };
  17232. //
  17233. // };
  17234. // Get points of shape and holes (spaced by regular distance)
  17235. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  17236. return {
  17237. shape: this.getTransformedSpacedPoints( divisions ),
  17238. holes: this.getSpacedPointsHoles( divisions )
  17239. };
  17240. };
  17241. /**************************************************************
  17242. * Utils
  17243. **************************************************************/
  17244. THREE.Shape.Utils = {
  17245. triangulateShape: function ( contour, holes ) {
  17246. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  17247. // inOtherPt needs to be collinear to the inSegment
  17248. if ( inSegPt1.x !== inSegPt2.x ) {
  17249. if ( inSegPt1.x < inSegPt2.x ) {
  17250. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  17251. } else {
  17252. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  17253. }
  17254. } else {
  17255. if ( inSegPt1.y < inSegPt2.y ) {
  17256. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  17257. } else {
  17258. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  17259. }
  17260. }
  17261. }
  17262. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  17263. var EPSILON = 0.0000000001;
  17264. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  17265. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  17266. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  17267. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  17268. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  17269. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  17270. if ( Math.abs( limit ) > EPSILON ) {
  17271. // not parallel
  17272. var perpSeg2;
  17273. if ( limit > 0 ) {
  17274. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  17275. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17276. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  17277. } else {
  17278. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  17279. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17280. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  17281. }
  17282. // i.e. to reduce rounding errors
  17283. // intersection at endpoint of segment#1?
  17284. if ( perpSeg2 === 0 ) {
  17285. if ( ( inExcludeAdjacentSegs ) &&
  17286. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17287. return [ inSeg1Pt1 ];
  17288. }
  17289. if ( perpSeg2 === limit ) {
  17290. if ( ( inExcludeAdjacentSegs ) &&
  17291. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17292. return [ inSeg1Pt2 ];
  17293. }
  17294. // intersection at endpoint of segment#2?
  17295. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  17296. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  17297. // return real intersection point
  17298. var factorSeg1 = perpSeg2 / limit;
  17299. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  17300. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  17301. } else {
  17302. // parallel or collinear
  17303. if ( ( perpSeg1 !== 0 ) ||
  17304. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  17305. // they are collinear or degenerate
  17306. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  17307. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  17308. // both segments are points
  17309. if ( seg1Pt && seg2Pt ) {
  17310. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  17311. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  17312. return [ inSeg1Pt1 ]; // they are the same point
  17313. }
  17314. // segment#1 is a single point
  17315. if ( seg1Pt ) {
  17316. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  17317. return [ inSeg1Pt1 ];
  17318. }
  17319. // segment#2 is a single point
  17320. if ( seg2Pt ) {
  17321. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  17322. return [ inSeg2Pt1 ];
  17323. }
  17324. // they are collinear segments, which might overlap
  17325. var seg1min, seg1max, seg1minVal, seg1maxVal;
  17326. var seg2min, seg2max, seg2minVal, seg2maxVal;
  17327. if ( seg1dx !== 0 ) {
  17328. // the segments are NOT on a vertical line
  17329. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  17330. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  17331. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  17332. } else {
  17333. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  17334. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  17335. }
  17336. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  17337. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  17338. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  17339. } else {
  17340. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  17341. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  17342. }
  17343. } else {
  17344. // the segments are on a vertical line
  17345. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  17346. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  17347. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  17348. } else {
  17349. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  17350. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  17351. }
  17352. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  17353. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  17354. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  17355. } else {
  17356. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  17357. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  17358. }
  17359. }
  17360. if ( seg1minVal <= seg2minVal ) {
  17361. if ( seg1maxVal < seg2minVal ) return [];
  17362. if ( seg1maxVal === seg2minVal ) {
  17363. if ( inExcludeAdjacentSegs ) return [];
  17364. return [ seg2min ];
  17365. }
  17366. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  17367. return [ seg2min, seg2max ];
  17368. } else {
  17369. if ( seg1minVal > seg2maxVal ) return [];
  17370. if ( seg1minVal === seg2maxVal ) {
  17371. if ( inExcludeAdjacentSegs ) return [];
  17372. return [ seg1min ];
  17373. }
  17374. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  17375. return [ seg1min, seg2max ];
  17376. }
  17377. }
  17378. }
  17379. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  17380. // The order of legs is important
  17381. var EPSILON = 0.0000000001;
  17382. // translation of all points, so that Vertex is at (0,0)
  17383. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  17384. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  17385. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  17386. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  17387. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  17388. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  17389. if ( Math.abs( from2toAngle ) > EPSILON ) {
  17390. // angle != 180 deg.
  17391. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  17392. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  17393. if ( from2toAngle > 0 ) {
  17394. // main angle < 180 deg.
  17395. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  17396. } else {
  17397. // main angle > 180 deg.
  17398. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  17399. }
  17400. } else {
  17401. // angle == 180 deg.
  17402. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  17403. return ( from2otherAngle > 0 );
  17404. }
  17405. }
  17406. function removeHoles( contour, holes ) {
  17407. var shape = contour.concat(); // work on this shape
  17408. var hole;
  17409. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  17410. // Check if hole point lies within angle around shape point
  17411. var lastShapeIdx = shape.length - 1;
  17412. var prevShapeIdx = inShapeIdx - 1;
  17413. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  17414. var nextShapeIdx = inShapeIdx + 1;
  17415. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  17416. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  17417. if ( ! insideAngle ) {
  17418. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  17419. return false;
  17420. }
  17421. // Check if shape point lies within angle around hole point
  17422. var lastHoleIdx = hole.length - 1;
  17423. var prevHoleIdx = inHoleIdx - 1;
  17424. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  17425. var nextHoleIdx = inHoleIdx + 1;
  17426. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  17427. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  17428. if ( ! insideAngle ) {
  17429. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  17430. return false;
  17431. }
  17432. return true;
  17433. }
  17434. function intersectsShapeEdge( inShapePt, inHolePt ) {
  17435. // checks for intersections with shape edges
  17436. var sIdx, nextIdx, intersection;
  17437. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  17438. nextIdx = sIdx + 1; nextIdx %= shape.length;
  17439. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  17440. if ( intersection.length > 0 ) return true;
  17441. }
  17442. return false;
  17443. }
  17444. var indepHoles = [];
  17445. function intersectsHoleEdge( inShapePt, inHolePt ) {
  17446. // checks for intersections with hole edges
  17447. var ihIdx, chkHole,
  17448. hIdx, nextIdx, intersection;
  17449. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  17450. chkHole = holes[ indepHoles[ ihIdx ]];
  17451. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  17452. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  17453. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  17454. if ( intersection.length > 0 ) return true;
  17455. }
  17456. }
  17457. return false;
  17458. }
  17459. var holeIndex, shapeIndex,
  17460. shapePt, holePt,
  17461. holeIdx, cutKey, failedCuts = [],
  17462. tmpShape1, tmpShape2,
  17463. tmpHole1, tmpHole2;
  17464. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17465. indepHoles.push( h );
  17466. }
  17467. var minShapeIndex = 0;
  17468. var counter = indepHoles.length * 2;
  17469. while ( indepHoles.length > 0 ) {
  17470. counter --;
  17471. if ( counter < 0 ) {
  17472. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  17473. break;
  17474. }
  17475. // search for shape-vertex and hole-vertex,
  17476. // which can be connected without intersections
  17477. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  17478. shapePt = shape[ shapeIndex ];
  17479. holeIndex = - 1;
  17480. // search for hole which can be reached without intersections
  17481. for ( var h = 0; h < indepHoles.length; h ++ ) {
  17482. holeIdx = indepHoles[ h ];
  17483. // prevent multiple checks
  17484. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  17485. if ( failedCuts[ cutKey ] !== undefined ) continue;
  17486. hole = holes[ holeIdx ];
  17487. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  17488. holePt = hole[ h2 ];
  17489. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  17490. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  17491. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  17492. holeIndex = h2;
  17493. indepHoles.splice( h, 1 );
  17494. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  17495. tmpShape2 = shape.slice( shapeIndex );
  17496. tmpHole1 = hole.slice( holeIndex );
  17497. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  17498. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  17499. minShapeIndex = shapeIndex;
  17500. // Debug only, to show the selected cuts
  17501. // glob_CutLines.push( [ shapePt, holePt ] );
  17502. break;
  17503. }
  17504. if ( holeIndex >= 0 ) break; // hole-vertex found
  17505. failedCuts[ cutKey ] = true; // remember failure
  17506. }
  17507. if ( holeIndex >= 0 ) break; // hole-vertex found
  17508. }
  17509. }
  17510. return shape; /* shape with no holes */
  17511. }
  17512. var i, il, f, face,
  17513. key, index,
  17514. allPointsMap = {};
  17515. // 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.
  17516. var allpoints = contour.concat();
  17517. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17518. Array.prototype.push.apply( allpoints, holes[ h ] );
  17519. }
  17520. //console.log( "allpoints",allpoints, allpoints.length );
  17521. // prepare all points map
  17522. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  17523. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  17524. if ( allPointsMap[ key ] !== undefined ) {
  17525. console.warn( "THREE.Shape: Duplicate point", key );
  17526. }
  17527. allPointsMap[ key ] = i;
  17528. }
  17529. // remove holes by cutting paths to holes and adding them to the shape
  17530. var shapeWithoutHoles = removeHoles( contour, holes );
  17531. var triangles = THREE.FontUtils.Triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  17532. //console.log( "triangles",triangles, triangles.length );
  17533. // check all face vertices against all points map
  17534. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  17535. face = triangles[ i ];
  17536. for ( f = 0; f < 3; f ++ ) {
  17537. key = face[ f ].x + ":" + face[ f ].y;
  17538. index = allPointsMap[ key ];
  17539. if ( index !== undefined ) {
  17540. face[ f ] = index;
  17541. }
  17542. }
  17543. }
  17544. return triangles.concat();
  17545. },
  17546. isClockWise: function ( pts ) {
  17547. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  17548. },
  17549. // Bezier Curves formulas obtained from
  17550. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  17551. // Quad Bezier Functions
  17552. b2p0: function ( t, p ) {
  17553. var k = 1 - t;
  17554. return k * k * p;
  17555. },
  17556. b2p1: function ( t, p ) {
  17557. return 2 * ( 1 - t ) * t * p;
  17558. },
  17559. b2p2: function ( t, p ) {
  17560. return t * t * p;
  17561. },
  17562. b2: function ( t, p0, p1, p2 ) {
  17563. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  17564. },
  17565. // Cubic Bezier Functions
  17566. b3p0: function ( t, p ) {
  17567. var k = 1 - t;
  17568. return k * k * k * p;
  17569. },
  17570. b3p1: function ( t, p ) {
  17571. var k = 1 - t;
  17572. return 3 * k * k * t * p;
  17573. },
  17574. b3p2: function ( t, p ) {
  17575. var k = 1 - t;
  17576. return 3 * k * t * t * p;
  17577. },
  17578. b3p3: function ( t, p ) {
  17579. return t * t * t * p;
  17580. },
  17581. b3: function ( t, p0, p1, p2, p3 ) {
  17582. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  17583. }
  17584. };
  17585. // File:src/extras/curves/LineCurve.js
  17586. /**************************************************************
  17587. * Line
  17588. **************************************************************/
  17589. THREE.LineCurve = function ( v1, v2 ) {
  17590. this.v1 = v1;
  17591. this.v2 = v2;
  17592. };
  17593. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  17594. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  17595. THREE.LineCurve.prototype.getPoint = function ( t ) {
  17596. var point = this.v2.clone().sub( this.v1 );
  17597. point.multiplyScalar( t ).add( this.v1 );
  17598. return point;
  17599. };
  17600. // Line curve is linear, so we can overwrite default getPointAt
  17601. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  17602. return this.getPoint( u );
  17603. };
  17604. THREE.LineCurve.prototype.getTangent = function( t ) {
  17605. var tangent = this.v2.clone().sub( this.v1 );
  17606. return tangent.normalize();
  17607. };
  17608. // File:src/extras/curves/QuadraticBezierCurve.js
  17609. /**************************************************************
  17610. * Quadratic Bezier curve
  17611. **************************************************************/
  17612. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  17613. this.v0 = v0;
  17614. this.v1 = v1;
  17615. this.v2 = v2;
  17616. };
  17617. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17618. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  17619. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  17620. var vector = new THREE.Vector2();
  17621. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17622. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17623. return vector;
  17624. };
  17625. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  17626. var vector = new THREE.Vector2();
  17627. vector.x = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  17628. vector.y = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  17629. // returns unit vector
  17630. return vector.normalize();
  17631. };
  17632. // File:src/extras/curves/CubicBezierCurve.js
  17633. /**************************************************************
  17634. * Cubic Bezier curve
  17635. **************************************************************/
  17636. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  17637. this.v0 = v0;
  17638. this.v1 = v1;
  17639. this.v2 = v2;
  17640. this.v3 = v3;
  17641. };
  17642. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17643. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  17644. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  17645. var tx, ty;
  17646. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17647. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17648. return new THREE.Vector2( tx, ty );
  17649. };
  17650. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  17651. var tx, ty;
  17652. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17653. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17654. var tangent = new THREE.Vector2( tx, ty );
  17655. tangent.normalize();
  17656. return tangent;
  17657. };
  17658. // File:src/extras/curves/SplineCurve.js
  17659. /**************************************************************
  17660. * Spline curve
  17661. **************************************************************/
  17662. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  17663. this.points = ( points == undefined ) ? [] : points;
  17664. };
  17665. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  17666. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  17667. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  17668. var points = this.points;
  17669. var point = ( points.length - 1 ) * t;
  17670. var intPoint = Math.floor( point );
  17671. var weight = point - intPoint;
  17672. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  17673. var point1 = points[ intPoint ];
  17674. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17675. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17676. var vector = new THREE.Vector2();
  17677. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17678. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17679. return vector;
  17680. };
  17681. // File:src/extras/curves/EllipseCurve.js
  17682. /**************************************************************
  17683. * Ellipse curve
  17684. **************************************************************/
  17685. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17686. this.aX = aX;
  17687. this.aY = aY;
  17688. this.xRadius = xRadius;
  17689. this.yRadius = yRadius;
  17690. this.aStartAngle = aStartAngle;
  17691. this.aEndAngle = aEndAngle;
  17692. this.aClockwise = aClockwise;
  17693. this.aRotation = aRotation || 0;
  17694. };
  17695. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  17696. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  17697. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  17698. var deltaAngle = this.aEndAngle - this.aStartAngle;
  17699. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  17700. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  17701. var angle;
  17702. if ( this.aClockwise === true ) {
  17703. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  17704. } else {
  17705. angle = this.aStartAngle + t * deltaAngle;
  17706. }
  17707. var x = this.aX + this.xRadius * Math.cos( angle );
  17708. var y = this.aY + this.yRadius * Math.sin( angle );
  17709. if ( this.aRotation !== 0 ) {
  17710. var cos = Math.cos( this.aRotation );
  17711. var sin = Math.sin( this.aRotation );
  17712. var tx = x, ty = y;
  17713. // Rotate the point about the center of the ellipse.
  17714. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  17715. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  17716. }
  17717. return new THREE.Vector2( x, y );
  17718. };
  17719. // File:src/extras/curves/ArcCurve.js
  17720. /**************************************************************
  17721. * Arc curve
  17722. **************************************************************/
  17723. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17724. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17725. };
  17726. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  17727. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  17728. // File:src/extras/curves/LineCurve3.js
  17729. /**************************************************************
  17730. * Line3D
  17731. **************************************************************/
  17732. THREE.LineCurve3 = THREE.Curve.create(
  17733. function ( v1, v2 ) {
  17734. this.v1 = v1;
  17735. this.v2 = v2;
  17736. },
  17737. function ( t ) {
  17738. var vector = new THREE.Vector3();
  17739. vector.subVectors( this.v2, this.v1 ); // diff
  17740. vector.multiplyScalar( t );
  17741. vector.add( this.v1 );
  17742. return vector;
  17743. }
  17744. );
  17745. // File:src/extras/curves/QuadraticBezierCurve3.js
  17746. /**************************************************************
  17747. * Quadratic Bezier 3D curve
  17748. **************************************************************/
  17749. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  17750. function ( v0, v1, v2 ) {
  17751. this.v0 = v0;
  17752. this.v1 = v1;
  17753. this.v2 = v2;
  17754. },
  17755. function ( t ) {
  17756. var vector = new THREE.Vector3();
  17757. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17758. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17759. vector.z = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  17760. return vector;
  17761. }
  17762. );
  17763. // File:src/extras/curves/CubicBezierCurve3.js
  17764. /**************************************************************
  17765. * Cubic Bezier 3D curve
  17766. **************************************************************/
  17767. THREE.CubicBezierCurve3 = THREE.Curve.create(
  17768. function ( v0, v1, v2, v3 ) {
  17769. this.v0 = v0;
  17770. this.v1 = v1;
  17771. this.v2 = v2;
  17772. this.v3 = v3;
  17773. },
  17774. function ( t ) {
  17775. var vector = new THREE.Vector3();
  17776. vector.x = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17777. vector.y = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17778. vector.z = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  17779. return vector;
  17780. }
  17781. );
  17782. // File:src/extras/curves/SplineCurve3.js
  17783. /**************************************************************
  17784. * Spline 3D curve
  17785. **************************************************************/
  17786. THREE.SplineCurve3 = THREE.Curve.create(
  17787. function ( points /* array of Vector3 */ ) {
  17788. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  17789. this.points = ( points == undefined ) ? [] : points;
  17790. },
  17791. function ( t ) {
  17792. var points = this.points;
  17793. var point = ( points.length - 1 ) * t;
  17794. var intPoint = Math.floor( point );
  17795. var weight = point - intPoint;
  17796. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  17797. var point1 = points[ intPoint ];
  17798. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17799. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17800. var vector = new THREE.Vector3();
  17801. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17802. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17803. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17804. return vector;
  17805. }
  17806. );
  17807. // File:src/extras/curves/CatmullRomCurve3.js
  17808. /**
  17809. * @author zz85 https://github.com/zz85
  17810. *
  17811. * Centripetal CatmullRom Curve - which is useful for avoiding
  17812. * cusps and self-intersections in non-uniform catmull rom curves.
  17813. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  17814. *
  17815. * curve.type accepts centripetal(default), chordal and catmullrom
  17816. * curve.tension is used for catmullrom which defaults to 0.5
  17817. */
  17818. THREE.CatmullRomCurve3 = ( function() {
  17819. var
  17820. tmp = new THREE.Vector3(),
  17821. px = new CubicPoly(),
  17822. py = new CubicPoly(),
  17823. pz = new CubicPoly();
  17824. /*
  17825. Based on an optimized c++ solution in
  17826. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  17827. - http://ideone.com/NoEbVM
  17828. This CubicPoly class could be used for reusing some variables and calculations,
  17829. but for three.js curve use, it could be possible inlined and flatten into a single function call
  17830. which can be placed in CurveUtils.
  17831. */
  17832. function CubicPoly() {
  17833. }
  17834. /*
  17835. * Compute coefficients for a cubic polynomial
  17836. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  17837. * such that
  17838. * p(0) = x0, p(1) = x1
  17839. * and
  17840. * p'(0) = t0, p'(1) = t1.
  17841. */
  17842. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  17843. this.c0 = x0;
  17844. this.c1 = t0;
  17845. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  17846. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  17847. };
  17848. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  17849. // compute tangents when parameterized in [t1,t2]
  17850. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  17851. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  17852. // rescale tangents for parametrization in [0,1]
  17853. t1 *= dt1;
  17854. t2 *= dt1;
  17855. // initCubicPoly
  17856. this.init( x1, x2, t1, t2 );
  17857. };
  17858. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  17859. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  17860. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  17861. };
  17862. CubicPoly.prototype.calc = function( t ) {
  17863. var t2 = t * t;
  17864. var t3 = t2 * t;
  17865. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  17866. };
  17867. // Subclass Three.js curve
  17868. return THREE.Curve.create(
  17869. function ( p /* array of Vector3 */ ) {
  17870. this.points = p || [];
  17871. },
  17872. function ( t ) {
  17873. var points = this.points,
  17874. point, intPoint, weight, l;
  17875. l = points.length;
  17876. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  17877. point = ( l - 1 ) * t;
  17878. intPoint = Math.floor( point );
  17879. weight = point - intPoint;
  17880. if ( weight === 0 && intPoint === l - 1 ) {
  17881. intPoint = l - 2;
  17882. weight = 1;
  17883. }
  17884. var p0, p1, p2, p3;
  17885. if ( intPoint === 0 ) {
  17886. // extrapolate first point
  17887. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  17888. p0 = tmp;
  17889. } else {
  17890. p0 = points[ intPoint - 1 ];
  17891. }
  17892. p1 = points[ intPoint ];
  17893. p2 = points[ intPoint + 1 ];
  17894. if ( intPoint + 2 < l ) {
  17895. p3 = points[ intPoint + 2 ]
  17896. } else {
  17897. // extrapolate last point
  17898. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  17899. p3 = tmp;
  17900. }
  17901. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  17902. // init Centripetal / Chordal Catmull-Rom
  17903. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  17904. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  17905. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  17906. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  17907. // safety check for repeated points
  17908. if ( dt1 < 1e-4 ) dt1 = 1.0;
  17909. if ( dt0 < 1e-4 ) dt0 = dt1;
  17910. if ( dt2 < 1e-4 ) dt2 = dt1;
  17911. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  17912. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  17913. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  17914. } else if ( this.type === 'catmullrom' ) {
  17915. var tension = this.tension !== undefined ? this.tension : 0.5;
  17916. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  17917. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  17918. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  17919. }
  17920. var v = new THREE.Vector3(
  17921. px.calc( weight ),
  17922. py.calc( weight ),
  17923. pz.calc( weight )
  17924. );
  17925. return v;
  17926. }
  17927. );
  17928. } )();
  17929. // File:src/extras/curves/ClosedSplineCurve3.js
  17930. /**************************************************************
  17931. * Closed Spline 3D curve
  17932. **************************************************************/
  17933. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  17934. function ( points /* array of Vector3 */ ) {
  17935. this.points = ( points == undefined ) ? [] : points;
  17936. },
  17937. function ( t ) {
  17938. var points = this.points;
  17939. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  17940. var intPoint = Math.floor( point );
  17941. var weight = point - intPoint;
  17942. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  17943. var point0 = points[ ( intPoint - 1 ) % points.length ];
  17944. var point1 = points[ ( intPoint ) % points.length ];
  17945. var point2 = points[ ( intPoint + 1 ) % points.length ];
  17946. var point3 = points[ ( intPoint + 2 ) % points.length ];
  17947. var vector = new THREE.Vector3();
  17948. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17949. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17950. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17951. return vector;
  17952. }
  17953. );
  17954. // File:src/extras/animation/AnimationHandler.js
  17955. /**
  17956. * @author mikael emtinger / http://gomo.se/
  17957. */
  17958. THREE.AnimationHandler = {
  17959. LINEAR: 0,
  17960. CATMULLROM: 1,
  17961. CATMULLROM_FORWARD: 2,
  17962. //
  17963. add: function () {
  17964. console.warn( 'THREE.AnimationHandler.add() has been deprecated.' );
  17965. },
  17966. get: function () {
  17967. console.warn( 'THREE.AnimationHandler.get() has been deprecated.' );
  17968. },
  17969. remove: function () {
  17970. console.warn( 'THREE.AnimationHandler.remove() has been deprecated.' );
  17971. },
  17972. //
  17973. animations: [],
  17974. init: function ( data ) {
  17975. if ( data.initialized === true ) return data;
  17976. // loop through all keys
  17977. for ( var h = 0; h < data.hierarchy.length; h ++ ) {
  17978. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17979. // remove minus times
  17980. if ( data.hierarchy[ h ].keys[ k ].time < 0 ) {
  17981. data.hierarchy[ h ].keys[ k ].time = 0;
  17982. }
  17983. // create quaternions
  17984. if ( data.hierarchy[ h ].keys[ k ].rot !== undefined &&
  17985. ! ( data.hierarchy[ h ].keys[ k ].rot instanceof THREE.Quaternion ) ) {
  17986. var quat = data.hierarchy[ h ].keys[ k ].rot;
  17987. data.hierarchy[ h ].keys[ k ].rot = new THREE.Quaternion().fromArray( quat );
  17988. }
  17989. }
  17990. // prepare morph target keys
  17991. if ( data.hierarchy[ h ].keys.length && data.hierarchy[ h ].keys[ 0 ].morphTargets !== undefined ) {
  17992. // get all used
  17993. var usedMorphTargets = {};
  17994. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17995. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17996. var morphTargetName = data.hierarchy[ h ].keys[ k ].morphTargets[ m ];
  17997. usedMorphTargets[ morphTargetName ] = - 1;
  17998. }
  17999. }
  18000. data.hierarchy[ h ].usedMorphTargets = usedMorphTargets;
  18001. // set all used on all frames
  18002. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  18003. var influences = {};
  18004. for ( var morphTargetName in usedMorphTargets ) {
  18005. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  18006. if ( data.hierarchy[ h ].keys[ k ].morphTargets[ m ] === morphTargetName ) {
  18007. influences[ morphTargetName ] = data.hierarchy[ h ].keys[ k ].morphTargetsInfluences[ m ];
  18008. break;
  18009. }
  18010. }
  18011. if ( m === data.hierarchy[ h ].keys[ k ].morphTargets.length ) {
  18012. influences[ morphTargetName ] = 0;
  18013. }
  18014. }
  18015. data.hierarchy[ h ].keys[ k ].morphTargetsInfluences = influences;
  18016. }
  18017. }
  18018. // remove all keys that are on the same time
  18019. for ( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
  18020. if ( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
  18021. data.hierarchy[ h ].keys.splice( k, 1 );
  18022. k --;
  18023. }
  18024. }
  18025. // set index
  18026. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  18027. data.hierarchy[ h ].keys[ k ].index = k;
  18028. }
  18029. }
  18030. data.initialized = true;
  18031. return data;
  18032. },
  18033. parse: function ( root ) {
  18034. var parseRecurseHierarchy = function ( root, hierarchy ) {
  18035. hierarchy.push( root );
  18036. for ( var c = 0; c < root.children.length; c ++ )
  18037. parseRecurseHierarchy( root.children[ c ], hierarchy );
  18038. };
  18039. // setup hierarchy
  18040. var hierarchy = [];
  18041. if ( root instanceof THREE.SkinnedMesh ) {
  18042. for ( var b = 0; b < root.skeleton.bones.length; b ++ ) {
  18043. hierarchy.push( root.skeleton.bones[ b ] );
  18044. }
  18045. } else {
  18046. parseRecurseHierarchy( root, hierarchy );
  18047. }
  18048. return hierarchy;
  18049. },
  18050. play: function ( animation ) {
  18051. if ( this.animations.indexOf( animation ) === - 1 ) {
  18052. this.animations.push( animation );
  18053. }
  18054. },
  18055. stop: function ( animation ) {
  18056. var index = this.animations.indexOf( animation );
  18057. if ( index !== - 1 ) {
  18058. this.animations.splice( index, 1 );
  18059. }
  18060. },
  18061. update: function ( deltaTimeMS ) {
  18062. for ( var i = 0; i < this.animations.length; i ++ ) {
  18063. this.animations[ i ].resetBlendWeights( );
  18064. }
  18065. for ( var i = 0; i < this.animations.length; i ++ ) {
  18066. this.animations[ i ].update( deltaTimeMS );
  18067. }
  18068. }
  18069. };
  18070. // File:src/extras/animation/Animation.js
  18071. /**
  18072. * @author mikael emtinger / http://gomo.se/
  18073. * @author mrdoob / http://mrdoob.com/
  18074. * @author alteredq / http://alteredqualia.com/
  18075. */
  18076. THREE.Animation = function ( root, data ) {
  18077. this.root = root;
  18078. this.data = THREE.AnimationHandler.init( data );
  18079. this.hierarchy = THREE.AnimationHandler.parse( root );
  18080. this.currentTime = 0;
  18081. this.timeScale = 1;
  18082. this.isPlaying = false;
  18083. this.loop = true;
  18084. this.weight = 0;
  18085. this.interpolationType = THREE.AnimationHandler.LINEAR;
  18086. };
  18087. THREE.Animation.prototype = {
  18088. constructor: THREE.Animation,
  18089. keyTypes: [ "pos", "rot", "scl" ],
  18090. play: function ( startTime, weight ) {
  18091. this.currentTime = startTime !== undefined ? startTime : 0;
  18092. this.weight = weight !== undefined ? weight : 1;
  18093. this.isPlaying = true;
  18094. this.reset();
  18095. THREE.AnimationHandler.play( this );
  18096. },
  18097. stop: function() {
  18098. this.isPlaying = false;
  18099. THREE.AnimationHandler.stop( this );
  18100. },
  18101. reset: function () {
  18102. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18103. var object = this.hierarchy[ h ];
  18104. if ( object.animationCache === undefined ) {
  18105. object.animationCache = {
  18106. animations: {},
  18107. blending: {
  18108. positionWeight: 0.0,
  18109. quaternionWeight: 0.0,
  18110. scaleWeight: 0.0
  18111. }
  18112. };
  18113. }
  18114. var name = this.data.name;
  18115. var animations = object.animationCache.animations;
  18116. var animationCache = animations[ name ];
  18117. if ( animationCache === undefined ) {
  18118. animationCache = {
  18119. prevKey: { pos: 0, rot: 0, scl: 0 },
  18120. nextKey: { pos: 0, rot: 0, scl: 0 },
  18121. originalMatrix: object.matrix
  18122. };
  18123. animations[ name ] = animationCache;
  18124. }
  18125. // Get keys to match our current time
  18126. for ( var t = 0; t < 3; t ++ ) {
  18127. var type = this.keyTypes[ t ];
  18128. var prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  18129. var nextKey = this.getNextKeyWith( type, h, 1 );
  18130. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18131. prevKey = nextKey;
  18132. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  18133. }
  18134. animationCache.prevKey[ type ] = prevKey;
  18135. animationCache.nextKey[ type ] = nextKey;
  18136. }
  18137. }
  18138. },
  18139. resetBlendWeights: function () {
  18140. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18141. var object = this.hierarchy[ h ];
  18142. var animationCache = object.animationCache;
  18143. if ( animationCache !== undefined ) {
  18144. var blending = animationCache.blending;
  18145. blending.positionWeight = 0.0;
  18146. blending.quaternionWeight = 0.0;
  18147. blending.scaleWeight = 0.0;
  18148. }
  18149. }
  18150. },
  18151. update: ( function() {
  18152. var points = [];
  18153. var target = new THREE.Vector3();
  18154. var newVector = new THREE.Vector3();
  18155. var newQuat = new THREE.Quaternion();
  18156. // Catmull-Rom spline
  18157. var interpolateCatmullRom = function ( points, scale ) {
  18158. var c = [], v3 = [],
  18159. point, intPoint, weight, w2, w3,
  18160. pa, pb, pc, pd;
  18161. point = ( points.length - 1 ) * scale;
  18162. intPoint = Math.floor( point );
  18163. weight = point - intPoint;
  18164. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  18165. c[ 1 ] = intPoint;
  18166. c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
  18167. c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;
  18168. pa = points[ c[ 0 ] ];
  18169. pb = points[ c[ 1 ] ];
  18170. pc = points[ c[ 2 ] ];
  18171. pd = points[ c[ 3 ] ];
  18172. w2 = weight * weight;
  18173. w3 = weight * w2;
  18174. v3[ 0 ] = interpolate( pa[ 0 ], pb[ 0 ], pc[ 0 ], pd[ 0 ], weight, w2, w3 );
  18175. v3[ 1 ] = interpolate( pa[ 1 ], pb[ 1 ], pc[ 1 ], pd[ 1 ], weight, w2, w3 );
  18176. v3[ 2 ] = interpolate( pa[ 2 ], pb[ 2 ], pc[ 2 ], pd[ 2 ], weight, w2, w3 );
  18177. return v3;
  18178. };
  18179. var interpolate = function ( p0, p1, p2, p3, t, t2, t3 ) {
  18180. var v0 = ( p2 - p0 ) * 0.5,
  18181. v1 = ( p3 - p1 ) * 0.5;
  18182. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  18183. };
  18184. return function ( delta ) {
  18185. if ( this.isPlaying === false ) return;
  18186. this.currentTime += delta * this.timeScale;
  18187. if ( this.weight === 0 )
  18188. return;
  18189. //
  18190. var duration = this.data.length;
  18191. if ( this.currentTime > duration || this.currentTime < 0 ) {
  18192. if ( this.loop ) {
  18193. this.currentTime %= duration;
  18194. if ( this.currentTime < 0 )
  18195. this.currentTime += duration;
  18196. this.reset();
  18197. } else {
  18198. this.stop();
  18199. }
  18200. }
  18201. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18202. var object = this.hierarchy[ h ];
  18203. var animationCache = object.animationCache.animations[ this.data.name ];
  18204. var blending = object.animationCache.blending;
  18205. // loop through pos/rot/scl
  18206. for ( var t = 0; t < 3; t ++ ) {
  18207. // get keys
  18208. var type = this.keyTypes[ t ];
  18209. var prevKey = animationCache.prevKey[ type ];
  18210. var nextKey = animationCache.nextKey[ type ];
  18211. if ( ( this.timeScale > 0 && nextKey.time <= this.currentTime ) ||
  18212. ( this.timeScale < 0 && prevKey.time >= this.currentTime ) ) {
  18213. prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  18214. nextKey = this.getNextKeyWith( type, h, 1 );
  18215. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18216. prevKey = nextKey;
  18217. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  18218. }
  18219. animationCache.prevKey[ type ] = prevKey;
  18220. animationCache.nextKey[ type ] = nextKey;
  18221. }
  18222. var scale = ( this.currentTime - prevKey.time ) / ( nextKey.time - prevKey.time );
  18223. var prevXYZ = prevKey[ type ];
  18224. var nextXYZ = nextKey[ type ];
  18225. if ( scale < 0 ) scale = 0;
  18226. if ( scale > 1 ) scale = 1;
  18227. // interpolate
  18228. if ( type === "pos" ) {
  18229. if ( this.interpolationType === THREE.AnimationHandler.LINEAR ) {
  18230. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  18231. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  18232. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  18233. // blend
  18234. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  18235. object.position.lerp( newVector, proportionalWeight );
  18236. blending.positionWeight += this.weight;
  18237. } else if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18238. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18239. points[ 0 ] = this.getPrevKeyWith( "pos", h, prevKey.index - 1 )[ "pos" ];
  18240. points[ 1 ] = prevXYZ;
  18241. points[ 2 ] = nextXYZ;
  18242. points[ 3 ] = this.getNextKeyWith( "pos", h, nextKey.index + 1 )[ "pos" ];
  18243. scale = scale * 0.33 + 0.33;
  18244. var currentPoint = interpolateCatmullRom( points, scale );
  18245. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  18246. blending.positionWeight += this.weight;
  18247. // blend
  18248. var vector = object.position;
  18249. vector.x = vector.x + ( currentPoint[ 0 ] - vector.x ) * proportionalWeight;
  18250. vector.y = vector.y + ( currentPoint[ 1 ] - vector.y ) * proportionalWeight;
  18251. vector.z = vector.z + ( currentPoint[ 2 ] - vector.z ) * proportionalWeight;
  18252. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18253. var forwardPoint = interpolateCatmullRom( points, scale * 1.01 );
  18254. target.set( forwardPoint[ 0 ], forwardPoint[ 1 ], forwardPoint[ 2 ] );
  18255. target.sub( vector );
  18256. target.y = 0;
  18257. target.normalize();
  18258. var angle = Math.atan2( target.x, target.z );
  18259. object.rotation.set( 0, angle, 0 );
  18260. }
  18261. }
  18262. } else if ( type === "rot" ) {
  18263. THREE.Quaternion.slerp( prevXYZ, nextXYZ, newQuat, scale );
  18264. // Avoid paying the cost of an additional slerp if we don't have to
  18265. if ( blending.quaternionWeight === 0 ) {
  18266. object.quaternion.copy( newQuat );
  18267. blending.quaternionWeight = this.weight;
  18268. } else {
  18269. var proportionalWeight = this.weight / ( this.weight + blending.quaternionWeight );
  18270. THREE.Quaternion.slerp( object.quaternion, newQuat, object.quaternion, proportionalWeight );
  18271. blending.quaternionWeight += this.weight;
  18272. }
  18273. } else if ( type === "scl" ) {
  18274. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  18275. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  18276. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  18277. var proportionalWeight = this.weight / ( this.weight + blending.scaleWeight );
  18278. object.scale.lerp( newVector, proportionalWeight );
  18279. blending.scaleWeight += this.weight;
  18280. }
  18281. }
  18282. }
  18283. return true;
  18284. };
  18285. } )(),
  18286. getNextKeyWith: function ( type, h, key ) {
  18287. var keys = this.data.hierarchy[ h ].keys;
  18288. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18289. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18290. key = key < keys.length - 1 ? key : keys.length - 1;
  18291. } else {
  18292. key = key % keys.length;
  18293. }
  18294. for ( ; key < keys.length; key ++ ) {
  18295. if ( keys[ key ][ type ] !== undefined ) {
  18296. return keys[ key ];
  18297. }
  18298. }
  18299. return this.data.hierarchy[ h ].keys[ 0 ];
  18300. },
  18301. getPrevKeyWith: function ( type, h, key ) {
  18302. var keys = this.data.hierarchy[ h ].keys;
  18303. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18304. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18305. key = key > 0 ? key : 0;
  18306. } else {
  18307. key = key >= 0 ? key : key + keys.length;
  18308. }
  18309. for ( ; key >= 0; key -- ) {
  18310. if ( keys[ key ][ type ] !== undefined ) {
  18311. return keys[ key ];
  18312. }
  18313. }
  18314. return this.data.hierarchy[ h ].keys[ keys.length - 1 ];
  18315. }
  18316. };
  18317. // File:src/extras/animation/KeyFrameAnimation.js
  18318. /**
  18319. * @author mikael emtinger / http://gomo.se/
  18320. * @author mrdoob / http://mrdoob.com/
  18321. * @author alteredq / http://alteredqualia.com/
  18322. * @author khang duong
  18323. * @author erik kitson
  18324. */
  18325. THREE.KeyFrameAnimation = function ( data ) {
  18326. this.root = data.node;
  18327. this.data = THREE.AnimationHandler.init( data );
  18328. this.hierarchy = THREE.AnimationHandler.parse( this.root );
  18329. this.currentTime = 0;
  18330. this.timeScale = 0.001;
  18331. this.isPlaying = false;
  18332. this.isPaused = true;
  18333. this.loop = true;
  18334. // initialize to first keyframes
  18335. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18336. var keys = this.data.hierarchy[ h ].keys,
  18337. sids = this.data.hierarchy[ h ].sids,
  18338. obj = this.hierarchy[ h ];
  18339. if ( keys.length && sids ) {
  18340. for ( var s = 0; s < sids.length; s ++ ) {
  18341. var sid = sids[ s ],
  18342. next = this.getNextKeyWith( sid, h, 0 );
  18343. if ( next ) {
  18344. next.apply( sid );
  18345. }
  18346. }
  18347. obj.matrixAutoUpdate = false;
  18348. this.data.hierarchy[ h ].node.updateMatrix();
  18349. obj.matrixWorldNeedsUpdate = true;
  18350. }
  18351. }
  18352. };
  18353. THREE.KeyFrameAnimation.prototype = {
  18354. constructor: THREE.KeyFrameAnimation,
  18355. play: function ( startTime ) {
  18356. this.currentTime = startTime !== undefined ? startTime : 0;
  18357. if ( this.isPlaying === false ) {
  18358. this.isPlaying = true;
  18359. // reset key cache
  18360. var h, hl = this.hierarchy.length,
  18361. object,
  18362. node;
  18363. for ( h = 0; h < hl; h ++ ) {
  18364. object = this.hierarchy[ h ];
  18365. node = this.data.hierarchy[ h ];
  18366. if ( node.animationCache === undefined ) {
  18367. node.animationCache = {};
  18368. node.animationCache.prevKey = null;
  18369. node.animationCache.nextKey = null;
  18370. node.animationCache.originalMatrix = object.matrix;
  18371. }
  18372. var keys = this.data.hierarchy[ h ].keys;
  18373. if ( keys.length ) {
  18374. node.animationCache.prevKey = keys[ 0 ];
  18375. node.animationCache.nextKey = keys[ 1 ];
  18376. this.startTime = Math.min( keys[ 0 ].time, this.startTime );
  18377. this.endTime = Math.max( keys[ keys.length - 1 ].time, this.endTime );
  18378. }
  18379. }
  18380. this.update( 0 );
  18381. }
  18382. this.isPaused = false;
  18383. THREE.AnimationHandler.play( this );
  18384. },
  18385. stop: function () {
  18386. this.isPlaying = false;
  18387. this.isPaused = false;
  18388. THREE.AnimationHandler.stop( this );
  18389. // reset JIT matrix and remove cache
  18390. for ( var h = 0; h < this.data.hierarchy.length; h ++ ) {
  18391. var obj = this.hierarchy[ h ];
  18392. var node = this.data.hierarchy[ h ];
  18393. if ( node.animationCache !== undefined ) {
  18394. var original = node.animationCache.originalMatrix;
  18395. original.copy( obj.matrix );
  18396. obj.matrix = original;
  18397. delete node.animationCache;
  18398. }
  18399. }
  18400. },
  18401. update: function ( delta ) {
  18402. if ( this.isPlaying === false ) return;
  18403. this.currentTime += delta * this.timeScale;
  18404. //
  18405. var duration = this.data.length;
  18406. if ( this.loop === true && this.currentTime > duration ) {
  18407. this.currentTime %= duration;
  18408. }
  18409. this.currentTime = Math.min( this.currentTime, duration );
  18410. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18411. var object = this.hierarchy[ h ];
  18412. var node = this.data.hierarchy[ h ];
  18413. var keys = node.keys,
  18414. animationCache = node.animationCache;
  18415. if ( keys.length ) {
  18416. var prevKey = animationCache.prevKey;
  18417. var nextKey = animationCache.nextKey;
  18418. if ( nextKey.time <= this.currentTime ) {
  18419. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18420. prevKey = nextKey;
  18421. nextKey = keys[ prevKey.index + 1 ];
  18422. }
  18423. animationCache.prevKey = prevKey;
  18424. animationCache.nextKey = nextKey;
  18425. }
  18426. if ( nextKey.time >= this.currentTime ) {
  18427. prevKey.interpolate( nextKey, this.currentTime );
  18428. } else {
  18429. prevKey.interpolate( nextKey, nextKey.time );
  18430. }
  18431. this.data.hierarchy[ h ].node.updateMatrix();
  18432. object.matrixWorldNeedsUpdate = true;
  18433. }
  18434. }
  18435. },
  18436. getNextKeyWith: function ( sid, h, key ) {
  18437. var keys = this.data.hierarchy[ h ].keys;
  18438. key = key % keys.length;
  18439. for ( ; key < keys.length; key ++ ) {
  18440. if ( keys[ key ].hasTarget( sid ) ) {
  18441. return keys[ key ];
  18442. }
  18443. }
  18444. return keys[ 0 ];
  18445. },
  18446. getPrevKeyWith: function ( sid, h, key ) {
  18447. var keys = this.data.hierarchy[ h ].keys;
  18448. key = key >= 0 ? key : key + keys.length;
  18449. for ( ; key >= 0; key -- ) {
  18450. if ( keys[ key ].hasTarget( sid ) ) {
  18451. return keys[ key ];
  18452. }
  18453. }
  18454. return keys[ keys.length - 1 ];
  18455. }
  18456. };
  18457. // File:src/extras/animation/MorphAnimation.js
  18458. /**
  18459. * @author mrdoob / http://mrdoob.com
  18460. * @author willy-vvu / http://willy-vvu.github.io
  18461. */
  18462. THREE.MorphAnimation = function ( mesh ) {
  18463. this.mesh = mesh;
  18464. this.frames = mesh.morphTargetInfluences.length;
  18465. this.currentTime = 0;
  18466. this.duration = 1000;
  18467. this.loop = true;
  18468. this.lastFrame = 0;
  18469. this.currentFrame = 0;
  18470. this.isPlaying = false;
  18471. };
  18472. THREE.MorphAnimation.prototype = {
  18473. constructor: THREE.MorphAnimation,
  18474. play: function () {
  18475. this.isPlaying = true;
  18476. },
  18477. pause: function () {
  18478. this.isPlaying = false;
  18479. },
  18480. update: function ( delta ) {
  18481. if ( this.isPlaying === false ) return;
  18482. this.currentTime += delta;
  18483. if ( this.loop === true && this.currentTime > this.duration ) {
  18484. this.currentTime %= this.duration;
  18485. }
  18486. this.currentTime = Math.min( this.currentTime, this.duration );
  18487. var frameTime = this.duration / this.frames;
  18488. var frame = Math.floor( this.currentTime / frameTime );
  18489. var influences = this.mesh.morphTargetInfluences;
  18490. if ( frame !== this.currentFrame ) {
  18491. influences[ this.lastFrame ] = 0;
  18492. influences[ this.currentFrame ] = 1;
  18493. influences[ frame ] = 0;
  18494. this.lastFrame = this.currentFrame;
  18495. this.currentFrame = frame;
  18496. }
  18497. var mix = ( this.currentTime % frameTime ) / frameTime;
  18498. influences[ frame ] = mix;
  18499. influences[ this.lastFrame ] = 1 - mix;
  18500. }
  18501. };
  18502. // File:src/extras/geometries/BoxGeometry.js
  18503. /**
  18504. * @author mrdoob / http://mrdoob.com/
  18505. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  18506. */
  18507. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  18508. THREE.Geometry.call( this );
  18509. this.type = 'BoxGeometry';
  18510. this.parameters = {
  18511. width: width,
  18512. height: height,
  18513. depth: depth,
  18514. widthSegments: widthSegments,
  18515. heightSegments: heightSegments,
  18516. depthSegments: depthSegments
  18517. };
  18518. this.widthSegments = widthSegments || 1;
  18519. this.heightSegments = heightSegments || 1;
  18520. this.depthSegments = depthSegments || 1;
  18521. var scope = this;
  18522. var width_half = width / 2;
  18523. var height_half = height / 2;
  18524. var depth_half = depth / 2;
  18525. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  18526. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  18527. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  18528. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  18529. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  18530. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  18531. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  18532. var w, ix, iy,
  18533. gridX = scope.widthSegments,
  18534. gridY = scope.heightSegments,
  18535. width_half = width / 2,
  18536. height_half = height / 2,
  18537. offset = scope.vertices.length;
  18538. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  18539. w = 'z';
  18540. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  18541. w = 'y';
  18542. gridY = scope.depthSegments;
  18543. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  18544. w = 'x';
  18545. gridX = scope.depthSegments;
  18546. }
  18547. var gridX1 = gridX + 1,
  18548. gridY1 = gridY + 1,
  18549. segment_width = width / gridX,
  18550. segment_height = height / gridY,
  18551. normal = new THREE.Vector3();
  18552. normal[ w ] = depth > 0 ? 1 : - 1;
  18553. for ( iy = 0; iy < gridY1; iy ++ ) {
  18554. for ( ix = 0; ix < gridX1; ix ++ ) {
  18555. var vector = new THREE.Vector3();
  18556. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  18557. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  18558. vector[ w ] = depth;
  18559. scope.vertices.push( vector );
  18560. }
  18561. }
  18562. for ( iy = 0; iy < gridY; iy ++ ) {
  18563. for ( ix = 0; ix < gridX; ix ++ ) {
  18564. var a = ix + gridX1 * iy;
  18565. var b = ix + gridX1 * ( iy + 1 );
  18566. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  18567. var d = ( ix + 1 ) + gridX1 * iy;
  18568. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  18569. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  18570. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  18571. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  18572. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  18573. face.normal.copy( normal );
  18574. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18575. face.materialIndex = materialIndex;
  18576. scope.faces.push( face );
  18577. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  18578. face = new THREE.Face3( b + offset, c + offset, d + offset );
  18579. face.normal.copy( normal );
  18580. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18581. face.materialIndex = materialIndex;
  18582. scope.faces.push( face );
  18583. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  18584. }
  18585. }
  18586. }
  18587. this.mergeVertices();
  18588. };
  18589. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18590. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  18591. THREE.BoxGeometry.prototype.clone = function () {
  18592. var geometry = new THREE.BoxGeometry(
  18593. this.parameters.width,
  18594. this.parameters.height,
  18595. this.parameters.depth,
  18596. this.parameters.widthSegments,
  18597. this.parameters.heightSegments,
  18598. this.parameters.depthSegments
  18599. );
  18600. return geometry;
  18601. };
  18602. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  18603. // File:src/extras/geometries/CircleGeometry.js
  18604. /**
  18605. * @author hughes
  18606. */
  18607. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18608. THREE.Geometry.call( this );
  18609. this.type = 'CircleGeometry';
  18610. this.parameters = {
  18611. radius: radius,
  18612. segments: segments,
  18613. thetaStart: thetaStart,
  18614. thetaLength: thetaLength
  18615. };
  18616. radius = radius || 50;
  18617. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18618. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18619. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18620. var i, uvs = [],
  18621. center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
  18622. this.vertices.push( center );
  18623. uvs.push( centerUV );
  18624. for ( i = 0; i <= segments; i ++ ) {
  18625. var vertex = new THREE.Vector3();
  18626. var segment = thetaStart + i / segments * thetaLength;
  18627. vertex.x = radius * Math.cos( segment );
  18628. vertex.y = radius * Math.sin( segment );
  18629. this.vertices.push( vertex );
  18630. uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, ( vertex.y / radius + 1 ) / 2 ) );
  18631. }
  18632. var n = new THREE.Vector3( 0, 0, 1 );
  18633. for ( i = 1; i <= segments; i ++ ) {
  18634. this.faces.push( new THREE.Face3( i, i + 1, 0, [ n.clone(), n.clone(), n.clone() ] ) );
  18635. this.faceVertexUvs[ 0 ].push( [ uvs[ i ].clone(), uvs[ i + 1 ].clone(), centerUV.clone() ] );
  18636. }
  18637. this.computeFaceNormals();
  18638. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18639. };
  18640. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18641. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  18642. THREE.CircleGeometry.prototype.clone = function () {
  18643. var geometry = new THREE.CircleGeometry(
  18644. this.parameters.radius,
  18645. this.parameters.segments,
  18646. this.parameters.thetaStart,
  18647. this.parameters.thetaLength
  18648. );
  18649. return geometry;
  18650. };
  18651. // File:src/extras/geometries/CircleBufferGeometry.js
  18652. /**
  18653. * @author benaadams / https://twitter.com/ben_a_adams
  18654. */
  18655. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18656. THREE.BufferGeometry.call( this );
  18657. this.type = 'CircleBufferGeometry';
  18658. this.parameters = {
  18659. radius: radius,
  18660. segments: segments,
  18661. thetaStart: thetaStart,
  18662. thetaLength: thetaLength
  18663. };
  18664. radius = radius || 50;
  18665. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18666. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18667. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18668. var vertices = segments + 2;
  18669. var positions = new Float32Array( vertices * 3 );
  18670. var normals = new Float32Array( vertices * 3 );
  18671. var uvs = new Float32Array( vertices * 2 );
  18672. // center data is already zero, but need to set a few extras
  18673. normals[ 3 ] = 1.0;
  18674. uvs[ 0 ] = 0.5;
  18675. uvs[ 1 ] = 0.5;
  18676. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  18677. var segment = thetaStart + s / segments * thetaLength;
  18678. positions[ i ] = radius * Math.cos( segment );
  18679. positions[ i + 1 ] = radius * Math.sin( segment );
  18680. normals[ i + 2 ] = 1; // normal z
  18681. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  18682. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  18683. }
  18684. var indices = [];
  18685. for ( var i = 1; i <= segments; i ++ ) {
  18686. indices.push( i );
  18687. indices.push( i + 1 );
  18688. indices.push( 0 );
  18689. }
  18690. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  18691. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  18692. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  18693. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  18694. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18695. };
  18696. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18697. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  18698. THREE.CircleBufferGeometry.prototype.clone = function () {
  18699. var geometry = new THREE.CircleBufferGeometry(
  18700. this.parameters.radius,
  18701. this.parameters.segments,
  18702. this.parameters.thetaStart,
  18703. this.parameters.thetaLength
  18704. );
  18705. geometry.copy( this );
  18706. return geometry;
  18707. };
  18708. // File:src/extras/geometries/CylinderGeometry.js
  18709. /**
  18710. * @author mrdoob / http://mrdoob.com/
  18711. */
  18712. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18713. THREE.Geometry.call( this );
  18714. this.type = 'CylinderGeometry';
  18715. this.parameters = {
  18716. radiusTop: radiusTop,
  18717. radiusBottom: radiusBottom,
  18718. height: height,
  18719. radialSegments: radialSegments,
  18720. heightSegments: heightSegments,
  18721. openEnded: openEnded,
  18722. thetaStart: thetaStart,
  18723. thetaLength: thetaLength
  18724. };
  18725. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  18726. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  18727. height = height !== undefined ? height : 100;
  18728. radialSegments = radialSegments || 8;
  18729. heightSegments = heightSegments || 1;
  18730. openEnded = openEnded !== undefined ? openEnded : false;
  18731. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18732. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  18733. var heightHalf = height / 2;
  18734. var x, y, vertices = [], uvs = [];
  18735. for ( y = 0; y <= heightSegments; y ++ ) {
  18736. var verticesRow = [];
  18737. var uvsRow = [];
  18738. var v = y / heightSegments;
  18739. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18740. for ( x = 0; x <= radialSegments; x ++ ) {
  18741. var u = x / radialSegments;
  18742. var vertex = new THREE.Vector3();
  18743. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  18744. vertex.y = - v * height + heightHalf;
  18745. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  18746. this.vertices.push( vertex );
  18747. verticesRow.push( this.vertices.length - 1 );
  18748. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  18749. }
  18750. vertices.push( verticesRow );
  18751. uvs.push( uvsRow );
  18752. }
  18753. var tanTheta = ( radiusBottom - radiusTop ) / height;
  18754. var na, nb;
  18755. for ( x = 0; x < radialSegments; x ++ ) {
  18756. if ( radiusTop !== 0 ) {
  18757. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  18758. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  18759. } else {
  18760. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  18761. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  18762. }
  18763. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  18764. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  18765. for ( y = 0; y < heightSegments; y ++ ) {
  18766. var v1 = vertices[ y ][ x ];
  18767. var v2 = vertices[ y + 1 ][ x ];
  18768. var v3 = vertices[ y + 1 ][ x + 1 ];
  18769. var v4 = vertices[ y ][ x + 1 ];
  18770. var n1 = na.clone();
  18771. var n2 = na.clone();
  18772. var n3 = nb.clone();
  18773. var n4 = nb.clone();
  18774. var uv1 = uvs[ y ][ x ].clone();
  18775. var uv2 = uvs[ y + 1 ][ x ].clone();
  18776. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  18777. var uv4 = uvs[ y ][ x + 1 ].clone();
  18778. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  18779. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  18780. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  18781. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  18782. }
  18783. }
  18784. // top cap
  18785. if ( openEnded === false && radiusTop > 0 ) {
  18786. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  18787. for ( x = 0; x < radialSegments; x ++ ) {
  18788. var v1 = vertices[ 0 ][ x ];
  18789. var v2 = vertices[ 0 ][ x + 1 ];
  18790. var v3 = this.vertices.length - 1;
  18791. var n1 = new THREE.Vector3( 0, 1, 0 );
  18792. var n2 = new THREE.Vector3( 0, 1, 0 );
  18793. var n3 = new THREE.Vector3( 0, 1, 0 );
  18794. var uv1 = uvs[ 0 ][ x ].clone();
  18795. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  18796. var uv3 = new THREE.Vector2( uv2.x, 0 );
  18797. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18798. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18799. }
  18800. }
  18801. // bottom cap
  18802. if ( openEnded === false && radiusBottom > 0 ) {
  18803. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  18804. for ( x = 0; x < radialSegments; x ++ ) {
  18805. var v1 = vertices[ heightSegments ][ x + 1 ];
  18806. var v2 = vertices[ heightSegments ][ x ];
  18807. var v3 = this.vertices.length - 1;
  18808. var n1 = new THREE.Vector3( 0, - 1, 0 );
  18809. var n2 = new THREE.Vector3( 0, - 1, 0 );
  18810. var n3 = new THREE.Vector3( 0, - 1, 0 );
  18811. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  18812. var uv2 = uvs[ heightSegments ][ x ].clone();
  18813. var uv3 = new THREE.Vector2( uv2.x, 1 );
  18814. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18815. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18816. }
  18817. }
  18818. this.computeFaceNormals();
  18819. };
  18820. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18821. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  18822. THREE.CylinderGeometry.prototype.clone = function () {
  18823. var geometry = new THREE.CylinderGeometry(
  18824. this.parameters.radiusTop,
  18825. this.parameters.radiusBottom,
  18826. this.parameters.height,
  18827. this.parameters.radialSegments,
  18828. this.parameters.heightSegments,
  18829. this.parameters.openEnded,
  18830. this.parameters.thetaStart,
  18831. this.parameters.thetaLength
  18832. );
  18833. return geometry;
  18834. };
  18835. // File:src/extras/geometries/EdgesGeometry.js
  18836. /**
  18837. * @author WestLangley / http://github.com/WestLangley
  18838. */
  18839. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  18840. THREE.BufferGeometry.call( this );
  18841. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18842. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  18843. var edge = [ 0, 0 ], hash = {};
  18844. var sortFunction = function ( a, b ) {
  18845. return a - b;
  18846. };
  18847. var keys = [ 'a', 'b', 'c' ];
  18848. var geometry2;
  18849. if ( geometry instanceof THREE.BufferGeometry ) {
  18850. geometry2 = new THREE.Geometry();
  18851. geometry2.fromBufferGeometry( geometry );
  18852. } else {
  18853. geometry2 = geometry.clone();
  18854. }
  18855. geometry2.mergeVertices();
  18856. geometry2.computeFaceNormals();
  18857. var vertices = geometry2.vertices;
  18858. var faces = geometry2.faces;
  18859. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18860. var face = faces[ i ];
  18861. for ( var j = 0; j < 3; j ++ ) {
  18862. edge[ 0 ] = face[ keys[ j ] ];
  18863. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  18864. edge.sort( sortFunction );
  18865. var key = edge.toString();
  18866. if ( hash[ key ] === undefined ) {
  18867. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  18868. } else {
  18869. hash[ key ].face2 = i;
  18870. }
  18871. }
  18872. }
  18873. var coords = [];
  18874. for ( var key in hash ) {
  18875. var h = hash[ key ];
  18876. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  18877. var vertex = vertices[ h.vert1 ];
  18878. coords.push( vertex.x );
  18879. coords.push( vertex.y );
  18880. coords.push( vertex.z );
  18881. vertex = vertices[ h.vert2 ];
  18882. coords.push( vertex.x );
  18883. coords.push( vertex.y );
  18884. coords.push( vertex.z );
  18885. }
  18886. }
  18887. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  18888. };
  18889. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18890. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  18891. // File:src/extras/geometries/ExtrudeGeometry.js
  18892. /**
  18893. * @author zz85 / http://www.lab4games.net/zz85/blog
  18894. *
  18895. * Creates extruded geometry from a path shape.
  18896. *
  18897. * parameters = {
  18898. *
  18899. * curveSegments: <int>, // number of points on the curves
  18900. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18901. * amount: <int>, // Depth to extrude the shape
  18902. *
  18903. * bevelEnabled: <bool>, // turn on bevel
  18904. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18905. * bevelSize: <float>, // how far from shape outline is bevel
  18906. * bevelSegments: <int>, // number of bevel layers
  18907. *
  18908. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  18909. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  18910. *
  18911. * uvGenerator: <Object> // object that provides UV generator functions
  18912. *
  18913. * }
  18914. **/
  18915. THREE.ExtrudeGeometry = function ( shapes, options ) {
  18916. if ( typeof( shapes ) === "undefined" ) {
  18917. shapes = [];
  18918. return;
  18919. }
  18920. THREE.Geometry.call( this );
  18921. this.type = 'ExtrudeGeometry';
  18922. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18923. this.addShapeList( shapes, options );
  18924. this.computeFaceNormals();
  18925. // can't really use automatic vertex normals
  18926. // as then front and back sides get smoothed too
  18927. // should do separate smoothing just for sides
  18928. //this.computeVertexNormals();
  18929. //console.log( "took", ( Date.now() - startTime ) );
  18930. };
  18931. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18932. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  18933. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  18934. var sl = shapes.length;
  18935. for ( var s = 0; s < sl; s ++ ) {
  18936. var shape = shapes[ s ];
  18937. this.addShape( shape, options );
  18938. }
  18939. };
  18940. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  18941. var amount = options.amount !== undefined ? options.amount : 100;
  18942. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  18943. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  18944. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18945. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  18946. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18947. var steps = options.steps !== undefined ? options.steps : 1;
  18948. var extrudePath = options.extrudePath;
  18949. var extrudePts, extrudeByPath = false;
  18950. // Use default WorldUVGenerator if no UV generators are specified.
  18951. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  18952. var splineTube, binormal, normal, position2;
  18953. if ( extrudePath ) {
  18954. extrudePts = extrudePath.getSpacedPoints( steps );
  18955. extrudeByPath = true;
  18956. bevelEnabled = false; // bevels not supported for path extrusion
  18957. // SETUP TNB variables
  18958. // Reuse TNB from TubeGeomtry for now.
  18959. // TODO1 - have a .isClosed in spline?
  18960. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  18961. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18962. binormal = new THREE.Vector3();
  18963. normal = new THREE.Vector3();
  18964. position2 = new THREE.Vector3();
  18965. }
  18966. // Safeguards if bevels are not enabled
  18967. if ( ! bevelEnabled ) {
  18968. bevelSegments = 0;
  18969. bevelThickness = 0;
  18970. bevelSize = 0;
  18971. }
  18972. // Variables initialization
  18973. var ahole, h, hl; // looping of holes
  18974. var scope = this;
  18975. var shapesOffset = this.vertices.length;
  18976. var shapePoints = shape.extractPoints( curveSegments );
  18977. var vertices = shapePoints.shape;
  18978. var holes = shapePoints.holes;
  18979. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  18980. if ( reverse ) {
  18981. vertices = vertices.reverse();
  18982. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18983. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18984. ahole = holes[ h ];
  18985. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  18986. holes[ h ] = ahole.reverse();
  18987. }
  18988. }
  18989. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  18990. }
  18991. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  18992. /* Vertices */
  18993. var contour = vertices; // vertices has all points but contour has only points of circumference
  18994. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18995. ahole = holes[ h ];
  18996. vertices = vertices.concat( ahole );
  18997. }
  18998. function scalePt2 ( pt, vec, size ) {
  18999. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  19000. return vec.clone().multiplyScalar( size ).add( pt );
  19001. }
  19002. var b, bs, t, z,
  19003. vert, vlen = vertices.length,
  19004. face, flen = faces.length;
  19005. // Find directions for point movement
  19006. function getBevelVec( inPt, inPrev, inNext ) {
  19007. var EPSILON = 0.0000000001;
  19008. // computes for inPt the corresponding point inPt' on a new contour
  19009. // shifted by 1 unit (length of normalized vector) to the left
  19010. // if we walk along contour clockwise, this new contour is outside the old one
  19011. //
  19012. // inPt' is the intersection of the two lines parallel to the two
  19013. // adjacent edges of inPt at a distance of 1 unit on the left side.
  19014. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  19015. // good reading for geometry algorithms (here: line-line intersection)
  19016. // http://geomalgorithms.com/a05-_intersect-1.html
  19017. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  19018. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  19019. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  19020. // check for collinear edges
  19021. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19022. if ( Math.abs( collinear0 ) > EPSILON ) {
  19023. // not collinear
  19024. // length of vectors for normalizing
  19025. var v_prev_len = Math.sqrt( v_prev_lensq );
  19026. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  19027. // shift adjacent points by unit vectors to the left
  19028. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  19029. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  19030. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  19031. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  19032. // scaling factor for v_prev to intersection point
  19033. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  19034. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  19035. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19036. // vector from inPt to intersection point
  19037. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  19038. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  19039. // Don't normalize!, otherwise sharp corners become ugly
  19040. // but prevent crazy spikes
  19041. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  19042. if ( v_trans_lensq <= 2 ) {
  19043. return new THREE.Vector2( v_trans_x, v_trans_y );
  19044. } else {
  19045. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  19046. }
  19047. } else {
  19048. // handle special case of collinear edges
  19049. var direction_eq = false; // assumes: opposite
  19050. if ( v_prev_x > EPSILON ) {
  19051. if ( v_next_x > EPSILON ) {
  19052. direction_eq = true;
  19053. }
  19054. } else {
  19055. if ( v_prev_x < - EPSILON ) {
  19056. if ( v_next_x < - EPSILON ) {
  19057. direction_eq = true;
  19058. }
  19059. } else {
  19060. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  19061. direction_eq = true;
  19062. }
  19063. }
  19064. }
  19065. if ( direction_eq ) {
  19066. // console.log("Warning: lines are a straight sequence");
  19067. v_trans_x = - v_prev_y;
  19068. v_trans_y = v_prev_x;
  19069. shrink_by = Math.sqrt( v_prev_lensq );
  19070. } else {
  19071. // console.log("Warning: lines are a straight spike");
  19072. v_trans_x = v_prev_x;
  19073. v_trans_y = v_prev_y;
  19074. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  19075. }
  19076. }
  19077. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  19078. }
  19079. var contourMovements = [];
  19080. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19081. if ( j === il ) j = 0;
  19082. if ( k === il ) k = 0;
  19083. // (j)---(i)---(k)
  19084. // console.log('i,j,k', i, j , k)
  19085. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  19086. }
  19087. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  19088. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19089. ahole = holes[ h ];
  19090. oneHoleMovements = [];
  19091. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19092. if ( j === il ) j = 0;
  19093. if ( k === il ) k = 0;
  19094. // (j)---(i)---(k)
  19095. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  19096. }
  19097. holesMovements.push( oneHoleMovements );
  19098. verticesMovements = verticesMovements.concat( oneHoleMovements );
  19099. }
  19100. // Loop bevelSegments, 1 for the front, 1 for the back
  19101. for ( b = 0; b < bevelSegments; b ++ ) {
  19102. //for ( b = bevelSegments; b > 0; b -- ) {
  19103. t = b / bevelSegments;
  19104. z = bevelThickness * ( 1 - t );
  19105. //z = bevelThickness * t;
  19106. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  19107. //bs = bevelSize * t; // linear
  19108. // contract shape
  19109. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19110. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19111. v( vert.x, vert.y, - z );
  19112. }
  19113. // expand holes
  19114. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19115. ahole = holes[ h ];
  19116. oneHoleMovements = holesMovements[ h ];
  19117. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19118. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19119. v( vert.x, vert.y, - z );
  19120. }
  19121. }
  19122. }
  19123. bs = bevelSize;
  19124. // Back facing vertices
  19125. for ( i = 0; i < vlen; i ++ ) {
  19126. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19127. if ( ! extrudeByPath ) {
  19128. v( vert.x, vert.y, 0 );
  19129. } else {
  19130. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  19131. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  19132. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  19133. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  19134. v( position2.x, position2.y, position2.z );
  19135. }
  19136. }
  19137. // Add stepped vertices...
  19138. // Including front facing vertices
  19139. var s;
  19140. for ( s = 1; s <= steps; s ++ ) {
  19141. for ( i = 0; i < vlen; i ++ ) {
  19142. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19143. if ( ! extrudeByPath ) {
  19144. v( vert.x, vert.y, amount / steps * s );
  19145. } else {
  19146. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  19147. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  19148. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  19149. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  19150. v( position2.x, position2.y, position2.z );
  19151. }
  19152. }
  19153. }
  19154. // Add bevel segments planes
  19155. //for ( b = 1; b <= bevelSegments; b ++ ) {
  19156. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  19157. t = b / bevelSegments;
  19158. z = bevelThickness * ( 1 - t );
  19159. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  19160. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  19161. // contract shape
  19162. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19163. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19164. v( vert.x, vert.y, amount + z );
  19165. }
  19166. // expand holes
  19167. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19168. ahole = holes[ h ];
  19169. oneHoleMovements = holesMovements[ h ];
  19170. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19171. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19172. if ( ! extrudeByPath ) {
  19173. v( vert.x, vert.y, amount + z );
  19174. } else {
  19175. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  19176. }
  19177. }
  19178. }
  19179. }
  19180. /* Faces */
  19181. // Top and bottom faces
  19182. buildLidFaces();
  19183. // Sides faces
  19184. buildSideFaces();
  19185. ///// Internal functions
  19186. function buildLidFaces() {
  19187. if ( bevelEnabled ) {
  19188. var layer = 0; // steps + 1
  19189. var offset = vlen * layer;
  19190. // Bottom faces
  19191. for ( i = 0; i < flen; i ++ ) {
  19192. face = faces[ i ];
  19193. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  19194. }
  19195. layer = steps + bevelSegments * 2;
  19196. offset = vlen * layer;
  19197. // Top faces
  19198. for ( i = 0; i < flen; i ++ ) {
  19199. face = faces[ i ];
  19200. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  19201. }
  19202. } else {
  19203. // Bottom faces
  19204. for ( i = 0; i < flen; i ++ ) {
  19205. face = faces[ i ];
  19206. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  19207. }
  19208. // Top faces
  19209. for ( i = 0; i < flen; i ++ ) {
  19210. face = faces[ i ];
  19211. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  19212. }
  19213. }
  19214. }
  19215. // Create faces for the z-sides of the shape
  19216. function buildSideFaces() {
  19217. var layeroffset = 0;
  19218. sidewalls( contour, layeroffset );
  19219. layeroffset += contour.length;
  19220. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19221. ahole = holes[ h ];
  19222. sidewalls( ahole, layeroffset );
  19223. //, true
  19224. layeroffset += ahole.length;
  19225. }
  19226. }
  19227. function sidewalls( contour, layeroffset ) {
  19228. var j, k;
  19229. i = contour.length;
  19230. while ( -- i >= 0 ) {
  19231. j = i;
  19232. k = i - 1;
  19233. if ( k < 0 ) k = contour.length - 1;
  19234. //console.log('b', i,j, i-1, k,vertices.length);
  19235. var s = 0, sl = steps + bevelSegments * 2;
  19236. for ( s = 0; s < sl; s ++ ) {
  19237. var slen1 = vlen * s;
  19238. var slen2 = vlen * ( s + 1 );
  19239. var a = layeroffset + j + slen1,
  19240. b = layeroffset + k + slen1,
  19241. c = layeroffset + k + slen2,
  19242. d = layeroffset + j + slen2;
  19243. f4( a, b, c, d, contour, s, sl, j, k );
  19244. }
  19245. }
  19246. }
  19247. function v( x, y, z ) {
  19248. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  19249. }
  19250. function f3( a, b, c ) {
  19251. a += shapesOffset;
  19252. b += shapesOffset;
  19253. c += shapesOffset;
  19254. scope.faces.push( new THREE.Face3( a, b, c ) );
  19255. var uvs = uvgen.generateTopUV( scope, a, b, c );
  19256. scope.faceVertexUvs[ 0 ].push( uvs );
  19257. }
  19258. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  19259. a += shapesOffset;
  19260. b += shapesOffset;
  19261. c += shapesOffset;
  19262. d += shapesOffset;
  19263. scope.faces.push( new THREE.Face3( a, b, d ) );
  19264. scope.faces.push( new THREE.Face3( b, c, d ) );
  19265. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  19266. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  19267. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  19268. }
  19269. };
  19270. THREE.ExtrudeGeometry.WorldUVGenerator = {
  19271. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  19272. var vertices = geometry.vertices;
  19273. var a = vertices[ indexA ];
  19274. var b = vertices[ indexB ];
  19275. var c = vertices[ indexC ];
  19276. return [
  19277. new THREE.Vector2( a.x, a.y ),
  19278. new THREE.Vector2( b.x, b.y ),
  19279. new THREE.Vector2( c.x, c.y )
  19280. ];
  19281. },
  19282. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  19283. var vertices = geometry.vertices;
  19284. var a = vertices[ indexA ];
  19285. var b = vertices[ indexB ];
  19286. var c = vertices[ indexC ];
  19287. var d = vertices[ indexD ];
  19288. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  19289. return [
  19290. new THREE.Vector2( a.x, 1 - a.z ),
  19291. new THREE.Vector2( b.x, 1 - b.z ),
  19292. new THREE.Vector2( c.x, 1 - c.z ),
  19293. new THREE.Vector2( d.x, 1 - d.z )
  19294. ];
  19295. } else {
  19296. return [
  19297. new THREE.Vector2( a.y, 1 - a.z ),
  19298. new THREE.Vector2( b.y, 1 - b.z ),
  19299. new THREE.Vector2( c.y, 1 - c.z ),
  19300. new THREE.Vector2( d.y, 1 - d.z )
  19301. ];
  19302. }
  19303. }
  19304. };
  19305. // File:src/extras/geometries/ShapeGeometry.js
  19306. /**
  19307. * @author jonobr1 / http://jonobr1.com
  19308. *
  19309. * Creates a one-sided polygonal geometry from a path shape. Similar to
  19310. * ExtrudeGeometry.
  19311. *
  19312. * parameters = {
  19313. *
  19314. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  19315. *
  19316. * material: <int> // material index for front and back faces
  19317. * uvGenerator: <Object> // object that provides UV generator functions
  19318. *
  19319. * }
  19320. **/
  19321. THREE.ShapeGeometry = function ( shapes, options ) {
  19322. THREE.Geometry.call( this );
  19323. this.type = 'ShapeGeometry';
  19324. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  19325. this.addShapeList( shapes, options );
  19326. this.computeFaceNormals();
  19327. };
  19328. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19329. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  19330. /**
  19331. * Add an array of shapes to THREE.ShapeGeometry.
  19332. */
  19333. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19334. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19335. this.addShape( shapes[ i ], options );
  19336. }
  19337. return this;
  19338. };
  19339. /**
  19340. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  19341. */
  19342. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  19343. if ( options === undefined ) options = {};
  19344. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19345. var material = options.material;
  19346. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  19347. //
  19348. var i, l, hole;
  19349. var shapesOffset = this.vertices.length;
  19350. var shapePoints = shape.extractPoints( curveSegments );
  19351. var vertices = shapePoints.shape;
  19352. var holes = shapePoints.holes;
  19353. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19354. if ( reverse ) {
  19355. vertices = vertices.reverse();
  19356. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  19357. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19358. hole = holes[ i ];
  19359. if ( THREE.Shape.Utils.isClockWise( hole ) ) {
  19360. holes[ i ] = hole.reverse();
  19361. }
  19362. }
  19363. reverse = false;
  19364. }
  19365. var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
  19366. // Vertices
  19367. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19368. hole = holes[ i ];
  19369. vertices = vertices.concat( hole );
  19370. }
  19371. //
  19372. var vert, vlen = vertices.length;
  19373. var face, flen = faces.length;
  19374. for ( i = 0; i < vlen; i ++ ) {
  19375. vert = vertices[ i ];
  19376. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  19377. }
  19378. for ( i = 0; i < flen; i ++ ) {
  19379. face = faces[ i ];
  19380. var a = face[ 0 ] + shapesOffset;
  19381. var b = face[ 1 ] + shapesOffset;
  19382. var c = face[ 2 ] + shapesOffset;
  19383. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  19384. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  19385. }
  19386. };
  19387. // File:src/extras/geometries/LatheGeometry.js
  19388. /**
  19389. * @author astrodud / http://astrodud.isgreat.org/
  19390. * @author zz85 / https://github.com/zz85
  19391. * @author bhouston / http://exocortex.com
  19392. */
  19393. // points - to create a closed torus, one must use a set of points
  19394. // like so: [ a, b, c, d, a ], see first is the same as last.
  19395. // segments - the number of circumference segments to create
  19396. // phiStart - the starting radian
  19397. // phiLength - the radian (0 to 2*PI) range of the lathed section
  19398. // 2*pi is a closed lathe, less than 2PI is a portion.
  19399. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  19400. THREE.Geometry.call( this );
  19401. this.type = 'LatheGeometry';
  19402. this.parameters = {
  19403. points: points,
  19404. segments: segments,
  19405. phiStart: phiStart,
  19406. phiLength: phiLength
  19407. };
  19408. segments = segments || 12;
  19409. phiStart = phiStart || 0;
  19410. phiLength = phiLength || 2 * Math.PI;
  19411. var inversePointLength = 1.0 / ( points.length - 1 );
  19412. var inverseSegments = 1.0 / segments;
  19413. for ( var i = 0, il = segments; i <= il; i ++ ) {
  19414. var phi = phiStart + i * inverseSegments * phiLength;
  19415. var c = Math.cos( phi ),
  19416. s = Math.sin( phi );
  19417. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  19418. var pt = points[ j ];
  19419. var vertex = new THREE.Vector3();
  19420. vertex.x = c * pt.x - s * pt.y;
  19421. vertex.y = s * pt.x + c * pt.y;
  19422. vertex.z = pt.z;
  19423. this.vertices.push( vertex );
  19424. }
  19425. }
  19426. var np = points.length;
  19427. for ( var i = 0, il = segments; i < il; i ++ ) {
  19428. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  19429. var base = j + np * i;
  19430. var a = base;
  19431. var b = base + np;
  19432. var c = base + 1 + np;
  19433. var d = base + 1;
  19434. var u0 = i * inverseSegments;
  19435. var v0 = j * inversePointLength;
  19436. var u1 = u0 + inverseSegments;
  19437. var v1 = v0 + inversePointLength;
  19438. this.faces.push( new THREE.Face3( a, b, d ) );
  19439. this.faceVertexUvs[ 0 ].push( [
  19440. new THREE.Vector2( u0, v0 ),
  19441. new THREE.Vector2( u1, v0 ),
  19442. new THREE.Vector2( u0, v1 )
  19443. ] );
  19444. this.faces.push( new THREE.Face3( b, c, d ) );
  19445. this.faceVertexUvs[ 0 ].push( [
  19446. new THREE.Vector2( u1, v0 ),
  19447. new THREE.Vector2( u1, v1 ),
  19448. new THREE.Vector2( u0, v1 )
  19449. ] );
  19450. }
  19451. }
  19452. this.mergeVertices();
  19453. this.computeFaceNormals();
  19454. this.computeVertexNormals();
  19455. };
  19456. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19457. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  19458. // File:src/extras/geometries/PlaneGeometry.js
  19459. /**
  19460. * @author mrdoob / http://mrdoob.com/
  19461. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19462. */
  19463. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  19464. THREE.Geometry.call( this );
  19465. this.type = 'PlaneGeometry';
  19466. this.parameters = {
  19467. width: width,
  19468. height: height,
  19469. widthSegments: widthSegments,
  19470. heightSegments: heightSegments
  19471. };
  19472. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  19473. };
  19474. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19475. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  19476. THREE.PlaneGeometry.prototype.clone = function () {
  19477. var geometry = new THREE.PlaneGeometry(
  19478. this.parameters.width,
  19479. this.parameters.height,
  19480. this.parameters.widthSegments,
  19481. this.parameters.heightSegments
  19482. );
  19483. return geometry;
  19484. };
  19485. // File:src/extras/geometries/PlaneBufferGeometry.js
  19486. /**
  19487. * @author mrdoob / http://mrdoob.com/
  19488. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19489. */
  19490. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  19491. THREE.BufferGeometry.call( this );
  19492. this.type = 'PlaneBufferGeometry';
  19493. this.parameters = {
  19494. width: width,
  19495. height: height,
  19496. widthSegments: widthSegments,
  19497. heightSegments: heightSegments
  19498. };
  19499. var width_half = width / 2;
  19500. var height_half = height / 2;
  19501. var gridX = Math.floor( widthSegments ) || 1;
  19502. var gridY = Math.floor( heightSegments ) || 1;
  19503. var gridX1 = gridX + 1;
  19504. var gridY1 = gridY + 1;
  19505. var segment_width = width / gridX;
  19506. var segment_height = height / gridY;
  19507. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  19508. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  19509. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  19510. var offset = 0;
  19511. var offset2 = 0;
  19512. for ( var iy = 0; iy < gridY1; iy ++ ) {
  19513. var y = iy * segment_height - height_half;
  19514. for ( var ix = 0; ix < gridX1; ix ++ ) {
  19515. var x = ix * segment_width - width_half;
  19516. vertices[ offset ] = x;
  19517. vertices[ offset + 1 ] = - y;
  19518. normals[ offset + 2 ] = 1;
  19519. uvs[ offset2 ] = ix / gridX;
  19520. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  19521. offset += 3;
  19522. offset2 += 2;
  19523. }
  19524. }
  19525. offset = 0;
  19526. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  19527. for ( var iy = 0; iy < gridY; iy ++ ) {
  19528. for ( var ix = 0; ix < gridX; ix ++ ) {
  19529. var a = ix + gridX1 * iy;
  19530. var b = ix + gridX1 * ( iy + 1 );
  19531. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  19532. var d = ( ix + 1 ) + gridX1 * iy;
  19533. indices[ offset ] = a;
  19534. indices[ offset + 1 ] = b;
  19535. indices[ offset + 2 ] = d;
  19536. indices[ offset + 3 ] = b;
  19537. indices[ offset + 4 ] = c;
  19538. indices[ offset + 5 ] = d;
  19539. offset += 6;
  19540. }
  19541. }
  19542. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  19543. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  19544. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  19545. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  19546. };
  19547. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19548. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  19549. THREE.PlaneBufferGeometry.prototype.clone = function () {
  19550. var geometry = new THREE.PlaneBufferGeometry(
  19551. this.parameters.width,
  19552. this.parameters.height,
  19553. this.parameters.widthSegments,
  19554. this.parameters.heightSegments
  19555. );
  19556. geometry.copy( this );
  19557. return geometry;
  19558. };
  19559. // File:src/extras/geometries/RingGeometry.js
  19560. /**
  19561. * @author Kaleb Murphy
  19562. */
  19563. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19564. THREE.Geometry.call( this );
  19565. this.type = 'RingGeometry';
  19566. this.parameters = {
  19567. innerRadius: innerRadius,
  19568. outerRadius: outerRadius,
  19569. thetaSegments: thetaSegments,
  19570. phiSegments: phiSegments,
  19571. thetaStart: thetaStart,
  19572. thetaLength: thetaLength
  19573. };
  19574. innerRadius = innerRadius || 0;
  19575. outerRadius = outerRadius || 50;
  19576. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19577. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19578. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  19579. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  19580. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19581. for ( i = 0; i < phiSegments + 1; i ++ ) {
  19582. // concentric circles inside ring
  19583. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  19584. // number of segments per circle
  19585. var vertex = new THREE.Vector3();
  19586. var segment = thetaStart + o / thetaSegments * thetaLength;
  19587. vertex.x = radius * Math.cos( segment );
  19588. vertex.y = radius * Math.sin( segment );
  19589. this.vertices.push( vertex );
  19590. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  19591. }
  19592. radius += radiusStep;
  19593. }
  19594. var n = new THREE.Vector3( 0, 0, 1 );
  19595. for ( i = 0; i < phiSegments; i ++ ) {
  19596. // concentric circles inside ring
  19597. var thetaSegment = i * ( thetaSegments + 1 );
  19598. for ( o = 0; o < thetaSegments ; o ++ ) {
  19599. // number of segments per circle
  19600. var segment = o + thetaSegment;
  19601. var v1 = segment;
  19602. var v2 = segment + thetaSegments + 1;
  19603. var v3 = segment + thetaSegments + 2;
  19604. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19605. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  19606. v1 = segment;
  19607. v2 = segment + thetaSegments + 2;
  19608. v3 = segment + 1;
  19609. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19610. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  19611. }
  19612. }
  19613. this.computeFaceNormals();
  19614. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19615. };
  19616. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19617. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  19618. THREE.RingGeometry.prototype.clone = function () {
  19619. var geometry = new THREE.RingGeometry(
  19620. this.parameters.innerRadius,
  19621. this.parameters.outerRadius,
  19622. this.parameters.thetaSegments,
  19623. this.parameters.phiSegments,
  19624. this.parameters.thetaStart,
  19625. this.parameters.thetaLength
  19626. );
  19627. return geometry;
  19628. };
  19629. // File:src/extras/geometries/SphereGeometry.js
  19630. /**
  19631. * @author mrdoob / http://mrdoob.com/
  19632. */
  19633. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19634. console.log( 'THREE.SphereGeometry: Consider using THREE.SphereBufferGeometry for lower memory footprint.' );
  19635. THREE.Geometry.call( this );
  19636. this.type = 'SphereGeometry';
  19637. this.parameters = {
  19638. radius: radius,
  19639. widthSegments: widthSegments,
  19640. heightSegments: heightSegments,
  19641. phiStart: phiStart,
  19642. phiLength: phiLength,
  19643. thetaStart: thetaStart,
  19644. thetaLength: thetaLength
  19645. };
  19646. radius = radius || 50;
  19647. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19648. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19649. phiStart = phiStart !== undefined ? phiStart : 0;
  19650. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19651. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19652. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19653. var x, y, vertices = [], uvs = [];
  19654. for ( y = 0; y <= heightSegments; y ++ ) {
  19655. var verticesRow = [];
  19656. var uvsRow = [];
  19657. for ( x = 0; x <= widthSegments; x ++ ) {
  19658. var u = x / widthSegments;
  19659. var v = y / heightSegments;
  19660. var vertex = new THREE.Vector3();
  19661. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19662. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  19663. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19664. this.vertices.push( vertex );
  19665. verticesRow.push( this.vertices.length - 1 );
  19666. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  19667. }
  19668. vertices.push( verticesRow );
  19669. uvs.push( uvsRow );
  19670. }
  19671. for ( y = 0; y < heightSegments; y ++ ) {
  19672. for ( x = 0; x < widthSegments; x ++ ) {
  19673. var v1 = vertices[ y ][ x + 1 ];
  19674. var v2 = vertices[ y ][ x ];
  19675. var v3 = vertices[ y + 1 ][ x ];
  19676. var v4 = vertices[ y + 1 ][ x + 1 ];
  19677. var n1 = this.vertices[ v1 ].clone().normalize();
  19678. var n2 = this.vertices[ v2 ].clone().normalize();
  19679. var n3 = this.vertices[ v3 ].clone().normalize();
  19680. var n4 = this.vertices[ v4 ].clone().normalize();
  19681. var uv1 = uvs[ y ][ x + 1 ].clone();
  19682. var uv2 = uvs[ y ][ x ].clone();
  19683. var uv3 = uvs[ y + 1 ][ x ].clone();
  19684. var uv4 = uvs[ y + 1 ][ x + 1 ].clone();
  19685. if ( Math.abs( this.vertices[ v1 ].y ) === radius ) {
  19686. uv1.x = ( uv1.x + uv2.x ) / 2;
  19687. this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
  19688. this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
  19689. } else if ( Math.abs( this.vertices[ v3 ].y ) === radius ) {
  19690. uv3.x = ( uv3.x + uv4.x ) / 2;
  19691. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  19692. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19693. } else {
  19694. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  19695. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  19696. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  19697. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  19698. }
  19699. }
  19700. }
  19701. this.computeFaceNormals();
  19702. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19703. };
  19704. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19705. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  19706. THREE.SphereGeometry.prototype.clone = function () {
  19707. var geometry = new THREE.SphereGeometry(
  19708. this.parameters.radius,
  19709. this.parameters.widthSegments,
  19710. this.parameters.heightSegments,
  19711. this.parameters.phiStart,
  19712. this.parameters.phiLength,
  19713. this.parameters.thetaStart,
  19714. this.parameters.thetaLength
  19715. );
  19716. return geometry;
  19717. };
  19718. // File:src/extras/geometries/SphereBufferGeometry.js
  19719. /**
  19720. * @author benaadams / https://twitter.com/ben_a_adams
  19721. * based on THREE.SphereGeometry
  19722. */
  19723. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19724. THREE.BufferGeometry.call( this );
  19725. this.type = 'SphereBufferGeometry';
  19726. this.parameters = {
  19727. radius: radius,
  19728. widthSegments: widthSegments,
  19729. heightSegments: heightSegments,
  19730. phiStart: phiStart,
  19731. phiLength: phiLength,
  19732. thetaStart: thetaStart,
  19733. thetaLength: thetaLength
  19734. };
  19735. radius = radius || 50;
  19736. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19737. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19738. phiStart = phiStart !== undefined ? phiStart : 0;
  19739. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19740. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19741. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19742. var thetaEnd = thetaStart + thetaLength;
  19743. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  19744. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19745. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19746. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  19747. var index = 0, vertices = [], normal = new THREE.Vector3();
  19748. for ( var y = 0; y <= heightSegments; y ++ ) {
  19749. var verticesRow = [];
  19750. var v = y / heightSegments;
  19751. for ( var x = 0; x <= widthSegments; x ++ ) {
  19752. var u = x / widthSegments;
  19753. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19754. var py = radius * Math.cos( thetaStart + v * thetaLength );
  19755. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19756. normal.set( px, py, pz ).normalize();
  19757. positions.setXYZ( index, px, py, pz );
  19758. normals.setXYZ( index, normal.x, normal.y, normal.z );
  19759. uvs.setXY( index, u, 1 - v );
  19760. verticesRow.push( index );
  19761. index ++;
  19762. }
  19763. vertices.push( verticesRow );
  19764. }
  19765. var indices = [];
  19766. for ( var y = 0; y < heightSegments; y ++ ) {
  19767. for ( var x = 0; x < widthSegments; x ++ ) {
  19768. var v1 = vertices[ y ][ x + 1 ];
  19769. var v2 = vertices[ y ][ x ];
  19770. var v3 = vertices[ y + 1 ][ x ];
  19771. var v4 = vertices[ y + 1 ][ x + 1 ];
  19772. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  19773. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  19774. }
  19775. }
  19776. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  19777. this.addAttribute( 'position', positions );
  19778. this.addAttribute( 'normal', normals );
  19779. this.addAttribute( 'uv', uvs );
  19780. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19781. };
  19782. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19783. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  19784. THREE.SphereBufferGeometry.prototype.clone = function () {
  19785. var geometry = new THREE.SphereBufferGeometry(
  19786. this.parameters.radius,
  19787. this.parameters.widthSegments,
  19788. this.parameters.heightSegments,
  19789. this.parameters.phiStart,
  19790. this.parameters.phiLength,
  19791. this.parameters.thetaStart,
  19792. this.parameters.thetaLength
  19793. );
  19794. geometry.copy( this );
  19795. return geometry;
  19796. };
  19797. // File:src/extras/geometries/TextGeometry.js
  19798. /**
  19799. * @author zz85 / http://www.lab4games.net/zz85/blog
  19800. * @author alteredq / http://alteredqualia.com/
  19801. *
  19802. * For creating 3D text geometry in three.js
  19803. *
  19804. * Text = 3D Text
  19805. *
  19806. * parameters = {
  19807. * size: <float>, // size of the text
  19808. * height: <float>, // thickness to extrude text
  19809. * curveSegments: <int>, // number of points on the curves
  19810. *
  19811. * font: <string>, // font name
  19812. * weight: <string>, // font weight (normal, bold)
  19813. * style: <string>, // font style (normal, italics)
  19814. *
  19815. * bevelEnabled: <bool>, // turn on bevel
  19816. * bevelThickness: <float>, // how deep into text bevel goes
  19817. * bevelSize: <float>, // how far from text outline is bevel
  19818. * }
  19819. *
  19820. */
  19821. /* Usage Examples
  19822. // TextGeometry wrapper
  19823. var text3d = new TextGeometry( text, options );
  19824. // Complete manner
  19825. var textShapes = THREE.FontUtils.generateShapes( text, options );
  19826. var text3d = new ExtrudeGeometry( textShapes, options );
  19827. */
  19828. THREE.TextGeometry = function ( text, parameters ) {
  19829. parameters = parameters || {};
  19830. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  19831. // translate parameters to ExtrudeGeometry API
  19832. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  19833. // defaults
  19834. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  19835. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  19836. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  19837. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  19838. this.type = 'TextGeometry';
  19839. };
  19840. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  19841. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  19842. // File:src/extras/geometries/TorusGeometry.js
  19843. /**
  19844. * @author oosmoxiecode
  19845. * @author mrdoob / http://mrdoob.com/
  19846. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  19847. */
  19848. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  19849. THREE.Geometry.call( this );
  19850. this.type = 'TorusGeometry';
  19851. this.parameters = {
  19852. radius: radius,
  19853. tube: tube,
  19854. radialSegments: radialSegments,
  19855. tubularSegments: tubularSegments,
  19856. arc: arc
  19857. };
  19858. radius = radius || 100;
  19859. tube = tube || 40;
  19860. radialSegments = radialSegments || 8;
  19861. tubularSegments = tubularSegments || 6;
  19862. arc = arc || Math.PI * 2;
  19863. var center = new THREE.Vector3(), uvs = [], normals = [];
  19864. for ( var j = 0; j <= radialSegments; j ++ ) {
  19865. for ( var i = 0; i <= tubularSegments; i ++ ) {
  19866. var u = i / tubularSegments * arc;
  19867. var v = j / radialSegments * Math.PI * 2;
  19868. center.x = radius * Math.cos( u );
  19869. center.y = radius * Math.sin( u );
  19870. var vertex = new THREE.Vector3();
  19871. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  19872. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  19873. vertex.z = tube * Math.sin( v );
  19874. this.vertices.push( vertex );
  19875. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  19876. normals.push( vertex.clone().sub( center ).normalize() );
  19877. }
  19878. }
  19879. for ( var j = 1; j <= radialSegments; j ++ ) {
  19880. for ( var i = 1; i <= tubularSegments; i ++ ) {
  19881. var a = ( tubularSegments + 1 ) * j + i - 1;
  19882. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  19883. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  19884. var d = ( tubularSegments + 1 ) * j + i;
  19885. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  19886. this.faces.push( face );
  19887. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  19888. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  19889. this.faces.push( face );
  19890. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  19891. }
  19892. }
  19893. this.computeFaceNormals();
  19894. };
  19895. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19896. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  19897. THREE.TorusGeometry.prototype.clone = function () {
  19898. var geometry = new THREE.TorusGeometry(
  19899. this.parameters.radius,
  19900. this.parameters.tube,
  19901. this.parameters.radialSegments,
  19902. this.parameters.tubularSegments,
  19903. this.parameters.arc
  19904. );
  19905. return geometry;
  19906. };
  19907. // File:src/extras/geometries/TorusKnotGeometry.js
  19908. /**
  19909. * @author oosmoxiecode
  19910. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  19911. */
  19912. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  19913. THREE.Geometry.call( this );
  19914. this.type = 'TorusKnotGeometry';
  19915. this.parameters = {
  19916. radius: radius,
  19917. tube: tube,
  19918. radialSegments: radialSegments,
  19919. tubularSegments: tubularSegments,
  19920. p: p,
  19921. q: q,
  19922. heightScale: heightScale
  19923. };
  19924. radius = radius || 100;
  19925. tube = tube || 40;
  19926. radialSegments = radialSegments || 64;
  19927. tubularSegments = tubularSegments || 8;
  19928. p = p || 2;
  19929. q = q || 3;
  19930. heightScale = heightScale || 1;
  19931. var grid = new Array( radialSegments );
  19932. var tang = new THREE.Vector3();
  19933. var n = new THREE.Vector3();
  19934. var bitan = new THREE.Vector3();
  19935. for ( var i = 0; i < radialSegments; ++ i ) {
  19936. grid[ i ] = new Array( tubularSegments );
  19937. var u = i / radialSegments * 2 * p * Math.PI;
  19938. var p1 = getPos( u, q, p, radius, heightScale );
  19939. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  19940. tang.subVectors( p2, p1 );
  19941. n.addVectors( p2, p1 );
  19942. bitan.crossVectors( tang, n );
  19943. n.crossVectors( bitan, tang );
  19944. bitan.normalize();
  19945. n.normalize();
  19946. for ( var j = 0; j < tubularSegments; ++ j ) {
  19947. var v = j / tubularSegments * 2 * Math.PI;
  19948. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19949. var cy = tube * Math.sin( v );
  19950. var pos = new THREE.Vector3();
  19951. pos.x = p1.x + cx * n.x + cy * bitan.x;
  19952. pos.y = p1.y + cx * n.y + cy * bitan.y;
  19953. pos.z = p1.z + cx * n.z + cy * bitan.z;
  19954. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  19955. }
  19956. }
  19957. for ( var i = 0; i < radialSegments; ++ i ) {
  19958. for ( var j = 0; j < tubularSegments; ++ j ) {
  19959. var ip = ( i + 1 ) % radialSegments;
  19960. var jp = ( j + 1 ) % tubularSegments;
  19961. var a = grid[ i ][ j ];
  19962. var b = grid[ ip ][ j ];
  19963. var c = grid[ ip ][ jp ];
  19964. var d = grid[ i ][ jp ];
  19965. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  19966. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  19967. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  19968. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  19969. this.faces.push( new THREE.Face3( a, b, d ) );
  19970. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19971. this.faces.push( new THREE.Face3( b, c, d ) );
  19972. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19973. }
  19974. }
  19975. this.computeFaceNormals();
  19976. this.computeVertexNormals();
  19977. function getPos( u, in_q, in_p, radius, heightScale ) {
  19978. var cu = Math.cos( u );
  19979. var su = Math.sin( u );
  19980. var quOverP = in_q / in_p * u;
  19981. var cs = Math.cos( quOverP );
  19982. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  19983. var ty = radius * ( 2 + cs ) * su * 0.5;
  19984. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  19985. return new THREE.Vector3( tx, ty, tz );
  19986. }
  19987. };
  19988. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19989. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  19990. THREE.TorusKnotGeometry.prototype.clone = function () {
  19991. var geometry = new THREE.TorusKnotGeometry(
  19992. this.parameters.radius,
  19993. this.parameters.tube,
  19994. this.parameters.radialSegments,
  19995. this.parameters.tubularSegments,
  19996. this.parameters.p,
  19997. this.parameters.q,
  19998. this.parameters.heightScale
  19999. );
  20000. return geometry;
  20001. };
  20002. // File:src/extras/geometries/TubeGeometry.js
  20003. /**
  20004. * @author WestLangley / https://github.com/WestLangley
  20005. * @author zz85 / https://github.com/zz85
  20006. * @author miningold / https://github.com/miningold
  20007. * @author jonobr1 / https://github.com/jonobr1
  20008. *
  20009. * Modified from the TorusKnotGeometry by @oosmoxiecode
  20010. *
  20011. * Creates a tube which extrudes along a 3d spline
  20012. *
  20013. * Uses parallel transport frames as described in
  20014. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  20015. */
  20016. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  20017. THREE.Geometry.call( this );
  20018. this.type = 'TubeGeometry';
  20019. this.parameters = {
  20020. path: path,
  20021. segments: segments,
  20022. radius: radius,
  20023. radialSegments: radialSegments,
  20024. closed: closed
  20025. };
  20026. segments = segments || 64;
  20027. radius = radius || 1;
  20028. radialSegments = radialSegments || 8;
  20029. closed = closed || false;
  20030. taper = taper || THREE.TubeGeometry.NoTaper;
  20031. var grid = [];
  20032. var scope = this,
  20033. tangent,
  20034. normal,
  20035. binormal,
  20036. numpoints = segments + 1,
  20037. u, v, r,
  20038. cx, cy,
  20039. pos, pos2 = new THREE.Vector3(),
  20040. i, j,
  20041. ip, jp,
  20042. a, b, c, d,
  20043. uva, uvb, uvc, uvd;
  20044. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  20045. tangents = frames.tangents,
  20046. normals = frames.normals,
  20047. binormals = frames.binormals;
  20048. // proxy internals
  20049. this.tangents = tangents;
  20050. this.normals = normals;
  20051. this.binormals = binormals;
  20052. function vert( x, y, z ) {
  20053. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  20054. }
  20055. // construct the grid
  20056. for ( i = 0; i < numpoints; i ++ ) {
  20057. grid[ i ] = [];
  20058. u = i / ( numpoints - 1 );
  20059. pos = path.getPointAt( u );
  20060. tangent = tangents[ i ];
  20061. normal = normals[ i ];
  20062. binormal = binormals[ i ];
  20063. r = radius * taper( u );
  20064. for ( j = 0; j < radialSegments; j ++ ) {
  20065. v = j / radialSegments * 2 * Math.PI;
  20066. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  20067. cy = r * Math.sin( v );
  20068. pos2.copy( pos );
  20069. pos2.x += cx * normal.x + cy * binormal.x;
  20070. pos2.y += cx * normal.y + cy * binormal.y;
  20071. pos2.z += cx * normal.z + cy * binormal.z;
  20072. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  20073. }
  20074. }
  20075. // construct the mesh
  20076. for ( i = 0; i < segments; i ++ ) {
  20077. for ( j = 0; j < radialSegments; j ++ ) {
  20078. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  20079. jp = ( j + 1 ) % radialSegments;
  20080. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  20081. b = grid[ ip ][ j ];
  20082. c = grid[ ip ][ jp ];
  20083. d = grid[ i ][ jp ];
  20084. uva = new THREE.Vector2( i / segments, j / radialSegments );
  20085. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  20086. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  20087. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  20088. this.faces.push( new THREE.Face3( a, b, d ) );
  20089. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20090. this.faces.push( new THREE.Face3( b, c, d ) );
  20091. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  20092. }
  20093. }
  20094. this.computeFaceNormals();
  20095. this.computeVertexNormals();
  20096. };
  20097. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20098. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  20099. THREE.TubeGeometry.NoTaper = function ( u ) {
  20100. return 1;
  20101. };
  20102. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  20103. return Math.sin( Math.PI * u );
  20104. };
  20105. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  20106. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  20107. var normal = new THREE.Vector3(),
  20108. tangents = [],
  20109. normals = [],
  20110. binormals = [],
  20111. vec = new THREE.Vector3(),
  20112. mat = new THREE.Matrix4(),
  20113. numpoints = segments + 1,
  20114. theta,
  20115. epsilon = 0.0001,
  20116. smallest,
  20117. tx, ty, tz,
  20118. i, u;
  20119. // expose internals
  20120. this.tangents = tangents;
  20121. this.normals = normals;
  20122. this.binormals = binormals;
  20123. // compute the tangent vectors for each segment on the path
  20124. for ( i = 0; i < numpoints; i ++ ) {
  20125. u = i / ( numpoints - 1 );
  20126. tangents[ i ] = path.getTangentAt( u );
  20127. tangents[ i ].normalize();
  20128. }
  20129. initialNormal3();
  20130. /*
  20131. function initialNormal1(lastBinormal) {
  20132. // fixed start binormal. Has dangers of 0 vectors
  20133. normals[ 0 ] = new THREE.Vector3();
  20134. binormals[ 0 ] = new THREE.Vector3();
  20135. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  20136. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  20137. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20138. }
  20139. function initialNormal2() {
  20140. // This uses the Frenet-Serret formula for deriving binormal
  20141. var t2 = path.getTangentAt( epsilon );
  20142. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  20143. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  20144. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  20145. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20146. }
  20147. */
  20148. function initialNormal3() {
  20149. // select an initial normal vector perpendicular to the first tangent vector,
  20150. // and in the direction of the smallest tangent xyz component
  20151. normals[ 0 ] = new THREE.Vector3();
  20152. binormals[ 0 ] = new THREE.Vector3();
  20153. smallest = Number.MAX_VALUE;
  20154. tx = Math.abs( tangents[ 0 ].x );
  20155. ty = Math.abs( tangents[ 0 ].y );
  20156. tz = Math.abs( tangents[ 0 ].z );
  20157. if ( tx <= smallest ) {
  20158. smallest = tx;
  20159. normal.set( 1, 0, 0 );
  20160. }
  20161. if ( ty <= smallest ) {
  20162. smallest = ty;
  20163. normal.set( 0, 1, 0 );
  20164. }
  20165. if ( tz <= smallest ) {
  20166. normal.set( 0, 0, 1 );
  20167. }
  20168. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20169. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20170. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20171. }
  20172. // compute the slowly-varying normal and binormal vectors for each segment on the path
  20173. for ( i = 1; i < numpoints; i ++ ) {
  20174. normals[ i ] = normals[ i - 1 ].clone();
  20175. binormals[ i ] = binormals[ i - 1 ].clone();
  20176. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20177. if ( vec.length() > epsilon ) {
  20178. vec.normalize();
  20179. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20180. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20181. }
  20182. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20183. }
  20184. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20185. if ( closed ) {
  20186. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  20187. theta /= ( numpoints - 1 );
  20188. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  20189. theta = - theta;
  20190. }
  20191. for ( i = 1; i < numpoints; i ++ ) {
  20192. // twist a little...
  20193. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  20194. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20195. }
  20196. }
  20197. };
  20198. // File:src/extras/geometries/PolyhedronGeometry.js
  20199. /**
  20200. * @author clockworkgeek / https://github.com/clockworkgeek
  20201. * @author timothypratley / https://github.com/timothypratley
  20202. * @author WestLangley / http://github.com/WestLangley
  20203. */
  20204. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  20205. THREE.Geometry.call( this );
  20206. this.type = 'PolyhedronGeometry';
  20207. this.parameters = {
  20208. vertices: vertices,
  20209. indices: indices,
  20210. radius: radius,
  20211. detail: detail
  20212. };
  20213. radius = radius || 1;
  20214. detail = detail || 0;
  20215. var that = this;
  20216. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  20217. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  20218. }
  20219. var p = this.vertices;
  20220. var faces = [];
  20221. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  20222. var v1 = p[ indices[ i ] ];
  20223. var v2 = p[ indices[ i + 1 ] ];
  20224. var v3 = p[ indices[ i + 2 ] ];
  20225. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  20226. }
  20227. var centroid = new THREE.Vector3();
  20228. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20229. subdivide( faces[ i ], detail );
  20230. }
  20231. // Handle case when face straddles the seam
  20232. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  20233. var uvs = this.faceVertexUvs[ 0 ][ i ];
  20234. var x0 = uvs[ 0 ].x;
  20235. var x1 = uvs[ 1 ].x;
  20236. var x2 = uvs[ 2 ].x;
  20237. var max = Math.max( x0, Math.max( x1, x2 ) );
  20238. var min = Math.min( x0, Math.min( x1, x2 ) );
  20239. if ( max > 0.9 && min < 0.1 ) {
  20240. // 0.9 is somewhat arbitrary
  20241. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  20242. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  20243. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  20244. }
  20245. }
  20246. // Apply radius
  20247. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  20248. this.vertices[ i ].multiplyScalar( radius );
  20249. }
  20250. // Merge vertices
  20251. this.mergeVertices();
  20252. this.computeFaceNormals();
  20253. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20254. // Project vector onto sphere's surface
  20255. function prepare( vector ) {
  20256. var vertex = vector.normalize().clone();
  20257. vertex.index = that.vertices.push( vertex ) - 1;
  20258. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  20259. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  20260. var v = inclination( vector ) / Math.PI + 0.5;
  20261. vertex.uv = new THREE.Vector2( u, 1 - v );
  20262. return vertex;
  20263. }
  20264. // Approximate a curved face with recursively sub-divided triangles.
  20265. function make( v1, v2, v3 ) {
  20266. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  20267. that.faces.push( face );
  20268. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  20269. var azi = azimuth( centroid );
  20270. that.faceVertexUvs[ 0 ].push( [
  20271. correctUV( v1.uv, v1, azi ),
  20272. correctUV( v2.uv, v2, azi ),
  20273. correctUV( v3.uv, v3, azi )
  20274. ] );
  20275. }
  20276. // Analytically subdivide a face to the required detail level.
  20277. function subdivide( face, detail ) {
  20278. var cols = Math.pow( 2, detail );
  20279. var a = prepare( that.vertices[ face.a ] );
  20280. var b = prepare( that.vertices[ face.b ] );
  20281. var c = prepare( that.vertices[ face.c ] );
  20282. var v = [];
  20283. // Construct all of the vertices for this subdivision.
  20284. for ( var i = 0 ; i <= cols; i ++ ) {
  20285. v[ i ] = [];
  20286. var aj = prepare( a.clone().lerp( c, i / cols ) );
  20287. var bj = prepare( b.clone().lerp( c, i / cols ) );
  20288. var rows = cols - i;
  20289. for ( var j = 0; j <= rows; j ++ ) {
  20290. if ( j === 0 && i === cols ) {
  20291. v[ i ][ j ] = aj;
  20292. } else {
  20293. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  20294. }
  20295. }
  20296. }
  20297. // Construct all of the faces.
  20298. for ( var i = 0; i < cols ; i ++ ) {
  20299. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  20300. var k = Math.floor( j / 2 );
  20301. if ( j % 2 === 0 ) {
  20302. make(
  20303. v[ i ][ k + 1 ],
  20304. v[ i + 1 ][ k ],
  20305. v[ i ][ k ]
  20306. );
  20307. } else {
  20308. make(
  20309. v[ i ][ k + 1 ],
  20310. v[ i + 1 ][ k + 1 ],
  20311. v[ i + 1 ][ k ]
  20312. );
  20313. }
  20314. }
  20315. }
  20316. }
  20317. // Angle around the Y axis, counter-clockwise when looking from above.
  20318. function azimuth( vector ) {
  20319. return Math.atan2( vector.z, - vector.x );
  20320. }
  20321. // Angle above the XZ plane.
  20322. function inclination( vector ) {
  20323. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  20324. }
  20325. // Texture fixing helper. Spheres have some odd behaviours.
  20326. function correctUV( uv, vector, azimuth ) {
  20327. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  20328. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  20329. return uv.clone();
  20330. }
  20331. };
  20332. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20333. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  20334. THREE.PolyhedronGeometry.prototype.clone = function () {
  20335. var geometry = new THREE.PolyhedronGeometry(
  20336. this.parameters.vertices,
  20337. this.parameters.indices,
  20338. this.parameters.radius,
  20339. this.parameters.detail
  20340. );
  20341. return geometry.copy( this );
  20342. };
  20343. THREE.PolyhedronGeometry.prototype.copy = function ( source ) {
  20344. THREE.Geometry.prototype.copy.call( this, source );
  20345. return this;
  20346. };
  20347. // File:src/extras/geometries/DodecahedronGeometry.js
  20348. /**
  20349. * @author Abe Pazos / https://hamoid.com
  20350. */
  20351. THREE.DodecahedronGeometry = function ( radius, detail ) {
  20352. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20353. var r = 1 / t;
  20354. var vertices = [
  20355. // (±1, ±1, ±1)
  20356. - 1, - 1, - 1, - 1, - 1, 1,
  20357. - 1, 1, - 1, - 1, 1, 1,
  20358. 1, - 1, - 1, 1, - 1, 1,
  20359. 1, 1, - 1, 1, 1, 1,
  20360. // (0, ±1/φ, ±φ)
  20361. 0, - r, - t, 0, - r, t,
  20362. 0, r, - t, 0, r, t,
  20363. // (±1/φ, ±φ, 0)
  20364. - r, - t, 0, - r, t, 0,
  20365. r, - t, 0, r, t, 0,
  20366. // (±φ, 0, ±1/φ)
  20367. - t, 0, - r, t, 0, - r,
  20368. - t, 0, r, t, 0, r
  20369. ];
  20370. var indices = [
  20371. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  20372. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  20373. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  20374. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  20375. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  20376. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  20377. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  20378. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  20379. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  20380. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  20381. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  20382. 1, 12, 14, 1, 14, 5, 1, 5, 9
  20383. ];
  20384. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20385. this.type = 'DodecahedronGeometry';
  20386. this.parameters = {
  20387. radius: radius,
  20388. detail: detail
  20389. };
  20390. };
  20391. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20392. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  20393. THREE.DodecahedronGeometry.prototype.clone = function () {
  20394. var geometry = new THREE.DodecahedronGeometry(
  20395. this.parameters.radius,
  20396. this.parameters.detail
  20397. );
  20398. geometry.copy( this );
  20399. return geometry;
  20400. };
  20401. // File:src/extras/geometries/IcosahedronGeometry.js
  20402. /**
  20403. * @author timothypratley / https://github.com/timothypratley
  20404. */
  20405. THREE.IcosahedronGeometry = function ( radius, detail ) {
  20406. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20407. var vertices = [
  20408. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  20409. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  20410. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  20411. ];
  20412. var indices = [
  20413. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  20414. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  20415. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  20416. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  20417. ];
  20418. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20419. this.type = 'IcosahedronGeometry';
  20420. this.parameters = {
  20421. radius: radius,
  20422. detail: detail
  20423. };
  20424. };
  20425. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20426. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  20427. THREE.IcosahedronGeometry.prototype.clone = function () {
  20428. var geometry = new THREE.IcosahedronGeometry(
  20429. this.parameters.radius,
  20430. this.parameters.detail
  20431. );
  20432. geometry.copy( this );
  20433. return geometry;
  20434. };
  20435. // File:src/extras/geometries/OctahedronGeometry.js
  20436. /**
  20437. * @author timothypratley / https://github.com/timothypratley
  20438. */
  20439. THREE.OctahedronGeometry = function ( radius, detail ) {
  20440. var vertices = [
  20441. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  20442. ];
  20443. var indices = [
  20444. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  20445. ];
  20446. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20447. this.type = 'OctahedronGeometry';
  20448. this.parameters = {
  20449. radius: radius,
  20450. detail: detail
  20451. };
  20452. };
  20453. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20454. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  20455. THREE.OctahedronGeometry.prototype.clone = function () {
  20456. var geometry = new THREE.OctahedronGeometry(
  20457. this.parameters.radius,
  20458. this.parameters.detail
  20459. );
  20460. geometry.copy( this );
  20461. return geometry;
  20462. };
  20463. // File:src/extras/geometries/TetrahedronGeometry.js
  20464. /**
  20465. * @author timothypratley / https://github.com/timothypratley
  20466. */
  20467. THREE.TetrahedronGeometry = function ( radius, detail ) {
  20468. var vertices = [
  20469. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20470. ];
  20471. var indices = [
  20472. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20473. ];
  20474. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20475. this.type = 'TetrahedronGeometry';
  20476. this.parameters = {
  20477. radius: radius,
  20478. detail: detail
  20479. };
  20480. };
  20481. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20482. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  20483. THREE.TetrahedronGeometry.prototype.clone = function () {
  20484. var geometry = new THREE.TetrahedronGeometry(
  20485. this.parameters.radius,
  20486. this.parameters.detail
  20487. );
  20488. geometry.copy( this );
  20489. return geometry;
  20490. };
  20491. // File:src/extras/geometries/ParametricGeometry.js
  20492. /**
  20493. * @author zz85 / https://github.com/zz85
  20494. * Parametric Surfaces Geometry
  20495. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  20496. *
  20497. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  20498. *
  20499. */
  20500. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  20501. THREE.Geometry.call( this );
  20502. this.type = 'ParametricGeometry';
  20503. this.parameters = {
  20504. func: func,
  20505. slices: slices,
  20506. stacks: stacks
  20507. };
  20508. var verts = this.vertices;
  20509. var faces = this.faces;
  20510. var uvs = this.faceVertexUvs[ 0 ];
  20511. var i, j, p;
  20512. var u, v;
  20513. var sliceCount = slices + 1;
  20514. for ( i = 0; i <= stacks; i ++ ) {
  20515. v = i / stacks;
  20516. for ( j = 0; j <= slices; j ++ ) {
  20517. u = j / slices;
  20518. p = func( u, v );
  20519. verts.push( p );
  20520. }
  20521. }
  20522. var a, b, c, d;
  20523. var uva, uvb, uvc, uvd;
  20524. for ( i = 0; i < stacks; i ++ ) {
  20525. for ( j = 0; j < slices; j ++ ) {
  20526. a = i * sliceCount + j;
  20527. b = i * sliceCount + j + 1;
  20528. c = ( i + 1 ) * sliceCount + j + 1;
  20529. d = ( i + 1 ) * sliceCount + j;
  20530. uva = new THREE.Vector2( j / slices, i / stacks );
  20531. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  20532. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  20533. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  20534. faces.push( new THREE.Face3( a, b, d ) );
  20535. uvs.push( [ uva, uvb, uvd ] );
  20536. faces.push( new THREE.Face3( b, c, d ) );
  20537. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  20538. }
  20539. }
  20540. // console.log(this);
  20541. // magic bullet
  20542. // var diff = this.mergeVertices();
  20543. // console.log('removed ', diff, ' vertices by merging');
  20544. this.computeFaceNormals();
  20545. this.computeVertexNormals();
  20546. };
  20547. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20548. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  20549. // File:src/extras/geometries/WireframeGeometry.js
  20550. /**
  20551. * @author mrdoob / http://mrdoob.com/
  20552. */
  20553. THREE.WireframeGeometry = function ( geometry ) {
  20554. THREE.BufferGeometry.call( this );
  20555. var edge = [ 0, 0 ], hash = {};
  20556. var sortFunction = function ( a, b ) {
  20557. return a - b;
  20558. };
  20559. var keys = [ 'a', 'b', 'c' ];
  20560. if ( geometry instanceof THREE.Geometry ) {
  20561. var vertices = geometry.vertices;
  20562. var faces = geometry.faces;
  20563. var numEdges = 0;
  20564. // allocate maximal size
  20565. var edges = new Uint32Array( 6 * faces.length );
  20566. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20567. var face = faces[ i ];
  20568. for ( var j = 0; j < 3; j ++ ) {
  20569. edge[ 0 ] = face[ keys[ j ] ];
  20570. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  20571. edge.sort( sortFunction );
  20572. var key = edge.toString();
  20573. if ( hash[ key ] === undefined ) {
  20574. edges[ 2 * numEdges ] = edge[ 0 ];
  20575. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20576. hash[ key ] = true;
  20577. numEdges ++;
  20578. }
  20579. }
  20580. }
  20581. var coords = new Float32Array( numEdges * 2 * 3 );
  20582. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20583. for ( var j = 0; j < 2; j ++ ) {
  20584. var vertex = vertices[ edges [ 2 * i + j ] ];
  20585. var index = 6 * i + 3 * j;
  20586. coords[ index + 0 ] = vertex.x;
  20587. coords[ index + 1 ] = vertex.y;
  20588. coords[ index + 2 ] = vertex.z;
  20589. }
  20590. }
  20591. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20592. } else if ( geometry instanceof THREE.BufferGeometry ) {
  20593. if ( geometry.attributes.index !== undefined ) {
  20594. // Indexed BufferGeometry
  20595. var vertices = geometry.attributes.position;
  20596. var indices = geometry.attributes.index.array;
  20597. var drawcalls = geometry.drawcalls;
  20598. var numEdges = 0;
  20599. if ( drawcalls.length === 0 ) {
  20600. drawcalls = [ { count : indices.length, index : 0, start : 0 } ];
  20601. }
  20602. // allocate maximal size
  20603. var edges = new Uint32Array( 2 * indices.length );
  20604. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  20605. var start = drawcalls[ o ].start;
  20606. var count = drawcalls[ o ].count;
  20607. var index = drawcalls[ o ].index;
  20608. for ( var i = start, il = start + count; i < il; i += 3 ) {
  20609. for ( var j = 0; j < 3; j ++ ) {
  20610. edge[ 0 ] = index + indices[ i + j ];
  20611. edge[ 1 ] = index + indices[ i + ( j + 1 ) % 3 ];
  20612. edge.sort( sortFunction );
  20613. var key = edge.toString();
  20614. if ( hash[ key ] === undefined ) {
  20615. edges[ 2 * numEdges ] = edge[ 0 ];
  20616. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20617. hash[ key ] = true;
  20618. numEdges ++;
  20619. }
  20620. }
  20621. }
  20622. }
  20623. var coords = new Float32Array( numEdges * 2 * 3 );
  20624. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20625. for ( var j = 0; j < 2; j ++ ) {
  20626. var index = 6 * i + 3 * j;
  20627. var index2 = edges[ 2 * i + j ];
  20628. coords[ index + 0 ] = vertices.getX( index2 );
  20629. coords[ index + 1 ] = vertices.getY( index2 );
  20630. coords[ index + 2 ] = vertices.getZ( index2 );
  20631. }
  20632. }
  20633. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20634. } else {
  20635. // non-indexed BufferGeometry
  20636. var vertices = geometry.attributes.position.array;
  20637. var numEdges = vertices.length / 3;
  20638. var numTris = numEdges / 3;
  20639. var coords = new Float32Array( numEdges * 2 * 3 );
  20640. for ( var i = 0, l = numTris; i < l; i ++ ) {
  20641. for ( var j = 0; j < 3; j ++ ) {
  20642. var index = 18 * i + 6 * j;
  20643. var index1 = 9 * i + 3 * j;
  20644. coords[ index + 0 ] = vertices[ index1 ];
  20645. coords[ index + 1 ] = vertices[ index1 + 1 ];
  20646. coords[ index + 2 ] = vertices[ index1 + 2 ];
  20647. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  20648. coords[ index + 3 ] = vertices[ index2 ];
  20649. coords[ index + 4 ] = vertices[ index2 + 1 ];
  20650. coords[ index + 5 ] = vertices[ index2 + 2 ];
  20651. }
  20652. }
  20653. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20654. }
  20655. }
  20656. };
  20657. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20658. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  20659. // File:src/extras/helpers/AxisHelper.js
  20660. /**
  20661. * @author sroucheray / http://sroucheray.org/
  20662. * @author mrdoob / http://mrdoob.com/
  20663. */
  20664. THREE.AxisHelper = function ( size ) {
  20665. size = size || 1;
  20666. var vertices = new Float32Array( [
  20667. 0, 0, 0, size, 0, 0,
  20668. 0, 0, 0, 0, size, 0,
  20669. 0, 0, 0, 0, 0, size
  20670. ] );
  20671. var colors = new Float32Array( [
  20672. 1, 0, 0, 1, 0.6, 0,
  20673. 0, 1, 0, 0.6, 1, 0,
  20674. 0, 0, 1, 0, 0.6, 1
  20675. ] );
  20676. var geometry = new THREE.BufferGeometry();
  20677. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  20678. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  20679. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20680. THREE.LineSegments.call( this, geometry, material );
  20681. };
  20682. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20683. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  20684. // File:src/extras/helpers/ArrowHelper.js
  20685. /**
  20686. * @author WestLangley / http://github.com/WestLangley
  20687. * @author zz85 / http://github.com/zz85
  20688. * @author bhouston / http://exocortex.com
  20689. *
  20690. * Creates an arrow for visualizing directions
  20691. *
  20692. * Parameters:
  20693. * dir - Vector3
  20694. * origin - Vector3
  20695. * length - Number
  20696. * color - color in hex value
  20697. * headLength - Number
  20698. * headWidth - Number
  20699. */
  20700. THREE.ArrowHelper = ( function () {
  20701. var lineGeometry = new THREE.Geometry();
  20702. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  20703. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  20704. coneGeometry.translate( 0, - 0.5, 0 );
  20705. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  20706. // dir is assumed to be normalized
  20707. THREE.Object3D.call( this );
  20708. if ( color === undefined ) color = 0xffff00;
  20709. if ( length === undefined ) length = 1;
  20710. if ( headLength === undefined ) headLength = 0.2 * length;
  20711. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20712. this.position.copy( origin );
  20713. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  20714. this.line.matrixAutoUpdate = false;
  20715. this.add( this.line );
  20716. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  20717. this.cone.matrixAutoUpdate = false;
  20718. this.add( this.cone );
  20719. this.setDirection( dir );
  20720. this.setLength( length, headLength, headWidth );
  20721. }
  20722. }() );
  20723. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  20724. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  20725. THREE.ArrowHelper.prototype.setDirection = ( function () {
  20726. var axis = new THREE.Vector3();
  20727. var radians;
  20728. return function setDirection( dir ) {
  20729. // dir is assumed to be normalized
  20730. if ( dir.y > 0.99999 ) {
  20731. this.quaternion.set( 0, 0, 0, 1 );
  20732. } else if ( dir.y < - 0.99999 ) {
  20733. this.quaternion.set( 1, 0, 0, 0 );
  20734. } else {
  20735. axis.set( dir.z, 0, - dir.x ).normalize();
  20736. radians = Math.acos( dir.y );
  20737. this.quaternion.setFromAxisAngle( axis, radians );
  20738. }
  20739. };
  20740. }() );
  20741. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  20742. if ( headLength === undefined ) headLength = 0.2 * length;
  20743. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20744. this.line.scale.set( 1, length - headLength, 1 );
  20745. this.line.updateMatrix();
  20746. this.cone.scale.set( headWidth, headLength, headWidth );
  20747. this.cone.position.y = length;
  20748. this.cone.updateMatrix();
  20749. };
  20750. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  20751. this.line.material.color.set( color );
  20752. this.cone.material.color.set( color );
  20753. };
  20754. // File:src/extras/helpers/BoxHelper.js
  20755. /**
  20756. * @author mrdoob / http://mrdoob.com/
  20757. */
  20758. THREE.BoxHelper = function ( object ) {
  20759. var geometry = new THREE.BufferGeometry();
  20760. geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( 72 ), 3 ) );
  20761. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  20762. if ( object !== undefined ) {
  20763. this.update( object );
  20764. }
  20765. };
  20766. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20767. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  20768. THREE.BoxHelper.prototype.update = ( function () {
  20769. var box = new THREE.Box3();
  20770. return function ( object ) {
  20771. box.setFromObject( object );
  20772. if ( box.empty() ) return;
  20773. var min = box.min;
  20774. var max = box.max;
  20775. /*
  20776. 5____4
  20777. 1/___0/|
  20778. | 6__|_7
  20779. 2/___3/
  20780. 0: max.x, max.y, max.z
  20781. 1: min.x, max.y, max.z
  20782. 2: min.x, min.y, max.z
  20783. 3: max.x, min.y, max.z
  20784. 4: max.x, max.y, min.z
  20785. 5: min.x, max.y, min.z
  20786. 6: min.x, min.y, min.z
  20787. 7: max.x, min.y, min.z
  20788. */
  20789. var vertices = this.geometry.attributes.position.array;
  20790. vertices[ 0 ] = max.x; vertices[ 1 ] = max.y; vertices[ 2 ] = max.z;
  20791. vertices[ 3 ] = min.x; vertices[ 4 ] = max.y; vertices[ 5 ] = max.z;
  20792. vertices[ 6 ] = min.x; vertices[ 7 ] = max.y; vertices[ 8 ] = max.z;
  20793. vertices[ 9 ] = min.x; vertices[ 10 ] = min.y; vertices[ 11 ] = max.z;
  20794. vertices[ 12 ] = min.x; vertices[ 13 ] = min.y; vertices[ 14 ] = max.z;
  20795. vertices[ 15 ] = max.x; vertices[ 16 ] = min.y; vertices[ 17 ] = max.z;
  20796. vertices[ 18 ] = max.x; vertices[ 19 ] = min.y; vertices[ 20 ] = max.z;
  20797. vertices[ 21 ] = max.x; vertices[ 22 ] = max.y; vertices[ 23 ] = max.z;
  20798. //
  20799. vertices[ 24 ] = max.x; vertices[ 25 ] = max.y; vertices[ 26 ] = min.z;
  20800. vertices[ 27 ] = min.x; vertices[ 28 ] = max.y; vertices[ 29 ] = min.z;
  20801. vertices[ 30 ] = min.x; vertices[ 31 ] = max.y; vertices[ 32 ] = min.z;
  20802. vertices[ 33 ] = min.x; vertices[ 34 ] = min.y; vertices[ 35 ] = min.z;
  20803. vertices[ 36 ] = min.x; vertices[ 37 ] = min.y; vertices[ 38 ] = min.z;
  20804. vertices[ 39 ] = max.x; vertices[ 40 ] = min.y; vertices[ 41 ] = min.z;
  20805. vertices[ 42 ] = max.x; vertices[ 43 ] = min.y; vertices[ 44 ] = min.z;
  20806. vertices[ 45 ] = max.x; vertices[ 46 ] = max.y; vertices[ 47 ] = min.z;
  20807. //
  20808. vertices[ 48 ] = max.x; vertices[ 49 ] = max.y; vertices[ 50 ] = max.z;
  20809. vertices[ 51 ] = max.x; vertices[ 52 ] = max.y; vertices[ 53 ] = min.z;
  20810. vertices[ 54 ] = min.x; vertices[ 55 ] = max.y; vertices[ 56 ] = max.z;
  20811. vertices[ 57 ] = min.x; vertices[ 58 ] = max.y; vertices[ 59 ] = min.z;
  20812. vertices[ 60 ] = min.x; vertices[ 61 ] = min.y; vertices[ 62 ] = max.z;
  20813. vertices[ 63 ] = min.x; vertices[ 64 ] = min.y; vertices[ 65 ] = min.z;
  20814. vertices[ 66 ] = max.x; vertices[ 67 ] = min.y; vertices[ 68 ] = max.z;
  20815. vertices[ 69 ] = max.x; vertices[ 70 ] = min.y; vertices[ 71 ] = min.z;
  20816. this.geometry.attributes.position.needsUpdate = true;
  20817. this.geometry.computeBoundingSphere();
  20818. }
  20819. } )();
  20820. // File:src/extras/helpers/BoundingBoxHelper.js
  20821. /**
  20822. * @author WestLangley / http://github.com/WestLangley
  20823. */
  20824. // a helper to show the world-axis-aligned bounding box for an object
  20825. THREE.BoundingBoxHelper = function ( object, hex ) {
  20826. var color = ( hex !== undefined ) ? hex : 0x888888;
  20827. this.object = object;
  20828. this.box = new THREE.Box3();
  20829. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  20830. };
  20831. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  20832. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  20833. THREE.BoundingBoxHelper.prototype.update = function () {
  20834. this.box.setFromObject( this.object );
  20835. this.box.size( this.scale );
  20836. this.box.center( this.position );
  20837. };
  20838. // File:src/extras/helpers/CameraHelper.js
  20839. /**
  20840. * @author alteredq / http://alteredqualia.com/
  20841. *
  20842. * - shows frustum, line of sight and up of the camera
  20843. * - suitable for fast updates
  20844. * - based on frustum visualization in lightgl.js shadowmap example
  20845. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  20846. */
  20847. THREE.CameraHelper = function ( camera ) {
  20848. var geometry = new THREE.Geometry();
  20849. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  20850. var pointMap = {};
  20851. // colors
  20852. var hexFrustum = 0xffaa00;
  20853. var hexCone = 0xff0000;
  20854. var hexUp = 0x00aaff;
  20855. var hexTarget = 0xffffff;
  20856. var hexCross = 0x333333;
  20857. // near
  20858. addLine( "n1", "n2", hexFrustum );
  20859. addLine( "n2", "n4", hexFrustum );
  20860. addLine( "n4", "n3", hexFrustum );
  20861. addLine( "n3", "n1", hexFrustum );
  20862. // far
  20863. addLine( "f1", "f2", hexFrustum );
  20864. addLine( "f2", "f4", hexFrustum );
  20865. addLine( "f4", "f3", hexFrustum );
  20866. addLine( "f3", "f1", hexFrustum );
  20867. // sides
  20868. addLine( "n1", "f1", hexFrustum );
  20869. addLine( "n2", "f2", hexFrustum );
  20870. addLine( "n3", "f3", hexFrustum );
  20871. addLine( "n4", "f4", hexFrustum );
  20872. // cone
  20873. addLine( "p", "n1", hexCone );
  20874. addLine( "p", "n2", hexCone );
  20875. addLine( "p", "n3", hexCone );
  20876. addLine( "p", "n4", hexCone );
  20877. // up
  20878. addLine( "u1", "u2", hexUp );
  20879. addLine( "u2", "u3", hexUp );
  20880. addLine( "u3", "u1", hexUp );
  20881. // target
  20882. addLine( "c", "t", hexTarget );
  20883. addLine( "p", "c", hexCross );
  20884. // cross
  20885. addLine( "cn1", "cn2", hexCross );
  20886. addLine( "cn3", "cn4", hexCross );
  20887. addLine( "cf1", "cf2", hexCross );
  20888. addLine( "cf3", "cf4", hexCross );
  20889. function addLine( a, b, hex ) {
  20890. addPoint( a, hex );
  20891. addPoint( b, hex );
  20892. }
  20893. function addPoint( id, hex ) {
  20894. geometry.vertices.push( new THREE.Vector3() );
  20895. geometry.colors.push( new THREE.Color( hex ) );
  20896. if ( pointMap[ id ] === undefined ) {
  20897. pointMap[ id ] = [];
  20898. }
  20899. pointMap[ id ].push( geometry.vertices.length - 1 );
  20900. }
  20901. THREE.LineSegments.call( this, geometry, material );
  20902. this.camera = camera;
  20903. this.matrix = camera.matrixWorld;
  20904. this.matrixAutoUpdate = false;
  20905. this.pointMap = pointMap;
  20906. this.update();
  20907. };
  20908. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20909. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  20910. THREE.CameraHelper.prototype.update = function () {
  20911. var geometry, pointMap;
  20912. var vector = new THREE.Vector3();
  20913. var camera = new THREE.Camera();
  20914. var setPoint = function ( point, x, y, z ) {
  20915. vector.set( x, y, z ).unproject( camera );
  20916. var points = pointMap[ point ];
  20917. if ( points !== undefined ) {
  20918. for ( var i = 0, il = points.length; i < il; i ++ ) {
  20919. geometry.vertices[ points[ i ] ].copy( vector );
  20920. }
  20921. }
  20922. };
  20923. return function () {
  20924. geometry = this.geometry;
  20925. pointMap = this.pointMap;
  20926. var w = 1, h = 1;
  20927. // we need just camera projection matrix
  20928. // world matrix must be identity
  20929. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  20930. // center / target
  20931. setPoint( "c", 0, 0, - 1 );
  20932. setPoint( "t", 0, 0, 1 );
  20933. // near
  20934. setPoint( "n1", - w, - h, - 1 );
  20935. setPoint( "n2", w, - h, - 1 );
  20936. setPoint( "n3", - w, h, - 1 );
  20937. setPoint( "n4", w, h, - 1 );
  20938. // far
  20939. setPoint( "f1", - w, - h, 1 );
  20940. setPoint( "f2", w, - h, 1 );
  20941. setPoint( "f3", - w, h, 1 );
  20942. setPoint( "f4", w, h, 1 );
  20943. // up
  20944. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  20945. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  20946. setPoint( "u3", 0, h * 2, - 1 );
  20947. // cross
  20948. setPoint( "cf1", - w, 0, 1 );
  20949. setPoint( "cf2", w, 0, 1 );
  20950. setPoint( "cf3", 0, - h, 1 );
  20951. setPoint( "cf4", 0, h, 1 );
  20952. setPoint( "cn1", - w, 0, - 1 );
  20953. setPoint( "cn2", w, 0, - 1 );
  20954. setPoint( "cn3", 0, - h, - 1 );
  20955. setPoint( "cn4", 0, h, - 1 );
  20956. geometry.verticesNeedUpdate = true;
  20957. };
  20958. }();
  20959. // File:src/extras/helpers/DirectionalLightHelper.js
  20960. /**
  20961. * @author alteredq / http://alteredqualia.com/
  20962. * @author mrdoob / http://mrdoob.com/
  20963. * @author WestLangley / http://github.com/WestLangley
  20964. */
  20965. THREE.DirectionalLightHelper = function ( light, size ) {
  20966. THREE.Object3D.call( this );
  20967. this.light = light;
  20968. this.light.updateMatrixWorld();
  20969. this.matrix = light.matrixWorld;
  20970. this.matrixAutoUpdate = false;
  20971. size = size || 1;
  20972. var geometry = new THREE.Geometry();
  20973. geometry.vertices.push(
  20974. new THREE.Vector3( - size, size, 0 ),
  20975. new THREE.Vector3( size, size, 0 ),
  20976. new THREE.Vector3( size, - size, 0 ),
  20977. new THREE.Vector3( - size, - size, 0 ),
  20978. new THREE.Vector3( - size, size, 0 )
  20979. );
  20980. var material = new THREE.LineBasicMaterial( { fog: false } );
  20981. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20982. this.lightPlane = new THREE.Line( geometry, material );
  20983. this.add( this.lightPlane );
  20984. geometry = new THREE.Geometry();
  20985. geometry.vertices.push(
  20986. new THREE.Vector3(),
  20987. new THREE.Vector3()
  20988. );
  20989. material = new THREE.LineBasicMaterial( { fog: false } );
  20990. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20991. this.targetLine = new THREE.Line( geometry, material );
  20992. this.add( this.targetLine );
  20993. this.update();
  20994. };
  20995. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20996. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  20997. THREE.DirectionalLightHelper.prototype.dispose = function () {
  20998. this.lightPlane.geometry.dispose();
  20999. this.lightPlane.material.dispose();
  21000. this.targetLine.geometry.dispose();
  21001. this.targetLine.material.dispose();
  21002. };
  21003. THREE.DirectionalLightHelper.prototype.update = function () {
  21004. var v1 = new THREE.Vector3();
  21005. var v2 = new THREE.Vector3();
  21006. var v3 = new THREE.Vector3();
  21007. return function () {
  21008. v1.setFromMatrixPosition( this.light.matrixWorld );
  21009. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  21010. v3.subVectors( v2, v1 );
  21011. this.lightPlane.lookAt( v3 );
  21012. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21013. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  21014. this.targetLine.geometry.verticesNeedUpdate = true;
  21015. this.targetLine.material.color.copy( this.lightPlane.material.color );
  21016. };
  21017. }();
  21018. // File:src/extras/helpers/EdgesHelper.js
  21019. /**
  21020. * @author WestLangley / http://github.com/WestLangley
  21021. * @param object THREE.Mesh whose geometry will be used
  21022. * @param hex line color
  21023. * @param thresholdAngle the minimum angle (in degrees),
  21024. * between the face normals of adjacent faces,
  21025. * that is required to render an edge. A value of 10 means
  21026. * an edge is only rendered if the angle is at least 10 degrees.
  21027. */
  21028. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  21029. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21030. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  21031. this.matrix = object.matrixWorld;
  21032. this.matrixAutoUpdate = false;
  21033. };
  21034. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21035. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  21036. // File:src/extras/helpers/FaceNormalsHelper.js
  21037. /**
  21038. * @author mrdoob / http://mrdoob.com/
  21039. * @author WestLangley / http://github.com/WestLangley
  21040. */
  21041. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  21042. // FaceNormalsHelper only supports THREE.Geometry
  21043. this.object = object;
  21044. this.size = ( size !== undefined ) ? size : 1;
  21045. var color = ( hex !== undefined ) ? hex : 0xffff00;
  21046. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21047. //
  21048. var nNormals = 0;
  21049. var objGeometry = this.object.geometry;
  21050. if ( objGeometry instanceof THREE.Geometry ) {
  21051. nNormals = objGeometry.faces.length;
  21052. } else {
  21053. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  21054. }
  21055. //
  21056. var geometry = new THREE.BufferGeometry();
  21057. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21058. geometry.addAttribute( 'position', positions );
  21059. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21060. //
  21061. this.matrixAutoUpdate = false;
  21062. this.normalMatrix = new THREE.Matrix3();
  21063. this.update();
  21064. };
  21065. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21066. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  21067. THREE.FaceNormalsHelper.prototype.update = ( function () {
  21068. var v1 = new THREE.Vector3();
  21069. var v2 = new THREE.Vector3();
  21070. return function update() {
  21071. this.object.updateMatrixWorld( true );
  21072. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21073. var matrixWorld = this.object.matrixWorld;
  21074. var position = this.geometry.attributes.position;
  21075. //
  21076. var objGeometry = this.object.geometry;
  21077. var vertices = objGeometry.vertices;
  21078. var faces = objGeometry.faces;
  21079. var idx = 0;
  21080. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21081. var face = faces[ i ];
  21082. var normal = face.normal;
  21083. v1.copy( vertices[ face.a ] )
  21084. .add( vertices[ face.b ] )
  21085. .add( vertices[ face.c ] )
  21086. .divideScalar( 3 )
  21087. .applyMatrix4( matrixWorld );
  21088. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21089. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21090. idx = idx + 1;
  21091. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21092. idx = idx + 1;
  21093. }
  21094. position.needsUpdate = true;
  21095. return this;
  21096. }
  21097. }() );
  21098. // File:src/extras/helpers/GridHelper.js
  21099. /**
  21100. * @author mrdoob / http://mrdoob.com/
  21101. */
  21102. THREE.GridHelper = function ( size, step ) {
  21103. var geometry = new THREE.Geometry();
  21104. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  21105. this.color1 = new THREE.Color( 0x444444 );
  21106. this.color2 = new THREE.Color( 0x888888 );
  21107. for ( var i = - size; i <= size; i += step ) {
  21108. geometry.vertices.push(
  21109. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  21110. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  21111. );
  21112. var color = i === 0 ? this.color1 : this.color2;
  21113. geometry.colors.push( color, color, color, color );
  21114. }
  21115. THREE.LineSegments.call( this, geometry, material );
  21116. };
  21117. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21118. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  21119. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  21120. this.color1.set( colorCenterLine );
  21121. this.color2.set( colorGrid );
  21122. this.geometry.colorsNeedUpdate = true;
  21123. };
  21124. // File:src/extras/helpers/HemisphereLightHelper.js
  21125. /**
  21126. * @author alteredq / http://alteredqualia.com/
  21127. * @author mrdoob / http://mrdoob.com/
  21128. */
  21129. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  21130. THREE.Object3D.call( this );
  21131. this.light = light;
  21132. this.light.updateMatrixWorld();
  21133. this.matrix = light.matrixWorld;
  21134. this.matrixAutoUpdate = false;
  21135. this.colors = [ new THREE.Color(), new THREE.Color() ];
  21136. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21137. geometry.rotateX( - Math.PI / 2 );
  21138. for ( var i = 0, il = 8; i < il; i ++ ) {
  21139. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  21140. }
  21141. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  21142. this.lightSphere = new THREE.Mesh( geometry, material );
  21143. this.add( this.lightSphere );
  21144. this.update();
  21145. };
  21146. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21147. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  21148. THREE.HemisphereLightHelper.prototype.dispose = function () {
  21149. this.lightSphere.geometry.dispose();
  21150. this.lightSphere.material.dispose();
  21151. };
  21152. THREE.HemisphereLightHelper.prototype.update = function () {
  21153. var vector = new THREE.Vector3();
  21154. return function () {
  21155. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  21156. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  21157. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  21158. this.lightSphere.geometry.colorsNeedUpdate = true;
  21159. }
  21160. }();
  21161. // File:src/extras/helpers/PointLightHelper.js
  21162. /**
  21163. * @author alteredq / http://alteredqualia.com/
  21164. * @author mrdoob / http://mrdoob.com/
  21165. */
  21166. THREE.PointLightHelper = function ( light, sphereSize ) {
  21167. this.light = light;
  21168. this.light.updateMatrixWorld();
  21169. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21170. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21171. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21172. THREE.Mesh.call( this, geometry, material );
  21173. this.matrix = this.light.matrixWorld;
  21174. this.matrixAutoUpdate = false;
  21175. /*
  21176. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  21177. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  21178. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  21179. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  21180. var d = light.distance;
  21181. if ( d === 0.0 ) {
  21182. this.lightDistance.visible = false;
  21183. } else {
  21184. this.lightDistance.scale.set( d, d, d );
  21185. }
  21186. this.add( this.lightDistance );
  21187. */
  21188. };
  21189. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  21190. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  21191. THREE.PointLightHelper.prototype.dispose = function () {
  21192. this.geometry.dispose();
  21193. this.material.dispose();
  21194. };
  21195. THREE.PointLightHelper.prototype.update = function () {
  21196. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21197. /*
  21198. var d = this.light.distance;
  21199. if ( d === 0.0 ) {
  21200. this.lightDistance.visible = false;
  21201. } else {
  21202. this.lightDistance.visible = true;
  21203. this.lightDistance.scale.set( d, d, d );
  21204. }
  21205. */
  21206. };
  21207. // File:src/extras/helpers/SkeletonHelper.js
  21208. /**
  21209. * @author Sean Griffin / http://twitter.com/sgrif
  21210. * @author Michael Guerrero / http://realitymeltdown.com
  21211. * @author mrdoob / http://mrdoob.com/
  21212. * @author ikerr / http://verold.com
  21213. */
  21214. THREE.SkeletonHelper = function ( object ) {
  21215. this.bones = this.getBoneList( object );
  21216. var geometry = new THREE.Geometry();
  21217. for ( var i = 0; i < this.bones.length; i ++ ) {
  21218. var bone = this.bones[ i ];
  21219. if ( bone.parent instanceof THREE.Bone ) {
  21220. geometry.vertices.push( new THREE.Vector3() );
  21221. geometry.vertices.push( new THREE.Vector3() );
  21222. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  21223. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  21224. }
  21225. }
  21226. geometry.dynamic = true;
  21227. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  21228. THREE.LineSegments.call( this, geometry, material );
  21229. this.root = object;
  21230. this.matrix = object.matrixWorld;
  21231. this.matrixAutoUpdate = false;
  21232. this.update();
  21233. };
  21234. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21235. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  21236. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  21237. var boneList = [];
  21238. if ( object instanceof THREE.Bone ) {
  21239. boneList.push( object );
  21240. }
  21241. for ( var i = 0; i < object.children.length; i ++ ) {
  21242. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  21243. }
  21244. return boneList;
  21245. };
  21246. THREE.SkeletonHelper.prototype.update = function () {
  21247. var geometry = this.geometry;
  21248. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  21249. var boneMatrix = new THREE.Matrix4();
  21250. var j = 0;
  21251. for ( var i = 0; i < this.bones.length; i ++ ) {
  21252. var bone = this.bones[ i ];
  21253. if ( bone.parent instanceof THREE.Bone ) {
  21254. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  21255. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  21256. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  21257. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  21258. j += 2;
  21259. }
  21260. }
  21261. geometry.verticesNeedUpdate = true;
  21262. geometry.computeBoundingSphere();
  21263. };
  21264. // File:src/extras/helpers/SpotLightHelper.js
  21265. /**
  21266. * @author alteredq / http://alteredqualia.com/
  21267. * @author mrdoob / http://mrdoob.com/
  21268. * @author WestLangley / http://github.com/WestLangley
  21269. */
  21270. THREE.SpotLightHelper = function ( light ) {
  21271. THREE.Object3D.call( this );
  21272. this.light = light;
  21273. this.light.updateMatrixWorld();
  21274. this.matrix = light.matrixWorld;
  21275. this.matrixAutoUpdate = false;
  21276. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  21277. geometry.translate( 0, - 0.5, 0 );
  21278. geometry.rotateX( - Math.PI / 2 );
  21279. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21280. this.cone = new THREE.Mesh( geometry, material );
  21281. this.add( this.cone );
  21282. this.update();
  21283. };
  21284. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21285. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  21286. THREE.SpotLightHelper.prototype.dispose = function () {
  21287. this.cone.geometry.dispose();
  21288. this.cone.material.dispose();
  21289. };
  21290. THREE.SpotLightHelper.prototype.update = function () {
  21291. var vector = new THREE.Vector3();
  21292. var vector2 = new THREE.Vector3();
  21293. return function () {
  21294. var coneLength = this.light.distance ? this.light.distance : 10000;
  21295. var coneWidth = coneLength * Math.tan( this.light.angle );
  21296. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  21297. vector.setFromMatrixPosition( this.light.matrixWorld );
  21298. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  21299. this.cone.lookAt( vector2.sub( vector ) );
  21300. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21301. };
  21302. }();
  21303. // File:src/extras/helpers/VertexNormalsHelper.js
  21304. /**
  21305. * @author mrdoob / http://mrdoob.com/
  21306. * @author WestLangley / http://github.com/WestLangley
  21307. */
  21308. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  21309. this.object = object;
  21310. this.size = ( size !== undefined ) ? size : 1;
  21311. var color = ( hex !== undefined ) ? hex : 0xff0000;
  21312. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21313. //
  21314. var nNormals = 0;
  21315. var objGeometry = this.object.geometry;
  21316. if ( objGeometry instanceof THREE.Geometry ) {
  21317. nNormals = objGeometry.faces.length * 3;
  21318. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21319. nNormals = objGeometry.attributes.normal.count
  21320. }
  21321. //
  21322. var geometry = new THREE.BufferGeometry();
  21323. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21324. geometry.addAttribute( 'position', positions );
  21325. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21326. //
  21327. this.matrixAutoUpdate = false;
  21328. this.normalMatrix = new THREE.Matrix3();
  21329. this.update();
  21330. };
  21331. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21332. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  21333. THREE.VertexNormalsHelper.prototype.update = ( function () {
  21334. var v1 = new THREE.Vector3();
  21335. var v2 = new THREE.Vector3();
  21336. return function update() {
  21337. var keys = [ 'a', 'b', 'c' ];
  21338. this.object.updateMatrixWorld( true );
  21339. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21340. var matrixWorld = this.object.matrixWorld;
  21341. var position = this.geometry.attributes.position;
  21342. //
  21343. var objGeometry = this.object.geometry;
  21344. if ( objGeometry instanceof THREE.Geometry ) {
  21345. var vertices = objGeometry.vertices;
  21346. var faces = objGeometry.faces;
  21347. var idx = 0;
  21348. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21349. var face = faces[ i ];
  21350. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  21351. var vertex = vertices[ face[ keys[ j ] ] ];
  21352. var normal = face.vertexNormals[ j ];
  21353. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21354. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21355. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21356. idx = idx + 1;
  21357. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21358. idx = idx + 1;
  21359. }
  21360. }
  21361. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21362. var objPos = objGeometry.attributes.position;
  21363. var objNorm = objGeometry.attributes.normal;
  21364. var idx = 0;
  21365. // for simplicity, ignore index and drawcalls, and render every normal
  21366. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21367. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21368. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  21369. v2.applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21370. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21371. idx = idx + 1;
  21372. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21373. idx = idx + 1;
  21374. }
  21375. }
  21376. position.needsUpdate = true;
  21377. return this;
  21378. }
  21379. }() );
  21380. // File:src/extras/helpers/VertexTangentsHelper.js
  21381. /**
  21382. * @author mrdoob / http://mrdoob.com/
  21383. * @author WestLangley / http://github.com/WestLangley
  21384. */
  21385. THREE.VertexTangentsHelper = function ( object, size, hex, linewidth ) {
  21386. this.object = object;
  21387. this.size = ( size !== undefined ) ? size : 1;
  21388. var color = ( hex !== undefined ) ? hex : 0x0000ff;
  21389. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21390. //
  21391. var nTangents = 0;
  21392. var objGeometry = this.object.geometry;
  21393. if ( objGeometry instanceof THREE.Geometry ) {
  21394. nTangents = objGeometry.faces.length * 3;
  21395. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21396. nTangents = objGeometry.attributes.tangent.count
  21397. }
  21398. //
  21399. var geometry = new THREE.BufferGeometry();
  21400. var positions = new THREE.Float32Attribute( nTangents * 2 * 3, 3 );
  21401. geometry.addAttribute( 'position', positions );
  21402. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21403. //
  21404. this.matrixAutoUpdate = false;
  21405. this.update();
  21406. };
  21407. THREE.VertexTangentsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21408. THREE.VertexTangentsHelper.prototype.constructor = THREE.VertexTangentsHelper;
  21409. THREE.VertexTangentsHelper.prototype.update = ( function ( object ) {
  21410. var v1 = new THREE.Vector3();
  21411. var v2 = new THREE.Vector3();
  21412. return function() {
  21413. var keys = [ 'a', 'b', 'c' ];
  21414. this.object.updateMatrixWorld( true );
  21415. var matrixWorld = this.object.matrixWorld;
  21416. var position = this.geometry.attributes.position;
  21417. //
  21418. var objGeometry = this.object.geometry;
  21419. if ( objGeometry instanceof THREE.Geometry ) {
  21420. var vertices = objGeometry.vertices;
  21421. var faces = objGeometry.faces;
  21422. var idx = 0;
  21423. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21424. var face = faces[ i ];
  21425. for ( var j = 0, jl = face.vertexTangents.length; j < jl; j ++ ) {
  21426. var vertex = vertices[ face[ keys[ j ] ] ];
  21427. var tangent = face.vertexTangents[ j ];
  21428. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21429. v2.set( tangent.x, tangent.y, tangent.z ); // tangent.w used for bitangents only
  21430. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  21431. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21432. idx = idx + 1;
  21433. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21434. idx = idx + 1;
  21435. }
  21436. }
  21437. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21438. var objPos = objGeometry.attributes.position;
  21439. var objTan = objGeometry.attributes.tangent;
  21440. var idx = 0;
  21441. // for simplicity, ignore index and drawcalls, and render every tangent
  21442. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21443. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21444. v2.set( objTan.getX( j ), objTan.getY( j ), objTan.getZ( j ) ); // tangent.w used for bitangents only
  21445. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  21446. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21447. idx = idx + 1;
  21448. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21449. idx = idx + 1;
  21450. }
  21451. }
  21452. position.needsUpdate = true;
  21453. return this;
  21454. }
  21455. }() );
  21456. // File:src/extras/helpers/WireframeHelper.js
  21457. /**
  21458. * @author mrdoob / http://mrdoob.com/
  21459. */
  21460. THREE.WireframeHelper = function ( object, hex ) {
  21461. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21462. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  21463. this.matrix = object.matrixWorld;
  21464. this.matrixAutoUpdate = false;
  21465. };
  21466. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21467. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  21468. // File:src/extras/objects/ImmediateRenderObject.js
  21469. /**
  21470. * @author alteredq / http://alteredqualia.com/
  21471. */
  21472. THREE.ImmediateRenderObject = function () {
  21473. THREE.Object3D.call( this );
  21474. this.render = function ( renderCallback ) {};
  21475. };
  21476. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  21477. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  21478. // File:src/extras/objects/MorphBlendMesh.js
  21479. /**
  21480. * @author alteredq / http://alteredqualia.com/
  21481. */
  21482. THREE.MorphBlendMesh = function( geometry, material ) {
  21483. THREE.Mesh.call( this, geometry, material );
  21484. this.animationsMap = {};
  21485. this.animationsList = [];
  21486. // prepare default animation
  21487. // (all frames played together in 1 second)
  21488. var numFrames = this.geometry.morphTargets.length;
  21489. var name = "__default";
  21490. var startFrame = 0;
  21491. var endFrame = numFrames - 1;
  21492. var fps = numFrames / 1;
  21493. this.createAnimation( name, startFrame, endFrame, fps );
  21494. this.setAnimationWeight( name, 1 );
  21495. };
  21496. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  21497. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21498. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21499. var animation = {
  21500. startFrame: start,
  21501. endFrame: end,
  21502. length: end - start + 1,
  21503. fps: fps,
  21504. duration: ( end - start ) / fps,
  21505. lastFrame: 0,
  21506. currentFrame: 0,
  21507. active: false,
  21508. time: 0,
  21509. direction: 1,
  21510. weight: 1,
  21511. directionBackwards: false,
  21512. mirroredLoop: false
  21513. };
  21514. this.animationsMap[ name ] = animation;
  21515. this.animationsList.push( animation );
  21516. };
  21517. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21518. var pattern = /([a-z]+)_?(\d+)/;
  21519. var firstAnimation, frameRanges = {};
  21520. var geometry = this.geometry;
  21521. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21522. var morph = geometry.morphTargets[ i ];
  21523. var chunks = morph.name.match( pattern );
  21524. if ( chunks && chunks.length > 1 ) {
  21525. var name = chunks[ 1 ];
  21526. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  21527. var range = frameRanges[ name ];
  21528. if ( i < range.start ) range.start = i;
  21529. if ( i > range.end ) range.end = i;
  21530. if ( ! firstAnimation ) firstAnimation = name;
  21531. }
  21532. }
  21533. for ( var name in frameRanges ) {
  21534. var range = frameRanges[ name ];
  21535. this.createAnimation( name, range.start, range.end, fps );
  21536. }
  21537. this.firstAnimation = firstAnimation;
  21538. };
  21539. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21540. var animation = this.animationsMap[ name ];
  21541. if ( animation ) {
  21542. animation.direction = 1;
  21543. animation.directionBackwards = false;
  21544. }
  21545. };
  21546. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21547. var animation = this.animationsMap[ name ];
  21548. if ( animation ) {
  21549. animation.direction = - 1;
  21550. animation.directionBackwards = true;
  21551. }
  21552. };
  21553. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21554. var animation = this.animationsMap[ name ];
  21555. if ( animation ) {
  21556. animation.fps = fps;
  21557. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21558. }
  21559. };
  21560. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21561. var animation = this.animationsMap[ name ];
  21562. if ( animation ) {
  21563. animation.duration = duration;
  21564. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21565. }
  21566. };
  21567. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21568. var animation = this.animationsMap[ name ];
  21569. if ( animation ) {
  21570. animation.weight = weight;
  21571. }
  21572. };
  21573. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  21574. var animation = this.animationsMap[ name ];
  21575. if ( animation ) {
  21576. animation.time = time;
  21577. }
  21578. };
  21579. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  21580. var time = 0;
  21581. var animation = this.animationsMap[ name ];
  21582. if ( animation ) {
  21583. time = animation.time;
  21584. }
  21585. return time;
  21586. };
  21587. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  21588. var duration = - 1;
  21589. var animation = this.animationsMap[ name ];
  21590. if ( animation ) {
  21591. duration = animation.duration;
  21592. }
  21593. return duration;
  21594. };
  21595. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  21596. var animation = this.animationsMap[ name ];
  21597. if ( animation ) {
  21598. animation.time = 0;
  21599. animation.active = true;
  21600. } else {
  21601. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  21602. }
  21603. };
  21604. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  21605. var animation = this.animationsMap[ name ];
  21606. if ( animation ) {
  21607. animation.active = false;
  21608. }
  21609. };
  21610. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  21611. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  21612. var animation = this.animationsList[ i ];
  21613. if ( ! animation.active ) continue;
  21614. var frameTime = animation.duration / animation.length;
  21615. animation.time += animation.direction * delta;
  21616. if ( animation.mirroredLoop ) {
  21617. if ( animation.time > animation.duration || animation.time < 0 ) {
  21618. animation.direction *= - 1;
  21619. if ( animation.time > animation.duration ) {
  21620. animation.time = animation.duration;
  21621. animation.directionBackwards = true;
  21622. }
  21623. if ( animation.time < 0 ) {
  21624. animation.time = 0;
  21625. animation.directionBackwards = false;
  21626. }
  21627. }
  21628. } else {
  21629. animation.time = animation.time % animation.duration;
  21630. if ( animation.time < 0 ) animation.time += animation.duration;
  21631. }
  21632. var keyframe = animation.startFrame + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  21633. var weight = animation.weight;
  21634. if ( keyframe !== animation.currentFrame ) {
  21635. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  21636. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  21637. this.morphTargetInfluences[ keyframe ] = 0;
  21638. animation.lastFrame = animation.currentFrame;
  21639. animation.currentFrame = keyframe;
  21640. }
  21641. var mix = ( animation.time % frameTime ) / frameTime;
  21642. if ( animation.directionBackwards ) mix = 1 - mix;
  21643. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  21644. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  21645. }
  21646. };