three.js 813 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '73dev' };
  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. if ( self.requestAnimationFrame === undefined || self.cancelAnimationFrame === undefined ) {
  14. // Missing in Android stock browser.
  15. ( function () {
  16. var lastTime = 0;
  17. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  18. for ( var x = 0; x < vendors.length && ! self.requestAnimationFrame; ++ x ) {
  19. self.requestAnimationFrame = self[ vendors[ x ] + 'RequestAnimationFrame' ];
  20. self.cancelAnimationFrame = self[ vendors[ x ] + 'CancelAnimationFrame' ] || self[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  21. }
  22. if ( self.requestAnimationFrame === undefined && self.setTimeout !== undefined ) {
  23. self.requestAnimationFrame = function ( callback ) {
  24. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  25. var id = self.setTimeout( function () {
  26. callback( currTime + timeToCall );
  27. }, timeToCall );
  28. lastTime = currTime + timeToCall;
  29. return id;
  30. };
  31. }
  32. if ( self.cancelAnimationFrame === undefined && self.clearTimeout !== undefined ) {
  33. self.cancelAnimationFrame = function ( id ) {
  34. self.clearTimeout( id );
  35. };
  36. }
  37. }() );
  38. }
  39. if ( Math.sign === undefined ) {
  40. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  41. Math.sign = function ( x ) {
  42. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  43. };
  44. }
  45. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  46. // Missing in IE9-11.
  47. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  48. Object.defineProperty( Function.prototype, 'name', {
  49. get: function () {
  50. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  51. }
  52. } );
  53. }
  54. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  55. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  56. // GL STATE CONSTANTS
  57. THREE.CullFaceNone = 0;
  58. THREE.CullFaceBack = 1;
  59. THREE.CullFaceFront = 2;
  60. THREE.CullFaceFrontBack = 3;
  61. THREE.FrontFaceDirectionCW = 0;
  62. THREE.FrontFaceDirectionCCW = 1;
  63. // SHADOWING TYPES
  64. THREE.BasicShadowMap = 0;
  65. THREE.PCFShadowMap = 1;
  66. THREE.PCFSoftShadowMap = 2;
  67. // MATERIAL CONSTANTS
  68. // side
  69. THREE.FrontSide = 0;
  70. THREE.BackSide = 1;
  71. THREE.DoubleSide = 2;
  72. // shading
  73. THREE.FlatShading = 1;
  74. THREE.SmoothShading = 2;
  75. // colors
  76. THREE.NoColors = 0;
  77. THREE.FaceColors = 1;
  78. THREE.VertexColors = 2;
  79. // blending modes
  80. THREE.NoBlending = 0;
  81. THREE.NormalBlending = 1;
  82. THREE.AdditiveBlending = 2;
  83. THREE.SubtractiveBlending = 3;
  84. THREE.MultiplyBlending = 4;
  85. THREE.CustomBlending = 5;
  86. // custom blending equations
  87. // (numbers start from 100 not to clash with other
  88. // mappings to OpenGL constants defined in Texture.js)
  89. THREE.AddEquation = 100;
  90. THREE.SubtractEquation = 101;
  91. THREE.ReverseSubtractEquation = 102;
  92. THREE.MinEquation = 103;
  93. THREE.MaxEquation = 104;
  94. // custom blending destination factors
  95. THREE.ZeroFactor = 200;
  96. THREE.OneFactor = 201;
  97. THREE.SrcColorFactor = 202;
  98. THREE.OneMinusSrcColorFactor = 203;
  99. THREE.SrcAlphaFactor = 204;
  100. THREE.OneMinusSrcAlphaFactor = 205;
  101. THREE.DstAlphaFactor = 206;
  102. THREE.OneMinusDstAlphaFactor = 207;
  103. // custom blending source factors
  104. //THREE.ZeroFactor = 200;
  105. //THREE.OneFactor = 201;
  106. //THREE.SrcAlphaFactor = 204;
  107. //THREE.OneMinusSrcAlphaFactor = 205;
  108. //THREE.DstAlphaFactor = 206;
  109. //THREE.OneMinusDstAlphaFactor = 207;
  110. THREE.DstColorFactor = 208;
  111. THREE.OneMinusDstColorFactor = 209;
  112. THREE.SrcAlphaSaturateFactor = 210;
  113. // depth modes
  114. THREE.NeverDepth = 0;
  115. THREE.AlwaysDepth = 1;
  116. THREE.LessDepth = 2;
  117. THREE.LessEqualDepth = 3;
  118. THREE.EqualDepth = 4;
  119. THREE.GreaterEqualDepth = 5;
  120. THREE.GreaterDepth = 6;
  121. THREE.NotEqualDepth = 7;
  122. // TEXTURE CONSTANTS
  123. THREE.MultiplyOperation = 0;
  124. THREE.MixOperation = 1;
  125. THREE.AddOperation = 2;
  126. // Mapping modes
  127. THREE.UVMapping = 300;
  128. THREE.CubeReflectionMapping = 301;
  129. THREE.CubeRefractionMapping = 302;
  130. THREE.EquirectangularReflectionMapping = 303;
  131. THREE.EquirectangularRefractionMapping = 304;
  132. THREE.SphericalReflectionMapping = 305;
  133. // Wrapping modes
  134. THREE.RepeatWrapping = 1000;
  135. THREE.ClampToEdgeWrapping = 1001;
  136. THREE.MirroredRepeatWrapping = 1002;
  137. // Filters
  138. THREE.NearestFilter = 1003;
  139. THREE.NearestMipMapNearestFilter = 1004;
  140. THREE.NearestMipMapLinearFilter = 1005;
  141. THREE.LinearFilter = 1006;
  142. THREE.LinearMipMapNearestFilter = 1007;
  143. THREE.LinearMipMapLinearFilter = 1008;
  144. // Data types
  145. THREE.UnsignedByteType = 1009;
  146. THREE.ByteType = 1010;
  147. THREE.ShortType = 1011;
  148. THREE.UnsignedShortType = 1012;
  149. THREE.IntType = 1013;
  150. THREE.UnsignedIntType = 1014;
  151. THREE.FloatType = 1015;
  152. THREE.HalfFloatType = 1025;
  153. // Pixel types
  154. //THREE.UnsignedByteType = 1009;
  155. THREE.UnsignedShort4444Type = 1016;
  156. THREE.UnsignedShort5551Type = 1017;
  157. THREE.UnsignedShort565Type = 1018;
  158. // Pixel formats
  159. THREE.AlphaFormat = 1019;
  160. THREE.RGBFormat = 1020;
  161. THREE.RGBAFormat = 1021;
  162. THREE.LuminanceFormat = 1022;
  163. THREE.LuminanceAlphaFormat = 1023;
  164. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  165. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  166. // DDS / ST3C Compressed texture formats
  167. THREE.RGB_S3TC_DXT1_Format = 2001;
  168. THREE.RGBA_S3TC_DXT1_Format = 2002;
  169. THREE.RGBA_S3TC_DXT3_Format = 2003;
  170. THREE.RGBA_S3TC_DXT5_Format = 2004;
  171. // PVRTC compressed texture formats
  172. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  173. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  174. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  175. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  176. // Loop styles for AnimationAction
  177. THREE.LoopOnce = 2200;
  178. THREE.LoopRepeat = 2201;
  179. THREE.LoopPingPong = 2202;
  180. // DEPRECATED
  181. THREE.Projector = function () {
  182. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  183. this.projectVector = function ( vector, camera ) {
  184. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  185. vector.project( camera );
  186. };
  187. this.unprojectVector = function ( vector, camera ) {
  188. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  189. vector.unproject( camera );
  190. };
  191. this.pickingRay = function ( vector, camera ) {
  192. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  193. };
  194. };
  195. THREE.CanvasRenderer = function () {
  196. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  197. this.domElement = document.createElement( 'canvas' );
  198. this.clear = function () {};
  199. this.render = function () {};
  200. this.setClearColor = function () {};
  201. this.setSize = function () {};
  202. };
  203. // File:src/math/Color.js
  204. /**
  205. * @author mrdoob / http://mrdoob.com/
  206. */
  207. THREE.Color = function ( color ) {
  208. if ( arguments.length === 3 ) {
  209. return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
  210. }
  211. return this.set( color );
  212. };
  213. THREE.Color.prototype = {
  214. constructor: THREE.Color,
  215. r: 1, g: 1, b: 1,
  216. set: function ( value ) {
  217. if ( value instanceof THREE.Color ) {
  218. this.copy( value );
  219. } else if ( typeof value === 'number' ) {
  220. this.setHex( value );
  221. } else if ( typeof value === 'string' ) {
  222. this.setStyle( value );
  223. }
  224. return this;
  225. },
  226. setHex: function ( hex ) {
  227. hex = Math.floor( hex );
  228. this.r = ( hex >> 16 & 255 ) / 255;
  229. this.g = ( hex >> 8 & 255 ) / 255;
  230. this.b = ( hex & 255 ) / 255;
  231. return this;
  232. },
  233. setRGB: function ( r, g, b ) {
  234. this.r = r;
  235. this.g = g;
  236. this.b = b;
  237. return this;
  238. },
  239. setHSL: function () {
  240. function hue2rgb ( p, q, t ) {
  241. if ( t < 0 ) t += 1;
  242. if ( t > 1 ) t -= 1;
  243. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  244. if ( t < 1 / 2 ) return q;
  245. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  246. return p;
  247. }
  248. return function ( h, s, l ) {
  249. // h,s,l ranges are in 0.0 - 1.0
  250. h = THREE.Math.euclideanModulo( h, 1 );
  251. s = THREE.Math.clamp( s, 0, 1 );
  252. l = THREE.Math.clamp( l, 0, 1 );
  253. if ( s === 0 ) {
  254. this.r = this.g = this.b = l;
  255. } else {
  256. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  257. var q = ( 2 * l ) - p;
  258. this.r = hue2rgb( q, p, h + 1 / 3 );
  259. this.g = hue2rgb( q, p, h );
  260. this.b = hue2rgb( q, p, h - 1 / 3 );
  261. }
  262. return this;
  263. };
  264. }(),
  265. setStyle: function ( style ) {
  266. var parseAlpha = function ( strAlpha ) {
  267. var alpha = parseFloat( strAlpha );
  268. if ( alpha < 1 ) {
  269. console.warn( 'THREE.Color: Alpha component of color ' + style + ' will be ignored.' );
  270. }
  271. return alpha;
  272. }
  273. var m;
  274. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  275. // rgb / hsl
  276. var color;
  277. var name = m[ 1 ];
  278. var components = m[ 2 ];
  279. switch ( name ) {
  280. case 'rgb':
  281. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*$/.exec( components ) ) {
  282. // rgb(255,0,0)
  283. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  284. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  285. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  286. return this;
  287. }
  288. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  289. // rgb(100%,0%,0%)
  290. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  291. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  292. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  293. return this;
  294. }
  295. break;
  296. case 'rgba':
  297. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  298. // rgba(255,0,0,0.5)
  299. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  300. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  301. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  302. parseAlpha( color[ 4 ] );
  303. return this;
  304. }
  305. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  306. // rgba(100%,0%,0%,0.5)
  307. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  308. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  309. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  310. parseAlpha( color[ 4 ] );
  311. return this;
  312. }
  313. break;
  314. case 'hsl':
  315. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  316. // hsl(120,50%,50%)
  317. var h = parseFloat( color[ 1 ] );
  318. var s = parseInt( color[ 2 ], 10 ) / 100;
  319. var l = parseInt( color[ 3 ], 10 ) / 100;
  320. return this.setHSL( h, s, l );
  321. }
  322. break;
  323. case 'hsla':
  324. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  325. // hsla(120,50%,50%,0.5)
  326. var h = parseFloat( color[ 1 ] );
  327. var s = parseInt( color[ 2 ], 10 ) / 100;
  328. var l = parseInt( color[ 3 ], 10 ) / 100;
  329. parseAlpha( color[ 4 ] );
  330. return this.setHSL( h, s, l );
  331. }
  332. break;
  333. }
  334. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  335. // hex color
  336. var hex = m[ 1 ];
  337. var size = hex.length;
  338. if ( size === 3 ) {
  339. // #ff0
  340. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  341. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  342. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  343. return this;
  344. } else if ( size === 6 ) {
  345. // #ff0000
  346. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  347. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  348. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  349. return this;
  350. }
  351. }
  352. if ( style && style.length > 0 ) {
  353. // color keywords
  354. var hex = THREE.ColorKeywords[ style ];
  355. if ( hex !== undefined ) {
  356. // red
  357. this.setHex( hex );
  358. } else {
  359. // unknown color
  360. console.warn( 'THREE.Color: Unknown color ' + style );
  361. }
  362. }
  363. return this;
  364. },
  365. clone: function () {
  366. return new this.constructor( this.r, this.g, this.b );
  367. },
  368. copy: function ( color ) {
  369. this.r = color.r;
  370. this.g = color.g;
  371. this.b = color.b;
  372. return this;
  373. },
  374. copyGammaToLinear: function ( color, gammaFactor ) {
  375. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  376. this.r = Math.pow( color.r, gammaFactor );
  377. this.g = Math.pow( color.g, gammaFactor );
  378. this.b = Math.pow( color.b, gammaFactor );
  379. return this;
  380. },
  381. copyLinearToGamma: function ( color, gammaFactor ) {
  382. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  383. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  384. this.r = Math.pow( color.r, safeInverse );
  385. this.g = Math.pow( color.g, safeInverse );
  386. this.b = Math.pow( color.b, safeInverse );
  387. return this;
  388. },
  389. convertGammaToLinear: function () {
  390. var r = this.r, g = this.g, b = this.b;
  391. this.r = r * r;
  392. this.g = g * g;
  393. this.b = b * b;
  394. return this;
  395. },
  396. convertLinearToGamma: function () {
  397. this.r = Math.sqrt( this.r );
  398. this.g = Math.sqrt( this.g );
  399. this.b = Math.sqrt( this.b );
  400. return this;
  401. },
  402. getHex: function () {
  403. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  404. },
  405. getHexString: function () {
  406. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  407. },
  408. getHSL: function ( optionalTarget ) {
  409. // h,s,l ranges are in 0.0 - 1.0
  410. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  411. var r = this.r, g = this.g, b = this.b;
  412. var max = Math.max( r, g, b );
  413. var min = Math.min( r, g, b );
  414. var hue, saturation;
  415. var lightness = ( min + max ) / 2.0;
  416. if ( min === max ) {
  417. hue = 0;
  418. saturation = 0;
  419. } else {
  420. var delta = max - min;
  421. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  422. switch ( max ) {
  423. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  424. case g: hue = ( b - r ) / delta + 2; break;
  425. case b: hue = ( r - g ) / delta + 4; break;
  426. }
  427. hue /= 6;
  428. }
  429. hsl.h = hue;
  430. hsl.s = saturation;
  431. hsl.l = lightness;
  432. return hsl;
  433. },
  434. getStyle: function () {
  435. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  436. },
  437. offsetHSL: function ( h, s, l ) {
  438. var hsl = this.getHSL();
  439. hsl.h += h; hsl.s += s; hsl.l += l;
  440. this.setHSL( hsl.h, hsl.s, hsl.l );
  441. return this;
  442. },
  443. add: function ( color ) {
  444. this.r += color.r;
  445. this.g += color.g;
  446. this.b += color.b;
  447. return this;
  448. },
  449. addColors: function ( color1, color2 ) {
  450. this.r = color1.r + color2.r;
  451. this.g = color1.g + color2.g;
  452. this.b = color1.b + color2.b;
  453. return this;
  454. },
  455. addScalar: function ( s ) {
  456. this.r += s;
  457. this.g += s;
  458. this.b += s;
  459. return this;
  460. },
  461. multiply: function ( color ) {
  462. this.r *= color.r;
  463. this.g *= color.g;
  464. this.b *= color.b;
  465. return this;
  466. },
  467. multiplyScalar: function ( s ) {
  468. this.r *= s;
  469. this.g *= s;
  470. this.b *= s;
  471. return this;
  472. },
  473. lerp: function ( color, alpha ) {
  474. this.r += ( color.r - this.r ) * alpha;
  475. this.g += ( color.g - this.g ) * alpha;
  476. this.b += ( color.b - this.b ) * alpha;
  477. return this;
  478. },
  479. equals: function ( c ) {
  480. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  481. },
  482. fromArray: function ( array ) {
  483. this.r = array[ 0 ];
  484. this.g = array[ 1 ];
  485. this.b = array[ 2 ];
  486. return this;
  487. },
  488. toArray: function ( array, offset ) {
  489. if ( array === undefined ) array = [];
  490. if ( offset === undefined ) offset = 0;
  491. array[ offset ] = this.r;
  492. array[ offset + 1 ] = this.g;
  493. array[ offset + 2 ] = this.b;
  494. return array;
  495. }
  496. };
  497. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  498. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  499. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  500. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  501. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  502. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  503. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  504. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  505. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  506. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  507. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  508. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  509. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  510. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  511. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  512. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  513. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  514. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  515. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  516. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  517. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  518. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  519. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  520. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  521. // File:src/math/Quaternion.js
  522. /**
  523. * @author mikael emtinger / http://gomo.se/
  524. * @author alteredq / http://alteredqualia.com/
  525. * @author WestLangley / http://github.com/WestLangley
  526. * @author bhouston / http://clara.io
  527. */
  528. THREE.Quaternion = function ( x, y, z, w ) {
  529. this._x = x || 0;
  530. this._y = y || 0;
  531. this._z = z || 0;
  532. this._w = ( w !== undefined ) ? w : 1;
  533. };
  534. THREE.Quaternion.prototype = {
  535. constructor: THREE.Quaternion,
  536. get x () {
  537. return this._x;
  538. },
  539. set x ( value ) {
  540. this._x = value;
  541. this.onChangeCallback();
  542. },
  543. get y () {
  544. return this._y;
  545. },
  546. set y ( value ) {
  547. this._y = value;
  548. this.onChangeCallback();
  549. },
  550. get z () {
  551. return this._z;
  552. },
  553. set z ( value ) {
  554. this._z = value;
  555. this.onChangeCallback();
  556. },
  557. get w () {
  558. return this._w;
  559. },
  560. set w ( value ) {
  561. this._w = value;
  562. this.onChangeCallback();
  563. },
  564. set: function ( x, y, z, w ) {
  565. this._x = x;
  566. this._y = y;
  567. this._z = z;
  568. this._w = w;
  569. this.onChangeCallback();
  570. return this;
  571. },
  572. clone: function () {
  573. return new this.constructor( this._x, this._y, this._z, this._w );
  574. },
  575. copy: function ( quaternion ) {
  576. this._x = quaternion.x;
  577. this._y = quaternion.y;
  578. this._z = quaternion.z;
  579. this._w = quaternion.w;
  580. this.onChangeCallback();
  581. return this;
  582. },
  583. setFromEuler: function ( euler, update ) {
  584. if ( euler instanceof THREE.Euler === false ) {
  585. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  586. }
  587. // http://www.mathworks.com/matlabcentral/fileexchange/
  588. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  589. // content/SpinCalc.m
  590. var c1 = Math.cos( euler._x / 2 );
  591. var c2 = Math.cos( euler._y / 2 );
  592. var c3 = Math.cos( euler._z / 2 );
  593. var s1 = Math.sin( euler._x / 2 );
  594. var s2 = Math.sin( euler._y / 2 );
  595. var s3 = Math.sin( euler._z / 2 );
  596. var order = euler.order;
  597. if ( order === 'XYZ' ) {
  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 ( order === 'YXZ' ) {
  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 ( order === 'ZXY' ) {
  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 ( order === 'ZYX' ) {
  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. } else if ( order === 'YZX' ) {
  618. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  619. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  620. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  621. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  622. } else if ( order === 'XZY' ) {
  623. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  624. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  625. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  626. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  627. }
  628. if ( update !== false ) this.onChangeCallback();
  629. return this;
  630. },
  631. setFromAxisAngle: function ( axis, angle ) {
  632. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  633. // assumes axis is normalized
  634. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  635. this._x = axis.x * s;
  636. this._y = axis.y * s;
  637. this._z = axis.z * s;
  638. this._w = Math.cos( halfAngle );
  639. this.onChangeCallback();
  640. return this;
  641. },
  642. setFromRotationMatrix: function ( m ) {
  643. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  644. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  645. var te = m.elements,
  646. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  647. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  648. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  649. trace = m11 + m22 + m33,
  650. s;
  651. if ( trace > 0 ) {
  652. s = 0.5 / Math.sqrt( trace + 1.0 );
  653. this._w = 0.25 / s;
  654. this._x = ( m32 - m23 ) * s;
  655. this._y = ( m13 - m31 ) * s;
  656. this._z = ( m21 - m12 ) * s;
  657. } else if ( m11 > m22 && m11 > m33 ) {
  658. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  659. this._w = ( m32 - m23 ) / s;
  660. this._x = 0.25 * s;
  661. this._y = ( m12 + m21 ) / s;
  662. this._z = ( m13 + m31 ) / s;
  663. } else if ( m22 > m33 ) {
  664. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  665. this._w = ( m13 - m31 ) / s;
  666. this._x = ( m12 + m21 ) / s;
  667. this._y = 0.25 * s;
  668. this._z = ( m23 + m32 ) / s;
  669. } else {
  670. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  671. this._w = ( m21 - m12 ) / s;
  672. this._x = ( m13 + m31 ) / s;
  673. this._y = ( m23 + m32 ) / s;
  674. this._z = 0.25 * s;
  675. }
  676. this.onChangeCallback();
  677. return this;
  678. },
  679. setFromUnitVectors: function () {
  680. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  681. // assumes direction vectors vFrom and vTo are normalized
  682. var v1, r;
  683. var EPS = 0.000001;
  684. return function ( vFrom, vTo ) {
  685. if ( v1 === undefined ) v1 = new THREE.Vector3();
  686. r = vFrom.dot( vTo ) + 1;
  687. if ( r < EPS ) {
  688. r = 0;
  689. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  690. v1.set( - vFrom.y, vFrom.x, 0 );
  691. } else {
  692. v1.set( 0, - vFrom.z, vFrom.y );
  693. }
  694. } else {
  695. v1.crossVectors( vFrom, vTo );
  696. }
  697. this._x = v1.x;
  698. this._y = v1.y;
  699. this._z = v1.z;
  700. this._w = r;
  701. this.normalize();
  702. return this;
  703. }
  704. }(),
  705. inverse: function () {
  706. this.conjugate().normalize();
  707. return this;
  708. },
  709. conjugate: function () {
  710. this._x *= - 1;
  711. this._y *= - 1;
  712. this._z *= - 1;
  713. this.onChangeCallback();
  714. return this;
  715. },
  716. dot: function ( v ) {
  717. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  718. },
  719. lengthSq: function () {
  720. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  721. },
  722. length: function () {
  723. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  724. },
  725. normalize: function () {
  726. var l = this.length();
  727. if ( l === 0 ) {
  728. this._x = 0;
  729. this._y = 0;
  730. this._z = 0;
  731. this._w = 1;
  732. } else {
  733. l = 1 / l;
  734. this._x = this._x * l;
  735. this._y = this._y * l;
  736. this._z = this._z * l;
  737. this._w = this._w * l;
  738. }
  739. this.onChangeCallback();
  740. return this;
  741. },
  742. multiply: function ( q, p ) {
  743. if ( p !== undefined ) {
  744. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  745. return this.multiplyQuaternions( q, p );
  746. }
  747. return this.multiplyQuaternions( this, q );
  748. },
  749. multiplyQuaternions: function ( a, b ) {
  750. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  751. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  752. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  753. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  754. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  755. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  756. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  757. this.onChangeCallback();
  758. return this;
  759. },
  760. multiplyVector3: function ( vector ) {
  761. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  762. return vector.applyQuaternion( this );
  763. },
  764. slerp: function ( qb, t ) {
  765. if ( t === 0 ) return this;
  766. if ( t === 1 ) return this.copy( qb );
  767. var x = this._x, y = this._y, z = this._z, w = this._w;
  768. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  769. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  770. if ( cosHalfTheta < 0 ) {
  771. this._w = - qb._w;
  772. this._x = - qb._x;
  773. this._y = - qb._y;
  774. this._z = - qb._z;
  775. cosHalfTheta = - cosHalfTheta;
  776. } else {
  777. this.copy( qb );
  778. }
  779. if ( cosHalfTheta >= 1.0 ) {
  780. this._w = w;
  781. this._x = x;
  782. this._y = y;
  783. this._z = z;
  784. return this;
  785. }
  786. var halfTheta = Math.acos( cosHalfTheta );
  787. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  788. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  789. this._w = 0.5 * ( w + this._w );
  790. this._x = 0.5 * ( x + this._x );
  791. this._y = 0.5 * ( y + this._y );
  792. this._z = 0.5 * ( z + this._z );
  793. return this;
  794. }
  795. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  796. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  797. this._w = ( w * ratioA + this._w * ratioB );
  798. this._x = ( x * ratioA + this._x * ratioB );
  799. this._y = ( y * ratioA + this._y * ratioB );
  800. this._z = ( z * ratioA + this._z * ratioB );
  801. this.onChangeCallback();
  802. return this;
  803. },
  804. equals: function ( quaternion ) {
  805. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  806. },
  807. fromArray: function ( array, offset ) {
  808. if ( offset === undefined ) offset = 0;
  809. this._x = array[ offset ];
  810. this._y = array[ offset + 1 ];
  811. this._z = array[ offset + 2 ];
  812. this._w = array[ offset + 3 ];
  813. this.onChangeCallback();
  814. return this;
  815. },
  816. toArray: function ( array, offset ) {
  817. if ( array === undefined ) array = [];
  818. if ( offset === undefined ) offset = 0;
  819. array[ offset ] = this._x;
  820. array[ offset + 1 ] = this._y;
  821. array[ offset + 2 ] = this._z;
  822. array[ offset + 3 ] = this._w;
  823. return array;
  824. },
  825. onChange: function ( callback ) {
  826. this.onChangeCallback = callback;
  827. return this;
  828. },
  829. onChangeCallback: function () {}
  830. };
  831. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  832. return qm.copy( qa ).slerp( qb, t );
  833. };
  834. // File:src/math/Vector2.js
  835. /**
  836. * @author mrdoob / http://mrdoob.com/
  837. * @author philogb / http://blog.thejit.org/
  838. * @author egraether / http://egraether.com/
  839. * @author zz85 / http://www.lab4games.net/zz85/blog
  840. */
  841. THREE.Vector2 = function ( x, y ) {
  842. this.x = x || 0;
  843. this.y = y || 0;
  844. };
  845. THREE.Vector2.prototype = {
  846. constructor: THREE.Vector2,
  847. set: function ( x, y ) {
  848. this.x = x;
  849. this.y = y;
  850. return this;
  851. },
  852. setX: function ( x ) {
  853. this.x = x;
  854. return this;
  855. },
  856. setY: function ( y ) {
  857. this.y = y;
  858. return this;
  859. },
  860. setComponent: function ( index, value ) {
  861. switch ( index ) {
  862. case 0: this.x = value; break;
  863. case 1: this.y = value; break;
  864. default: throw new Error( 'index is out of range: ' + index );
  865. }
  866. },
  867. getComponent: function ( index ) {
  868. switch ( index ) {
  869. case 0: return this.x;
  870. case 1: return this.y;
  871. default: throw new Error( 'index is out of range: ' + index );
  872. }
  873. },
  874. clone: function () {
  875. return new this.constructor( this.x, this.y );
  876. },
  877. copy: function ( v ) {
  878. this.x = v.x;
  879. this.y = v.y;
  880. return this;
  881. },
  882. add: function ( v, w ) {
  883. if ( w !== undefined ) {
  884. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  885. return this.addVectors( v, w );
  886. }
  887. this.x += v.x;
  888. this.y += v.y;
  889. return this;
  890. },
  891. addScalar: function ( s ) {
  892. this.x += s;
  893. this.y += s;
  894. return this;
  895. },
  896. addVectors: function ( a, b ) {
  897. this.x = a.x + b.x;
  898. this.y = a.y + b.y;
  899. return this;
  900. },
  901. addScaledVector: function ( v, s ) {
  902. this.x += v.x * s;
  903. this.y += v.y * s;
  904. return this;
  905. },
  906. sub: function ( v, w ) {
  907. if ( w !== undefined ) {
  908. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  909. return this.subVectors( v, w );
  910. }
  911. this.x -= v.x;
  912. this.y -= v.y;
  913. return this;
  914. },
  915. subScalar: function ( s ) {
  916. this.x -= s;
  917. this.y -= s;
  918. return this;
  919. },
  920. subVectors: function ( a, b ) {
  921. this.x = a.x - b.x;
  922. this.y = a.y - b.y;
  923. return this;
  924. },
  925. multiply: function ( v ) {
  926. this.x *= v.x;
  927. this.y *= v.y;
  928. return this;
  929. },
  930. multiplyScalar: function ( s ) {
  931. this.x *= s;
  932. this.y *= s;
  933. return this;
  934. },
  935. divide: function ( v ) {
  936. this.x /= v.x;
  937. this.y /= v.y;
  938. return this;
  939. },
  940. divideScalar: function ( scalar ) {
  941. if ( scalar !== 0 ) {
  942. var invScalar = 1 / scalar;
  943. this.x *= invScalar;
  944. this.y *= invScalar;
  945. } else {
  946. this.x = 0;
  947. this.y = 0;
  948. }
  949. return this;
  950. },
  951. min: function ( v ) {
  952. if ( this.x > v.x ) {
  953. this.x = v.x;
  954. }
  955. if ( this.y > v.y ) {
  956. this.y = v.y;
  957. }
  958. return this;
  959. },
  960. max: function ( v ) {
  961. if ( this.x < v.x ) {
  962. this.x = v.x;
  963. }
  964. if ( this.y < v.y ) {
  965. this.y = v.y;
  966. }
  967. return this;
  968. },
  969. clamp: function ( min, max ) {
  970. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  971. if ( this.x < min.x ) {
  972. this.x = min.x;
  973. } else if ( this.x > max.x ) {
  974. this.x = max.x;
  975. }
  976. if ( this.y < min.y ) {
  977. this.y = min.y;
  978. } else if ( this.y > max.y ) {
  979. this.y = max.y;
  980. }
  981. return this;
  982. },
  983. clampScalar: function () {
  984. var min, max;
  985. return function clampScalar( minVal, maxVal ) {
  986. if ( min === undefined ) {
  987. min = new THREE.Vector2();
  988. max = new THREE.Vector2();
  989. }
  990. min.set( minVal, minVal );
  991. max.set( maxVal, maxVal );
  992. return this.clamp( min, max );
  993. };
  994. }(),
  995. floor: function () {
  996. this.x = Math.floor( this.x );
  997. this.y = Math.floor( this.y );
  998. return this;
  999. },
  1000. ceil: function () {
  1001. this.x = Math.ceil( this.x );
  1002. this.y = Math.ceil( this.y );
  1003. return this;
  1004. },
  1005. round: function () {
  1006. this.x = Math.round( this.x );
  1007. this.y = Math.round( this.y );
  1008. return this;
  1009. },
  1010. roundToZero: function () {
  1011. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1012. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1013. return this;
  1014. },
  1015. negate: function () {
  1016. this.x = - this.x;
  1017. this.y = - this.y;
  1018. return this;
  1019. },
  1020. dot: function ( v ) {
  1021. return this.x * v.x + this.y * v.y;
  1022. },
  1023. lengthSq: function () {
  1024. return this.x * this.x + this.y * this.y;
  1025. },
  1026. length: function () {
  1027. return Math.sqrt( this.x * this.x + this.y * this.y );
  1028. },
  1029. lengthManhattan: function() {
  1030. return Math.abs( this.x ) + Math.abs( this.y );
  1031. },
  1032. normalize: function () {
  1033. return this.divideScalar( this.length() );
  1034. },
  1035. distanceTo: function ( v ) {
  1036. return Math.sqrt( this.distanceToSquared( v ) );
  1037. },
  1038. distanceToSquared: function ( v ) {
  1039. var dx = this.x - v.x, dy = this.y - v.y;
  1040. return dx * dx + dy * dy;
  1041. },
  1042. setLength: function ( l ) {
  1043. var oldLength = this.length();
  1044. if ( oldLength !== 0 && l !== oldLength ) {
  1045. this.multiplyScalar( l / oldLength );
  1046. }
  1047. return this;
  1048. },
  1049. lerp: function ( v, alpha ) {
  1050. this.x += ( v.x - this.x ) * alpha;
  1051. this.y += ( v.y - this.y ) * alpha;
  1052. return this;
  1053. },
  1054. lerpVectors: function ( v1, v2, alpha ) {
  1055. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1056. return this;
  1057. },
  1058. equals: function ( v ) {
  1059. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1060. },
  1061. fromArray: function ( array, offset ) {
  1062. if ( offset === undefined ) offset = 0;
  1063. this.x = array[ offset ];
  1064. this.y = array[ offset + 1 ];
  1065. return this;
  1066. },
  1067. toArray: function ( array, offset ) {
  1068. if ( array === undefined ) array = [];
  1069. if ( offset === undefined ) offset = 0;
  1070. array[ offset ] = this.x;
  1071. array[ offset + 1 ] = this.y;
  1072. return array;
  1073. },
  1074. fromAttribute: function ( attribute, index, offset ) {
  1075. if ( offset === undefined ) offset = 0;
  1076. index = index * attribute.itemSize + offset;
  1077. this.x = attribute.array[ index ];
  1078. this.y = attribute.array[ index + 1 ];
  1079. return this;
  1080. }
  1081. };
  1082. // File:src/math/Vector3.js
  1083. /**
  1084. * @author mrdoob / http://mrdoob.com/
  1085. * @author *kile / http://kile.stravaganza.org/
  1086. * @author philogb / http://blog.thejit.org/
  1087. * @author mikael emtinger / http://gomo.se/
  1088. * @author egraether / http://egraether.com/
  1089. * @author WestLangley / http://github.com/WestLangley
  1090. */
  1091. THREE.Vector3 = function ( x, y, z ) {
  1092. this.x = x || 0;
  1093. this.y = y || 0;
  1094. this.z = z || 0;
  1095. };
  1096. THREE.Vector3.prototype = {
  1097. constructor: THREE.Vector3,
  1098. set: function ( x, y, z ) {
  1099. this.x = x;
  1100. this.y = y;
  1101. this.z = z;
  1102. return this;
  1103. },
  1104. setX: function ( x ) {
  1105. this.x = x;
  1106. return this;
  1107. },
  1108. setY: function ( y ) {
  1109. this.y = y;
  1110. return this;
  1111. },
  1112. setZ: function ( z ) {
  1113. this.z = z;
  1114. return this;
  1115. },
  1116. setComponent: function ( index, value ) {
  1117. switch ( index ) {
  1118. case 0: this.x = value; break;
  1119. case 1: this.y = value; break;
  1120. case 2: this.z = value; break;
  1121. default: throw new Error( 'index is out of range: ' + index );
  1122. }
  1123. },
  1124. getComponent: function ( index ) {
  1125. switch ( index ) {
  1126. case 0: return this.x;
  1127. case 1: return this.y;
  1128. case 2: return this.z;
  1129. default: throw new Error( 'index is out of range: ' + index );
  1130. }
  1131. },
  1132. clone: function () {
  1133. return new this.constructor( this.x, this.y, this.z );
  1134. },
  1135. copy: function ( v ) {
  1136. this.x = v.x;
  1137. this.y = v.y;
  1138. this.z = v.z;
  1139. return this;
  1140. },
  1141. add: function ( v, w ) {
  1142. if ( w !== undefined ) {
  1143. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1144. return this.addVectors( v, w );
  1145. }
  1146. this.x += v.x;
  1147. this.y += v.y;
  1148. this.z += v.z;
  1149. return this;
  1150. },
  1151. addScalar: function ( s ) {
  1152. this.x += s;
  1153. this.y += s;
  1154. this.z += s;
  1155. return this;
  1156. },
  1157. addVectors: function ( a, b ) {
  1158. this.x = a.x + b.x;
  1159. this.y = a.y + b.y;
  1160. this.z = a.z + b.z;
  1161. return this;
  1162. },
  1163. addScaledVector: function ( v, s ) {
  1164. this.x += v.x * s;
  1165. this.y += v.y * s;
  1166. this.z += v.z * s;
  1167. return this;
  1168. },
  1169. sub: function ( v, w ) {
  1170. if ( w !== undefined ) {
  1171. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1172. return this.subVectors( v, w );
  1173. }
  1174. this.x -= v.x;
  1175. this.y -= v.y;
  1176. this.z -= v.z;
  1177. return this;
  1178. },
  1179. subScalar: function ( s ) {
  1180. this.x -= s;
  1181. this.y -= s;
  1182. this.z -= s;
  1183. return this;
  1184. },
  1185. subVectors: function ( a, b ) {
  1186. this.x = a.x - b.x;
  1187. this.y = a.y - b.y;
  1188. this.z = a.z - b.z;
  1189. return this;
  1190. },
  1191. multiply: function ( v, w ) {
  1192. if ( w !== undefined ) {
  1193. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1194. return this.multiplyVectors( v, w );
  1195. }
  1196. this.x *= v.x;
  1197. this.y *= v.y;
  1198. this.z *= v.z;
  1199. return this;
  1200. },
  1201. multiplyScalar: function ( scalar ) {
  1202. this.x *= scalar;
  1203. this.y *= scalar;
  1204. this.z *= scalar;
  1205. return this;
  1206. },
  1207. multiplyVectors: function ( a, b ) {
  1208. this.x = a.x * b.x;
  1209. this.y = a.y * b.y;
  1210. this.z = a.z * b.z;
  1211. return this;
  1212. },
  1213. applyEuler: function () {
  1214. var quaternion;
  1215. return function applyEuler( euler ) {
  1216. if ( euler instanceof THREE.Euler === false ) {
  1217. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1218. }
  1219. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1220. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1221. return this;
  1222. };
  1223. }(),
  1224. applyAxisAngle: function () {
  1225. var quaternion;
  1226. return function applyAxisAngle( axis, angle ) {
  1227. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1228. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1229. return this;
  1230. };
  1231. }(),
  1232. applyMatrix3: function ( m ) {
  1233. var x = this.x;
  1234. var y = this.y;
  1235. var z = this.z;
  1236. var e = m.elements;
  1237. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1238. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1239. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1240. return this;
  1241. },
  1242. applyMatrix4: function ( m ) {
  1243. // input: THREE.Matrix4 affine matrix
  1244. var x = this.x, y = this.y, z = this.z;
  1245. var e = m.elements;
  1246. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1247. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1248. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1249. return this;
  1250. },
  1251. applyProjection: function ( m ) {
  1252. // input: THREE.Matrix4 projection matrix
  1253. var x = this.x, y = this.y, z = this.z;
  1254. var e = m.elements;
  1255. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1256. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1257. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1258. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1259. return this;
  1260. },
  1261. applyQuaternion: function ( q ) {
  1262. var x = this.x;
  1263. var y = this.y;
  1264. var z = this.z;
  1265. var qx = q.x;
  1266. var qy = q.y;
  1267. var qz = q.z;
  1268. var qw = q.w;
  1269. // calculate quat * vector
  1270. var ix = qw * x + qy * z - qz * y;
  1271. var iy = qw * y + qz * x - qx * z;
  1272. var iz = qw * z + qx * y - qy * x;
  1273. var iw = - qx * x - qy * y - qz * z;
  1274. // calculate result * inverse quat
  1275. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1276. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1277. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1278. return this;
  1279. },
  1280. project: function () {
  1281. var matrix;
  1282. return function project( camera ) {
  1283. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1284. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1285. return this.applyProjection( matrix );
  1286. };
  1287. }(),
  1288. unproject: function () {
  1289. var matrix;
  1290. return function unproject( camera ) {
  1291. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1292. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1293. return this.applyProjection( matrix );
  1294. };
  1295. }(),
  1296. transformDirection: function ( m ) {
  1297. // input: THREE.Matrix4 affine matrix
  1298. // vector interpreted as a direction
  1299. var x = this.x, y = this.y, z = this.z;
  1300. var e = m.elements;
  1301. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1302. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1303. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1304. this.normalize();
  1305. return this;
  1306. },
  1307. divide: function ( v ) {
  1308. this.x /= v.x;
  1309. this.y /= v.y;
  1310. this.z /= v.z;
  1311. return this;
  1312. },
  1313. divideScalar: function ( scalar ) {
  1314. if ( scalar !== 0 ) {
  1315. var invScalar = 1 / scalar;
  1316. this.x *= invScalar;
  1317. this.y *= invScalar;
  1318. this.z *= invScalar;
  1319. } else {
  1320. this.x = 0;
  1321. this.y = 0;
  1322. this.z = 0;
  1323. }
  1324. return this;
  1325. },
  1326. min: function ( v ) {
  1327. if ( this.x > v.x ) {
  1328. this.x = v.x;
  1329. }
  1330. if ( this.y > v.y ) {
  1331. this.y = v.y;
  1332. }
  1333. if ( this.z > v.z ) {
  1334. this.z = v.z;
  1335. }
  1336. return this;
  1337. },
  1338. max: function ( v ) {
  1339. if ( this.x < v.x ) {
  1340. this.x = v.x;
  1341. }
  1342. if ( this.y < v.y ) {
  1343. this.y = v.y;
  1344. }
  1345. if ( this.z < v.z ) {
  1346. this.z = v.z;
  1347. }
  1348. return this;
  1349. },
  1350. clamp: function ( min, max ) {
  1351. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1352. if ( this.x < min.x ) {
  1353. this.x = min.x;
  1354. } else if ( this.x > max.x ) {
  1355. this.x = max.x;
  1356. }
  1357. if ( this.y < min.y ) {
  1358. this.y = min.y;
  1359. } else if ( this.y > max.y ) {
  1360. this.y = max.y;
  1361. }
  1362. if ( this.z < min.z ) {
  1363. this.z = min.z;
  1364. } else if ( this.z > max.z ) {
  1365. this.z = max.z;
  1366. }
  1367. return this;
  1368. },
  1369. clampScalar: function () {
  1370. var min, max;
  1371. return function clampScalar( minVal, maxVal ) {
  1372. if ( min === undefined ) {
  1373. min = new THREE.Vector3();
  1374. max = new THREE.Vector3();
  1375. }
  1376. min.set( minVal, minVal, minVal );
  1377. max.set( maxVal, maxVal, maxVal );
  1378. return this.clamp( min, max );
  1379. };
  1380. }(),
  1381. floor: function () {
  1382. this.x = Math.floor( this.x );
  1383. this.y = Math.floor( this.y );
  1384. this.z = Math.floor( this.z );
  1385. return this;
  1386. },
  1387. ceil: function () {
  1388. this.x = Math.ceil( this.x );
  1389. this.y = Math.ceil( this.y );
  1390. this.z = Math.ceil( this.z );
  1391. return this;
  1392. },
  1393. round: function () {
  1394. this.x = Math.round( this.x );
  1395. this.y = Math.round( this.y );
  1396. this.z = Math.round( this.z );
  1397. return this;
  1398. },
  1399. roundToZero: function () {
  1400. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1401. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1402. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1403. return this;
  1404. },
  1405. negate: function () {
  1406. this.x = - this.x;
  1407. this.y = - this.y;
  1408. this.z = - this.z;
  1409. return this;
  1410. },
  1411. dot: function ( v ) {
  1412. return this.x * v.x + this.y * v.y + this.z * v.z;
  1413. },
  1414. lengthSq: function () {
  1415. return this.x * this.x + this.y * this.y + this.z * this.z;
  1416. },
  1417. length: function () {
  1418. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1419. },
  1420. lengthManhattan: function () {
  1421. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1422. },
  1423. normalize: function () {
  1424. return this.divideScalar( this.length() );
  1425. },
  1426. setLength: function ( l ) {
  1427. var oldLength = this.length();
  1428. if ( oldLength !== 0 && l !== oldLength ) {
  1429. this.multiplyScalar( l / oldLength );
  1430. }
  1431. return this;
  1432. },
  1433. lerp: function ( v, alpha ) {
  1434. this.x += ( v.x - this.x ) * alpha;
  1435. this.y += ( v.y - this.y ) * alpha;
  1436. this.z += ( v.z - this.z ) * alpha;
  1437. return this;
  1438. },
  1439. lerpVectors: function ( v1, v2, alpha ) {
  1440. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1441. return this;
  1442. },
  1443. cross: function ( v, w ) {
  1444. if ( w !== undefined ) {
  1445. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1446. return this.crossVectors( v, w );
  1447. }
  1448. var x = this.x, y = this.y, z = this.z;
  1449. this.x = y * v.z - z * v.y;
  1450. this.y = z * v.x - x * v.z;
  1451. this.z = x * v.y - y * v.x;
  1452. return this;
  1453. },
  1454. crossVectors: function ( a, b ) {
  1455. var ax = a.x, ay = a.y, az = a.z;
  1456. var bx = b.x, by = b.y, bz = b.z;
  1457. this.x = ay * bz - az * by;
  1458. this.y = az * bx - ax * bz;
  1459. this.z = ax * by - ay * bx;
  1460. return this;
  1461. },
  1462. projectOnVector: function () {
  1463. var v1, dot;
  1464. return function projectOnVector( vector ) {
  1465. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1466. v1.copy( vector ).normalize();
  1467. dot = this.dot( v1 );
  1468. return this.copy( v1 ).multiplyScalar( dot );
  1469. };
  1470. }(),
  1471. projectOnPlane: function () {
  1472. var v1;
  1473. return function projectOnPlane( planeNormal ) {
  1474. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1475. v1.copy( this ).projectOnVector( planeNormal );
  1476. return this.sub( v1 );
  1477. }
  1478. }(),
  1479. reflect: function () {
  1480. // reflect incident vector off plane orthogonal to normal
  1481. // normal is assumed to have unit length
  1482. var v1;
  1483. return function reflect( normal ) {
  1484. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1485. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1486. }
  1487. }(),
  1488. angleTo: function ( v ) {
  1489. var theta = this.dot( v ) / ( this.length() * v.length() );
  1490. // clamp, to handle numerical problems
  1491. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1492. },
  1493. distanceTo: function ( v ) {
  1494. return Math.sqrt( this.distanceToSquared( v ) );
  1495. },
  1496. distanceToSquared: function ( v ) {
  1497. var dx = this.x - v.x;
  1498. var dy = this.y - v.y;
  1499. var dz = this.z - v.z;
  1500. return dx * dx + dy * dy + dz * dz;
  1501. },
  1502. setEulerFromRotationMatrix: function ( m, order ) {
  1503. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1504. },
  1505. setEulerFromQuaternion: function ( q, order ) {
  1506. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1507. },
  1508. getPositionFromMatrix: function ( m ) {
  1509. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1510. return this.setFromMatrixPosition( m );
  1511. },
  1512. getScaleFromMatrix: function ( m ) {
  1513. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1514. return this.setFromMatrixScale( m );
  1515. },
  1516. getColumnFromMatrix: function ( index, matrix ) {
  1517. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1518. return this.setFromMatrixColumn( index, matrix );
  1519. },
  1520. setFromMatrixPosition: function ( m ) {
  1521. this.x = m.elements[ 12 ];
  1522. this.y = m.elements[ 13 ];
  1523. this.z = m.elements[ 14 ];
  1524. return this;
  1525. },
  1526. setFromMatrixScale: function ( m ) {
  1527. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1528. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1529. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1530. this.x = sx;
  1531. this.y = sy;
  1532. this.z = sz;
  1533. return this;
  1534. },
  1535. setFromMatrixColumn: function ( index, matrix ) {
  1536. var offset = index * 4;
  1537. var me = matrix.elements;
  1538. this.x = me[ offset ];
  1539. this.y = me[ offset + 1 ];
  1540. this.z = me[ offset + 2 ];
  1541. return this;
  1542. },
  1543. equals: function ( v ) {
  1544. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1545. },
  1546. fromArray: function ( array, offset ) {
  1547. if ( offset === undefined ) offset = 0;
  1548. this.x = array[ offset ];
  1549. this.y = array[ offset + 1 ];
  1550. this.z = array[ offset + 2 ];
  1551. return this;
  1552. },
  1553. toArray: function ( array, offset ) {
  1554. if ( array === undefined ) array = [];
  1555. if ( offset === undefined ) offset = 0;
  1556. array[ offset ] = this.x;
  1557. array[ offset + 1 ] = this.y;
  1558. array[ offset + 2 ] = this.z;
  1559. return array;
  1560. },
  1561. fromAttribute: function ( attribute, index, offset ) {
  1562. if ( offset === undefined ) offset = 0;
  1563. index = index * attribute.itemSize + offset;
  1564. this.x = attribute.array[ index ];
  1565. this.y = attribute.array[ index + 1 ];
  1566. this.z = attribute.array[ index + 2 ];
  1567. return this;
  1568. }
  1569. };
  1570. // File:src/math/Vector4.js
  1571. /**
  1572. * @author supereggbert / http://www.paulbrunt.co.uk/
  1573. * @author philogb / http://blog.thejit.org/
  1574. * @author mikael emtinger / http://gomo.se/
  1575. * @author egraether / http://egraether.com/
  1576. * @author WestLangley / http://github.com/WestLangley
  1577. */
  1578. THREE.Vector4 = function ( x, y, z, w ) {
  1579. this.x = x || 0;
  1580. this.y = y || 0;
  1581. this.z = z || 0;
  1582. this.w = ( w !== undefined ) ? w : 1;
  1583. };
  1584. THREE.Vector4.prototype = {
  1585. constructor: THREE.Vector4,
  1586. set: function ( x, y, z, w ) {
  1587. this.x = x;
  1588. this.y = y;
  1589. this.z = z;
  1590. this.w = w;
  1591. return this;
  1592. },
  1593. setX: function ( x ) {
  1594. this.x = x;
  1595. return this;
  1596. },
  1597. setY: function ( y ) {
  1598. this.y = y;
  1599. return this;
  1600. },
  1601. setZ: function ( z ) {
  1602. this.z = z;
  1603. return this;
  1604. },
  1605. setW: function ( w ) {
  1606. this.w = w;
  1607. return this;
  1608. },
  1609. setComponent: function ( index, value ) {
  1610. switch ( index ) {
  1611. case 0: this.x = value; break;
  1612. case 1: this.y = value; break;
  1613. case 2: this.z = value; break;
  1614. case 3: this.w = value; break;
  1615. default: throw new Error( 'index is out of range: ' + index );
  1616. }
  1617. },
  1618. getComponent: function ( index ) {
  1619. switch ( index ) {
  1620. case 0: return this.x;
  1621. case 1: return this.y;
  1622. case 2: return this.z;
  1623. case 3: return this.w;
  1624. default: throw new Error( 'index is out of range: ' + index );
  1625. }
  1626. },
  1627. clone: function () {
  1628. return new this.constructor( this.x, this.y, this.z, this.w );
  1629. },
  1630. copy: function ( v ) {
  1631. this.x = v.x;
  1632. this.y = v.y;
  1633. this.z = v.z;
  1634. this.w = ( v.w !== undefined ) ? v.w : 1;
  1635. return this;
  1636. },
  1637. add: function ( v, w ) {
  1638. if ( w !== undefined ) {
  1639. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1640. return this.addVectors( v, w );
  1641. }
  1642. this.x += v.x;
  1643. this.y += v.y;
  1644. this.z += v.z;
  1645. this.w += v.w;
  1646. return this;
  1647. },
  1648. addScalar: function ( s ) {
  1649. this.x += s;
  1650. this.y += s;
  1651. this.z += s;
  1652. this.w += s;
  1653. return this;
  1654. },
  1655. addVectors: function ( a, b ) {
  1656. this.x = a.x + b.x;
  1657. this.y = a.y + b.y;
  1658. this.z = a.z + b.z;
  1659. this.w = a.w + b.w;
  1660. return this;
  1661. },
  1662. addScaledVector: function ( v, s ) {
  1663. this.x += v.x * s;
  1664. this.y += v.y * s;
  1665. this.z += v.z * s;
  1666. this.w += v.w * s;
  1667. return this;
  1668. },
  1669. sub: function ( v, w ) {
  1670. if ( w !== undefined ) {
  1671. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1672. return this.subVectors( v, w );
  1673. }
  1674. this.x -= v.x;
  1675. this.y -= v.y;
  1676. this.z -= v.z;
  1677. this.w -= v.w;
  1678. return this;
  1679. },
  1680. subScalar: function ( s ) {
  1681. this.x -= s;
  1682. this.y -= s;
  1683. this.z -= s;
  1684. this.w -= s;
  1685. return this;
  1686. },
  1687. subVectors: function ( a, b ) {
  1688. this.x = a.x - b.x;
  1689. this.y = a.y - b.y;
  1690. this.z = a.z - b.z;
  1691. this.w = a.w - b.w;
  1692. return this;
  1693. },
  1694. multiplyScalar: function ( scalar ) {
  1695. this.x *= scalar;
  1696. this.y *= scalar;
  1697. this.z *= scalar;
  1698. this.w *= scalar;
  1699. return this;
  1700. },
  1701. applyMatrix4: function ( m ) {
  1702. var x = this.x;
  1703. var y = this.y;
  1704. var z = this.z;
  1705. var w = this.w;
  1706. var e = m.elements;
  1707. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1708. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1709. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1710. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1711. return this;
  1712. },
  1713. divideScalar: function ( scalar ) {
  1714. if ( scalar !== 0 ) {
  1715. var invScalar = 1 / scalar;
  1716. this.x *= invScalar;
  1717. this.y *= invScalar;
  1718. this.z *= invScalar;
  1719. this.w *= invScalar;
  1720. } else {
  1721. this.x = 0;
  1722. this.y = 0;
  1723. this.z = 0;
  1724. this.w = 1;
  1725. }
  1726. return this;
  1727. },
  1728. setAxisAngleFromQuaternion: function ( q ) {
  1729. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1730. // q is assumed to be normalized
  1731. this.w = 2 * Math.acos( q.w );
  1732. var s = Math.sqrt( 1 - q.w * q.w );
  1733. if ( s < 0.0001 ) {
  1734. this.x = 1;
  1735. this.y = 0;
  1736. this.z = 0;
  1737. } else {
  1738. this.x = q.x / s;
  1739. this.y = q.y / s;
  1740. this.z = q.z / s;
  1741. }
  1742. return this;
  1743. },
  1744. setAxisAngleFromRotationMatrix: function ( m ) {
  1745. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1746. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1747. var angle, x, y, z, // variables for result
  1748. epsilon = 0.01, // margin to allow for rounding errors
  1749. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1750. te = m.elements,
  1751. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1752. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1753. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1754. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1755. && ( Math.abs( m13 - m31 ) < epsilon )
  1756. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1757. // singularity found
  1758. // first check for identity matrix which must have +1 for all terms
  1759. // in leading diagonal and zero in other terms
  1760. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1761. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1762. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1763. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1764. // this singularity is identity matrix so angle = 0
  1765. this.set( 1, 0, 0, 0 );
  1766. return this; // zero angle, arbitrary axis
  1767. }
  1768. // otherwise this singularity is angle = 180
  1769. angle = Math.PI;
  1770. var xx = ( m11 + 1 ) / 2;
  1771. var yy = ( m22 + 1 ) / 2;
  1772. var zz = ( m33 + 1 ) / 2;
  1773. var xy = ( m12 + m21 ) / 4;
  1774. var xz = ( m13 + m31 ) / 4;
  1775. var yz = ( m23 + m32 ) / 4;
  1776. if ( ( xx > yy ) && ( xx > zz ) ) {
  1777. // m11 is the largest diagonal term
  1778. if ( xx < epsilon ) {
  1779. x = 0;
  1780. y = 0.707106781;
  1781. z = 0.707106781;
  1782. } else {
  1783. x = Math.sqrt( xx );
  1784. y = xy / x;
  1785. z = xz / x;
  1786. }
  1787. } else if ( yy > zz ) {
  1788. // m22 is the largest diagonal term
  1789. if ( yy < epsilon ) {
  1790. x = 0.707106781;
  1791. y = 0;
  1792. z = 0.707106781;
  1793. } else {
  1794. y = Math.sqrt( yy );
  1795. x = xy / y;
  1796. z = yz / y;
  1797. }
  1798. } else {
  1799. // m33 is the largest diagonal term so base result on this
  1800. if ( zz < epsilon ) {
  1801. x = 0.707106781;
  1802. y = 0.707106781;
  1803. z = 0;
  1804. } else {
  1805. z = Math.sqrt( zz );
  1806. x = xz / z;
  1807. y = yz / z;
  1808. }
  1809. }
  1810. this.set( x, y, z, angle );
  1811. return this; // return 180 deg rotation
  1812. }
  1813. // as we have reached here there are no singularities so we can handle normally
  1814. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1815. + ( m13 - m31 ) * ( m13 - m31 )
  1816. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1817. if ( Math.abs( s ) < 0.001 ) s = 1;
  1818. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1819. // caught by singularity test above, but I've left it in just in case
  1820. this.x = ( m32 - m23 ) / s;
  1821. this.y = ( m13 - m31 ) / s;
  1822. this.z = ( m21 - m12 ) / s;
  1823. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1824. return this;
  1825. },
  1826. min: function ( v ) {
  1827. if ( this.x > v.x ) {
  1828. this.x = v.x;
  1829. }
  1830. if ( this.y > v.y ) {
  1831. this.y = v.y;
  1832. }
  1833. if ( this.z > v.z ) {
  1834. this.z = v.z;
  1835. }
  1836. if ( this.w > v.w ) {
  1837. this.w = v.w;
  1838. }
  1839. return this;
  1840. },
  1841. max: function ( v ) {
  1842. if ( this.x < v.x ) {
  1843. this.x = v.x;
  1844. }
  1845. if ( this.y < v.y ) {
  1846. this.y = v.y;
  1847. }
  1848. if ( this.z < v.z ) {
  1849. this.z = v.z;
  1850. }
  1851. if ( this.w < v.w ) {
  1852. this.w = v.w;
  1853. }
  1854. return this;
  1855. },
  1856. clamp: function ( min, max ) {
  1857. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1858. if ( this.x < min.x ) {
  1859. this.x = min.x;
  1860. } else if ( this.x > max.x ) {
  1861. this.x = max.x;
  1862. }
  1863. if ( this.y < min.y ) {
  1864. this.y = min.y;
  1865. } else if ( this.y > max.y ) {
  1866. this.y = max.y;
  1867. }
  1868. if ( this.z < min.z ) {
  1869. this.z = min.z;
  1870. } else if ( this.z > max.z ) {
  1871. this.z = max.z;
  1872. }
  1873. if ( this.w < min.w ) {
  1874. this.w = min.w;
  1875. } else if ( this.w > max.w ) {
  1876. this.w = max.w;
  1877. }
  1878. return this;
  1879. },
  1880. clampScalar: function () {
  1881. var min, max;
  1882. return function clampScalar( minVal, maxVal ) {
  1883. if ( min === undefined ) {
  1884. min = new THREE.Vector4();
  1885. max = new THREE.Vector4();
  1886. }
  1887. min.set( minVal, minVal, minVal, minVal );
  1888. max.set( maxVal, maxVal, maxVal, maxVal );
  1889. return this.clamp( min, max );
  1890. };
  1891. }(),
  1892. floor: function () {
  1893. this.x = Math.floor( this.x );
  1894. this.y = Math.floor( this.y );
  1895. this.z = Math.floor( this.z );
  1896. this.w = Math.floor( this.w );
  1897. return this;
  1898. },
  1899. ceil: function () {
  1900. this.x = Math.ceil( this.x );
  1901. this.y = Math.ceil( this.y );
  1902. this.z = Math.ceil( this.z );
  1903. this.w = Math.ceil( this.w );
  1904. return this;
  1905. },
  1906. round: function () {
  1907. this.x = Math.round( this.x );
  1908. this.y = Math.round( this.y );
  1909. this.z = Math.round( this.z );
  1910. this.w = Math.round( this.w );
  1911. return this;
  1912. },
  1913. roundToZero: function () {
  1914. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1915. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1916. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1917. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1918. return this;
  1919. },
  1920. negate: function () {
  1921. this.x = - this.x;
  1922. this.y = - this.y;
  1923. this.z = - this.z;
  1924. this.w = - this.w;
  1925. return this;
  1926. },
  1927. dot: function ( v ) {
  1928. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1929. },
  1930. lengthSq: function () {
  1931. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1932. },
  1933. length: function () {
  1934. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1935. },
  1936. lengthManhattan: function () {
  1937. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1938. },
  1939. normalize: function () {
  1940. return this.divideScalar( this.length() );
  1941. },
  1942. setLength: function ( l ) {
  1943. var oldLength = this.length();
  1944. if ( oldLength !== 0 && l !== oldLength ) {
  1945. this.multiplyScalar( l / oldLength );
  1946. }
  1947. return this;
  1948. },
  1949. lerp: function ( v, alpha ) {
  1950. this.x += ( v.x - this.x ) * alpha;
  1951. this.y += ( v.y - this.y ) * alpha;
  1952. this.z += ( v.z - this.z ) * alpha;
  1953. this.w += ( v.w - this.w ) * alpha;
  1954. return this;
  1955. },
  1956. lerpVectors: function ( v1, v2, alpha ) {
  1957. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1958. return this;
  1959. },
  1960. equals: function ( v ) {
  1961. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1962. },
  1963. fromArray: function ( array, offset ) {
  1964. if ( offset === undefined ) offset = 0;
  1965. this.x = array[ offset ];
  1966. this.y = array[ offset + 1 ];
  1967. this.z = array[ offset + 2 ];
  1968. this.w = array[ offset + 3 ];
  1969. return this;
  1970. },
  1971. toArray: function ( array, offset ) {
  1972. if ( array === undefined ) array = [];
  1973. if ( offset === undefined ) offset = 0;
  1974. array[ offset ] = this.x;
  1975. array[ offset + 1 ] = this.y;
  1976. array[ offset + 2 ] = this.z;
  1977. array[ offset + 3 ] = this.w;
  1978. return array;
  1979. },
  1980. fromAttribute: function ( attribute, index, offset ) {
  1981. if ( offset === undefined ) offset = 0;
  1982. index = index * attribute.itemSize + offset;
  1983. this.x = attribute.array[ index ];
  1984. this.y = attribute.array[ index + 1 ];
  1985. this.z = attribute.array[ index + 2 ];
  1986. this.w = attribute.array[ index + 3 ];
  1987. return this;
  1988. }
  1989. };
  1990. // File:src/math/Euler.js
  1991. /**
  1992. * @author mrdoob / http://mrdoob.com/
  1993. * @author WestLangley / http://github.com/WestLangley
  1994. * @author bhouston / http://clara.io
  1995. */
  1996. THREE.Euler = function ( x, y, z, order ) {
  1997. this._x = x || 0;
  1998. this._y = y || 0;
  1999. this._z = z || 0;
  2000. this._order = order || THREE.Euler.DefaultOrder;
  2001. };
  2002. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  2003. THREE.Euler.DefaultOrder = 'XYZ';
  2004. THREE.Euler.prototype = {
  2005. constructor: THREE.Euler,
  2006. get x () {
  2007. return this._x;
  2008. },
  2009. set x ( value ) {
  2010. this._x = value;
  2011. this.onChangeCallback();
  2012. },
  2013. get y () {
  2014. return this._y;
  2015. },
  2016. set y ( value ) {
  2017. this._y = value;
  2018. this.onChangeCallback();
  2019. },
  2020. get z () {
  2021. return this._z;
  2022. },
  2023. set z ( value ) {
  2024. this._z = value;
  2025. this.onChangeCallback();
  2026. },
  2027. get order () {
  2028. return this._order;
  2029. },
  2030. set order ( value ) {
  2031. this._order = value;
  2032. this.onChangeCallback();
  2033. },
  2034. set: function ( x, y, z, order ) {
  2035. this._x = x;
  2036. this._y = y;
  2037. this._z = z;
  2038. this._order = order || this._order;
  2039. this.onChangeCallback();
  2040. return this;
  2041. },
  2042. clone: function () {
  2043. return new this.constructor( this._x, this._y, this._z, this._order);
  2044. },
  2045. copy: function ( euler ) {
  2046. this._x = euler._x;
  2047. this._y = euler._y;
  2048. this._z = euler._z;
  2049. this._order = euler._order;
  2050. this.onChangeCallback();
  2051. return this;
  2052. },
  2053. setFromRotationMatrix: function ( m, order, update ) {
  2054. var clamp = THREE.Math.clamp;
  2055. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2056. var te = m.elements;
  2057. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2058. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2059. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2060. order = order || this._order;
  2061. if ( order === 'XYZ' ) {
  2062. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2063. if ( Math.abs( m13 ) < 0.99999 ) {
  2064. this._x = Math.atan2( - m23, m33 );
  2065. this._z = Math.atan2( - m12, m11 );
  2066. } else {
  2067. this._x = Math.atan2( m32, m22 );
  2068. this._z = 0;
  2069. }
  2070. } else if ( order === 'YXZ' ) {
  2071. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2072. if ( Math.abs( m23 ) < 0.99999 ) {
  2073. this._y = Math.atan2( m13, m33 );
  2074. this._z = Math.atan2( m21, m22 );
  2075. } else {
  2076. this._y = Math.atan2( - m31, m11 );
  2077. this._z = 0;
  2078. }
  2079. } else if ( order === 'ZXY' ) {
  2080. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2081. if ( Math.abs( m32 ) < 0.99999 ) {
  2082. this._y = Math.atan2( - m31, m33 );
  2083. this._z = Math.atan2( - m12, m22 );
  2084. } else {
  2085. this._y = 0;
  2086. this._z = Math.atan2( m21, m11 );
  2087. }
  2088. } else if ( order === 'ZYX' ) {
  2089. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2090. if ( Math.abs( m31 ) < 0.99999 ) {
  2091. this._x = Math.atan2( m32, m33 );
  2092. this._z = Math.atan2( m21, m11 );
  2093. } else {
  2094. this._x = 0;
  2095. this._z = Math.atan2( - m12, m22 );
  2096. }
  2097. } else if ( order === 'YZX' ) {
  2098. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2099. if ( Math.abs( m21 ) < 0.99999 ) {
  2100. this._x = Math.atan2( - m23, m22 );
  2101. this._y = Math.atan2( - m31, m11 );
  2102. } else {
  2103. this._x = 0;
  2104. this._y = Math.atan2( m13, m33 );
  2105. }
  2106. } else if ( order === 'XZY' ) {
  2107. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2108. if ( Math.abs( m12 ) < 0.99999 ) {
  2109. this._x = Math.atan2( m32, m22 );
  2110. this._y = Math.atan2( m13, m11 );
  2111. } else {
  2112. this._x = Math.atan2( - m23, m33 );
  2113. this._y = 0;
  2114. }
  2115. } else {
  2116. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2117. }
  2118. this._order = order;
  2119. if ( update !== false ) this.onChangeCallback();
  2120. return this;
  2121. },
  2122. setFromQuaternion: function () {
  2123. var matrix;
  2124. return function ( q, order, update ) {
  2125. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2126. matrix.makeRotationFromQuaternion( q );
  2127. this.setFromRotationMatrix( matrix, order, update );
  2128. return this;
  2129. };
  2130. }(),
  2131. setFromVector3: function ( v, order ) {
  2132. return this.set( v.x, v.y, v.z, order || this._order );
  2133. },
  2134. reorder: function () {
  2135. // WARNING: this discards revolution information -bhouston
  2136. var q = new THREE.Quaternion();
  2137. return function ( newOrder ) {
  2138. q.setFromEuler( this );
  2139. this.setFromQuaternion( q, newOrder );
  2140. };
  2141. }(),
  2142. equals: function ( euler ) {
  2143. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2144. },
  2145. fromArray: function ( array ) {
  2146. this._x = array[ 0 ];
  2147. this._y = array[ 1 ];
  2148. this._z = array[ 2 ];
  2149. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2150. this.onChangeCallback();
  2151. return this;
  2152. },
  2153. toArray: function ( array, offset ) {
  2154. if ( array === undefined ) array = [];
  2155. if ( offset === undefined ) offset = 0;
  2156. array[ offset ] = this._x;
  2157. array[ offset + 1 ] = this._y;
  2158. array[ offset + 2 ] = this._z;
  2159. array[ offset + 3 ] = this._order;
  2160. return array;
  2161. },
  2162. toVector3: function ( optionalResult ) {
  2163. if ( optionalResult ) {
  2164. return optionalResult.set( this._x, this._y, this._z );
  2165. } else {
  2166. return new THREE.Vector3( this._x, this._y, this._z );
  2167. }
  2168. },
  2169. onChange: function ( callback ) {
  2170. this.onChangeCallback = callback;
  2171. return this;
  2172. },
  2173. onChangeCallback: function () {}
  2174. };
  2175. // File:src/math/Line3.js
  2176. /**
  2177. * @author bhouston / http://clara.io
  2178. */
  2179. THREE.Line3 = function ( start, end ) {
  2180. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2181. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2182. };
  2183. THREE.Line3.prototype = {
  2184. constructor: THREE.Line3,
  2185. set: function ( start, end ) {
  2186. this.start.copy( start );
  2187. this.end.copy( end );
  2188. return this;
  2189. },
  2190. clone: function () {
  2191. return new this.constructor().copy( this );
  2192. },
  2193. copy: function ( line ) {
  2194. this.start.copy( line.start );
  2195. this.end.copy( line.end );
  2196. return this;
  2197. },
  2198. center: function ( optionalTarget ) {
  2199. var result = optionalTarget || new THREE.Vector3();
  2200. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2201. },
  2202. delta: function ( optionalTarget ) {
  2203. var result = optionalTarget || new THREE.Vector3();
  2204. return result.subVectors( this.end, this.start );
  2205. },
  2206. distanceSq: function () {
  2207. return this.start.distanceToSquared( this.end );
  2208. },
  2209. distance: function () {
  2210. return this.start.distanceTo( this.end );
  2211. },
  2212. at: function ( t, optionalTarget ) {
  2213. var result = optionalTarget || new THREE.Vector3();
  2214. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2215. },
  2216. closestPointToPointParameter: function () {
  2217. var startP = new THREE.Vector3();
  2218. var startEnd = new THREE.Vector3();
  2219. return function ( point, clampToLine ) {
  2220. startP.subVectors( point, this.start );
  2221. startEnd.subVectors( this.end, this.start );
  2222. var startEnd2 = startEnd.dot( startEnd );
  2223. var startEnd_startP = startEnd.dot( startP );
  2224. var t = startEnd_startP / startEnd2;
  2225. if ( clampToLine ) {
  2226. t = THREE.Math.clamp( t, 0, 1 );
  2227. }
  2228. return t;
  2229. };
  2230. }(),
  2231. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2232. var t = this.closestPointToPointParameter( point, clampToLine );
  2233. var result = optionalTarget || new THREE.Vector3();
  2234. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2235. },
  2236. applyMatrix4: function ( matrix ) {
  2237. this.start.applyMatrix4( matrix );
  2238. this.end.applyMatrix4( matrix );
  2239. return this;
  2240. },
  2241. equals: function ( line ) {
  2242. return line.start.equals( this.start ) && line.end.equals( this.end );
  2243. }
  2244. };
  2245. // File:src/math/Box2.js
  2246. /**
  2247. * @author bhouston / http://clara.io
  2248. */
  2249. THREE.Box2 = function ( min, max ) {
  2250. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2251. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2252. };
  2253. THREE.Box2.prototype = {
  2254. constructor: THREE.Box2,
  2255. set: function ( min, max ) {
  2256. this.min.copy( min );
  2257. this.max.copy( max );
  2258. return this;
  2259. },
  2260. setFromPoints: function ( points ) {
  2261. this.makeEmpty();
  2262. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2263. this.expandByPoint( points[ i ] )
  2264. }
  2265. return this;
  2266. },
  2267. setFromCenterAndSize: function () {
  2268. var v1 = new THREE.Vector2();
  2269. return function ( center, size ) {
  2270. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2271. this.min.copy( center ).sub( halfSize );
  2272. this.max.copy( center ).add( halfSize );
  2273. return this;
  2274. };
  2275. }(),
  2276. clone: function () {
  2277. return new this.constructor().copy( this );
  2278. },
  2279. copy: function ( box ) {
  2280. this.min.copy( box.min );
  2281. this.max.copy( box.max );
  2282. return this;
  2283. },
  2284. makeEmpty: function () {
  2285. this.min.x = this.min.y = Infinity;
  2286. this.max.x = this.max.y = - Infinity;
  2287. return this;
  2288. },
  2289. empty: function () {
  2290. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2291. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2292. },
  2293. center: function ( optionalTarget ) {
  2294. var result = optionalTarget || new THREE.Vector2();
  2295. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2296. },
  2297. size: function ( optionalTarget ) {
  2298. var result = optionalTarget || new THREE.Vector2();
  2299. return result.subVectors( this.max, this.min );
  2300. },
  2301. expandByPoint: function ( point ) {
  2302. this.min.min( point );
  2303. this.max.max( point );
  2304. return this;
  2305. },
  2306. expandByVector: function ( vector ) {
  2307. this.min.sub( vector );
  2308. this.max.add( vector );
  2309. return this;
  2310. },
  2311. expandByScalar: function ( scalar ) {
  2312. this.min.addScalar( - scalar );
  2313. this.max.addScalar( scalar );
  2314. return this;
  2315. },
  2316. containsPoint: function ( point ) {
  2317. if ( point.x < this.min.x || point.x > this.max.x ||
  2318. point.y < this.min.y || point.y > this.max.y ) {
  2319. return false;
  2320. }
  2321. return true;
  2322. },
  2323. containsBox: function ( box ) {
  2324. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2325. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2326. return true;
  2327. }
  2328. return false;
  2329. },
  2330. getParameter: function ( point, optionalTarget ) {
  2331. // This can potentially have a divide by zero if the box
  2332. // has a size dimension of 0.
  2333. var result = optionalTarget || new THREE.Vector2();
  2334. return result.set(
  2335. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2336. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2337. );
  2338. },
  2339. isIntersectionBox: function ( box ) {
  2340. // using 6 splitting planes to rule out intersections.
  2341. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2342. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2343. return false;
  2344. }
  2345. return true;
  2346. },
  2347. clampPoint: function ( point, optionalTarget ) {
  2348. var result = optionalTarget || new THREE.Vector2();
  2349. return result.copy( point ).clamp( this.min, this.max );
  2350. },
  2351. distanceToPoint: function () {
  2352. var v1 = new THREE.Vector2();
  2353. return function ( point ) {
  2354. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2355. return clampedPoint.sub( point ).length();
  2356. };
  2357. }(),
  2358. intersect: function ( box ) {
  2359. this.min.max( box.min );
  2360. this.max.min( box.max );
  2361. return this;
  2362. },
  2363. union: function ( box ) {
  2364. this.min.min( box.min );
  2365. this.max.max( box.max );
  2366. return this;
  2367. },
  2368. translate: function ( offset ) {
  2369. this.min.add( offset );
  2370. this.max.add( offset );
  2371. return this;
  2372. },
  2373. equals: function ( box ) {
  2374. return box.min.equals( this.min ) && box.max.equals( this.max );
  2375. }
  2376. };
  2377. // File:src/math/Box3.js
  2378. /**
  2379. * @author bhouston / http://clara.io
  2380. * @author WestLangley / http://github.com/WestLangley
  2381. */
  2382. THREE.Box3 = function ( min, max ) {
  2383. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2384. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2385. };
  2386. THREE.Box3.prototype = {
  2387. constructor: THREE.Box3,
  2388. set: function ( min, max ) {
  2389. this.min.copy( min );
  2390. this.max.copy( max );
  2391. return this;
  2392. },
  2393. setFromPoints: function ( points ) {
  2394. this.makeEmpty();
  2395. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2396. this.expandByPoint( points[ i ] );
  2397. }
  2398. return this;
  2399. },
  2400. setFromCenterAndSize: function () {
  2401. var v1 = new THREE.Vector3();
  2402. return function ( center, size ) {
  2403. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2404. this.min.copy( center ).sub( halfSize );
  2405. this.max.copy( center ).add( halfSize );
  2406. return this;
  2407. };
  2408. }(),
  2409. setFromObject: function () {
  2410. // Computes the world-axis-aligned bounding box of an object (including its children),
  2411. // accounting for both the object's, and children's, world transforms
  2412. var v1 = new THREE.Vector3();
  2413. return function ( object ) {
  2414. var scope = this;
  2415. object.updateMatrixWorld( true );
  2416. this.makeEmpty();
  2417. object.traverse( function ( node ) {
  2418. var geometry = node.geometry;
  2419. if ( geometry !== undefined ) {
  2420. if ( geometry instanceof THREE.Geometry ) {
  2421. var vertices = geometry.vertices;
  2422. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2423. v1.copy( vertices[ i ] );
  2424. v1.applyMatrix4( node.matrixWorld );
  2425. scope.expandByPoint( v1 );
  2426. }
  2427. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2428. var positions = geometry.attributes[ 'position' ].array;
  2429. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2430. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2431. v1.applyMatrix4( node.matrixWorld );
  2432. scope.expandByPoint( v1 );
  2433. }
  2434. }
  2435. }
  2436. } );
  2437. return this;
  2438. };
  2439. }(),
  2440. clone: function () {
  2441. return new this.constructor().copy( this );
  2442. },
  2443. copy: function ( box ) {
  2444. this.min.copy( box.min );
  2445. this.max.copy( box.max );
  2446. return this;
  2447. },
  2448. makeEmpty: function () {
  2449. this.min.x = this.min.y = this.min.z = Infinity;
  2450. this.max.x = this.max.y = this.max.z = - Infinity;
  2451. return this;
  2452. },
  2453. empty: function () {
  2454. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2455. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2456. },
  2457. center: function ( optionalTarget ) {
  2458. var result = optionalTarget || new THREE.Vector3();
  2459. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2460. },
  2461. size: function ( optionalTarget ) {
  2462. var result = optionalTarget || new THREE.Vector3();
  2463. return result.subVectors( this.max, this.min );
  2464. },
  2465. expandByPoint: function ( point ) {
  2466. this.min.min( point );
  2467. this.max.max( point );
  2468. return this;
  2469. },
  2470. expandByVector: function ( vector ) {
  2471. this.min.sub( vector );
  2472. this.max.add( vector );
  2473. return this;
  2474. },
  2475. expandByScalar: function ( scalar ) {
  2476. this.min.addScalar( - scalar );
  2477. this.max.addScalar( scalar );
  2478. return this;
  2479. },
  2480. containsPoint: function ( point ) {
  2481. if ( point.x < this.min.x || point.x > this.max.x ||
  2482. point.y < this.min.y || point.y > this.max.y ||
  2483. point.z < this.min.z || point.z > this.max.z ) {
  2484. return false;
  2485. }
  2486. return true;
  2487. },
  2488. containsBox: function ( box ) {
  2489. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2490. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2491. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2492. return true;
  2493. }
  2494. return false;
  2495. },
  2496. getParameter: function ( point, optionalTarget ) {
  2497. // This can potentially have a divide by zero if the box
  2498. // has a size dimension of 0.
  2499. var result = optionalTarget || new THREE.Vector3();
  2500. return result.set(
  2501. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2502. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2503. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2504. );
  2505. },
  2506. isIntersectionBox: function ( box ) {
  2507. // using 6 splitting planes to rule out intersections.
  2508. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2509. box.max.y < this.min.y || box.min.y > this.max.y ||
  2510. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2511. return false;
  2512. }
  2513. return true;
  2514. },
  2515. clampPoint: function ( point, optionalTarget ) {
  2516. var result = optionalTarget || new THREE.Vector3();
  2517. return result.copy( point ).clamp( this.min, this.max );
  2518. },
  2519. distanceToPoint: function () {
  2520. var v1 = new THREE.Vector3();
  2521. return function ( point ) {
  2522. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2523. return clampedPoint.sub( point ).length();
  2524. };
  2525. }(),
  2526. getBoundingSphere: function () {
  2527. var v1 = new THREE.Vector3();
  2528. return function ( optionalTarget ) {
  2529. var result = optionalTarget || new THREE.Sphere();
  2530. result.center = this.center();
  2531. result.radius = this.size( v1 ).length() * 0.5;
  2532. return result;
  2533. };
  2534. }(),
  2535. intersect: function ( box ) {
  2536. this.min.max( box.min );
  2537. this.max.min( box.max );
  2538. return this;
  2539. },
  2540. union: function ( box ) {
  2541. this.min.min( box.min );
  2542. this.max.max( box.max );
  2543. return this;
  2544. },
  2545. applyMatrix4: function () {
  2546. var points = [
  2547. new THREE.Vector3(),
  2548. new THREE.Vector3(),
  2549. new THREE.Vector3(),
  2550. new THREE.Vector3(),
  2551. new THREE.Vector3(),
  2552. new THREE.Vector3(),
  2553. new THREE.Vector3(),
  2554. new THREE.Vector3()
  2555. ];
  2556. return function ( matrix ) {
  2557. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2558. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2559. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2560. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2561. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2562. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2563. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2564. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2565. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2566. this.makeEmpty();
  2567. this.setFromPoints( points );
  2568. return this;
  2569. };
  2570. }(),
  2571. translate: function ( offset ) {
  2572. this.min.add( offset );
  2573. this.max.add( offset );
  2574. return this;
  2575. },
  2576. equals: function ( box ) {
  2577. return box.min.equals( this.min ) && box.max.equals( this.max );
  2578. }
  2579. };
  2580. // File:src/math/Matrix3.js
  2581. /**
  2582. * @author alteredq / http://alteredqualia.com/
  2583. * @author WestLangley / http://github.com/WestLangley
  2584. * @author bhouston / http://clara.io
  2585. */
  2586. THREE.Matrix3 = function () {
  2587. this.elements = new Float32Array( [
  2588. 1, 0, 0,
  2589. 0, 1, 0,
  2590. 0, 0, 1
  2591. ] );
  2592. if ( arguments.length > 0 ) {
  2593. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2594. }
  2595. };
  2596. THREE.Matrix3.prototype = {
  2597. constructor: THREE.Matrix3,
  2598. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2599. var te = this.elements;
  2600. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2601. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2602. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2603. return this;
  2604. },
  2605. identity: function () {
  2606. this.set(
  2607. 1, 0, 0,
  2608. 0, 1, 0,
  2609. 0, 0, 1
  2610. );
  2611. return this;
  2612. },
  2613. clone: function () {
  2614. return new this.constructor().fromArray( this.elements );
  2615. },
  2616. copy: function ( m ) {
  2617. var me = m.elements;
  2618. this.set(
  2619. me[ 0 ], me[ 3 ], me[ 6 ],
  2620. me[ 1 ], me[ 4 ], me[ 7 ],
  2621. me[ 2 ], me[ 5 ], me[ 8 ]
  2622. );
  2623. return this;
  2624. },
  2625. multiplyVector3: function ( vector ) {
  2626. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2627. return vector.applyMatrix3( this );
  2628. },
  2629. multiplyVector3Array: function ( a ) {
  2630. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2631. return this.applyToVector3Array( a );
  2632. },
  2633. applyToVector3Array: function () {
  2634. var v1;
  2635. return function ( array, offset, length ) {
  2636. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2637. if ( offset === undefined ) offset = 0;
  2638. if ( length === undefined ) length = array.length;
  2639. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2640. v1.fromArray( array, j );
  2641. v1.applyMatrix3( this );
  2642. v1.toArray( array, j );
  2643. }
  2644. return array;
  2645. };
  2646. }(),
  2647. applyToBuffer: function () {
  2648. var v1;
  2649. return function applyToBuffer( buffer, offset, length ) {
  2650. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2651. if ( offset === undefined ) offset = 0;
  2652. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2653. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2654. v1.x = buffer.getX( j );
  2655. v1.y = buffer.getY( j );
  2656. v1.z = buffer.getZ( j );
  2657. v1.applyMatrix3( this );
  2658. buffer.setXYZ( v1.x, v1.y, v1.z );
  2659. }
  2660. return buffer;
  2661. };
  2662. }(),
  2663. multiplyScalar: function ( s ) {
  2664. var te = this.elements;
  2665. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2666. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2667. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2668. return this;
  2669. },
  2670. determinant: function () {
  2671. var te = this.elements;
  2672. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2673. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2674. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2675. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2676. },
  2677. getInverse: function ( matrix, throwOnInvertible ) {
  2678. // input: THREE.Matrix4
  2679. // ( based on http://code.google.com/p/webgl-mjs/ )
  2680. var me = matrix.elements;
  2681. var te = this.elements;
  2682. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2683. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2684. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2685. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2686. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2687. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2688. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2689. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2690. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2691. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2692. // no inverse
  2693. if ( det === 0 ) {
  2694. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2695. if ( throwOnInvertible || false ) {
  2696. throw new Error( msg );
  2697. } else {
  2698. console.warn( msg );
  2699. }
  2700. this.identity();
  2701. return this;
  2702. }
  2703. this.multiplyScalar( 1.0 / det );
  2704. return this;
  2705. },
  2706. transpose: function () {
  2707. var tmp, m = this.elements;
  2708. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2709. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2710. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2711. return this;
  2712. },
  2713. flattenToArrayOffset: function ( array, offset ) {
  2714. var te = this.elements;
  2715. array[ offset ] = te[ 0 ];
  2716. array[ offset + 1 ] = te[ 1 ];
  2717. array[ offset + 2 ] = te[ 2 ];
  2718. array[ offset + 3 ] = te[ 3 ];
  2719. array[ offset + 4 ] = te[ 4 ];
  2720. array[ offset + 5 ] = te[ 5 ];
  2721. array[ offset + 6 ] = te[ 6 ];
  2722. array[ offset + 7 ] = te[ 7 ];
  2723. array[ offset + 8 ] = te[ 8 ];
  2724. return array;
  2725. },
  2726. getNormalMatrix: function ( m ) {
  2727. // input: THREE.Matrix4
  2728. this.getInverse( m ).transpose();
  2729. return this;
  2730. },
  2731. transposeIntoArray: function ( r ) {
  2732. var m = this.elements;
  2733. r[ 0 ] = m[ 0 ];
  2734. r[ 1 ] = m[ 3 ];
  2735. r[ 2 ] = m[ 6 ];
  2736. r[ 3 ] = m[ 1 ];
  2737. r[ 4 ] = m[ 4 ];
  2738. r[ 5 ] = m[ 7 ];
  2739. r[ 6 ] = m[ 2 ];
  2740. r[ 7 ] = m[ 5 ];
  2741. r[ 8 ] = m[ 8 ];
  2742. return this;
  2743. },
  2744. fromArray: function ( array ) {
  2745. this.elements.set( array );
  2746. return this;
  2747. },
  2748. toArray: function () {
  2749. var te = this.elements;
  2750. return [
  2751. te[ 0 ], te[ 1 ], te[ 2 ],
  2752. te[ 3 ], te[ 4 ], te[ 5 ],
  2753. te[ 6 ], te[ 7 ], te[ 8 ]
  2754. ];
  2755. }
  2756. };
  2757. // File:src/math/Matrix4.js
  2758. /**
  2759. * @author mrdoob / http://mrdoob.com/
  2760. * @author supereggbert / http://www.paulbrunt.co.uk/
  2761. * @author philogb / http://blog.thejit.org/
  2762. * @author jordi_ros / http://plattsoft.com
  2763. * @author D1plo1d / http://github.com/D1plo1d
  2764. * @author alteredq / http://alteredqualia.com/
  2765. * @author mikael emtinger / http://gomo.se/
  2766. * @author timknip / http://www.floorplanner.com/
  2767. * @author bhouston / http://clara.io
  2768. * @author WestLangley / http://github.com/WestLangley
  2769. */
  2770. THREE.Matrix4 = function () {
  2771. this.elements = new Float32Array( [
  2772. 1, 0, 0, 0,
  2773. 0, 1, 0, 0,
  2774. 0, 0, 1, 0,
  2775. 0, 0, 0, 1
  2776. ] );
  2777. if ( arguments.length > 0 ) {
  2778. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2779. }
  2780. };
  2781. THREE.Matrix4.prototype = {
  2782. constructor: THREE.Matrix4,
  2783. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2784. var te = this.elements;
  2785. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2786. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2787. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2788. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2789. return this;
  2790. },
  2791. identity: function () {
  2792. this.set(
  2793. 1, 0, 0, 0,
  2794. 0, 1, 0, 0,
  2795. 0, 0, 1, 0,
  2796. 0, 0, 0, 1
  2797. );
  2798. return this;
  2799. },
  2800. clone: function () {
  2801. return new THREE.Matrix4().fromArray( this.elements );
  2802. },
  2803. copy: function ( m ) {
  2804. this.elements.set( m.elements );
  2805. return this;
  2806. },
  2807. extractPosition: function ( m ) {
  2808. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2809. return this.copyPosition( m );
  2810. },
  2811. copyPosition: function ( m ) {
  2812. var te = this.elements;
  2813. var me = m.elements;
  2814. te[ 12 ] = me[ 12 ];
  2815. te[ 13 ] = me[ 13 ];
  2816. te[ 14 ] = me[ 14 ];
  2817. return this;
  2818. },
  2819. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2820. var te = this.elements;
  2821. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2822. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2823. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2824. return this;
  2825. },
  2826. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2827. this.set(
  2828. xAxis.x, yAxis.x, zAxis.x, 0,
  2829. xAxis.y, yAxis.y, zAxis.y, 0,
  2830. xAxis.z, yAxis.z, zAxis.z, 0,
  2831. 0, 0, 0, 1
  2832. );
  2833. return this;
  2834. },
  2835. extractRotation: function () {
  2836. var v1;
  2837. return function ( m ) {
  2838. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2839. var te = this.elements;
  2840. var me = m.elements;
  2841. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2842. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2843. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2844. te[ 0 ] = me[ 0 ] * scaleX;
  2845. te[ 1 ] = me[ 1 ] * scaleX;
  2846. te[ 2 ] = me[ 2 ] * scaleX;
  2847. te[ 4 ] = me[ 4 ] * scaleY;
  2848. te[ 5 ] = me[ 5 ] * scaleY;
  2849. te[ 6 ] = me[ 6 ] * scaleY;
  2850. te[ 8 ] = me[ 8 ] * scaleZ;
  2851. te[ 9 ] = me[ 9 ] * scaleZ;
  2852. te[ 10 ] = me[ 10 ] * scaleZ;
  2853. return this;
  2854. };
  2855. }(),
  2856. makeRotationFromEuler: function ( euler ) {
  2857. if ( euler instanceof THREE.Euler === false ) {
  2858. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2859. }
  2860. var te = this.elements;
  2861. var x = euler.x, y = euler.y, z = euler.z;
  2862. var a = Math.cos( x ), b = Math.sin( x );
  2863. var c = Math.cos( y ), d = Math.sin( y );
  2864. var e = Math.cos( z ), f = Math.sin( z );
  2865. if ( euler.order === 'XYZ' ) {
  2866. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2867. te[ 0 ] = c * e;
  2868. te[ 4 ] = - c * f;
  2869. te[ 8 ] = d;
  2870. te[ 1 ] = af + be * d;
  2871. te[ 5 ] = ae - bf * d;
  2872. te[ 9 ] = - b * c;
  2873. te[ 2 ] = bf - ae * d;
  2874. te[ 6 ] = be + af * d;
  2875. te[ 10 ] = a * c;
  2876. } else if ( euler.order === 'YXZ' ) {
  2877. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2878. te[ 0 ] = ce + df * b;
  2879. te[ 4 ] = de * b - cf;
  2880. te[ 8 ] = a * d;
  2881. te[ 1 ] = a * f;
  2882. te[ 5 ] = a * e;
  2883. te[ 9 ] = - b;
  2884. te[ 2 ] = cf * b - de;
  2885. te[ 6 ] = df + ce * b;
  2886. te[ 10 ] = a * c;
  2887. } else if ( euler.order === 'ZXY' ) {
  2888. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2889. te[ 0 ] = ce - df * b;
  2890. te[ 4 ] = - a * f;
  2891. te[ 8 ] = de + cf * b;
  2892. te[ 1 ] = cf + de * b;
  2893. te[ 5 ] = a * e;
  2894. te[ 9 ] = df - ce * b;
  2895. te[ 2 ] = - a * d;
  2896. te[ 6 ] = b;
  2897. te[ 10 ] = a * c;
  2898. } else if ( euler.order === 'ZYX' ) {
  2899. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2900. te[ 0 ] = c * e;
  2901. te[ 4 ] = be * d - af;
  2902. te[ 8 ] = ae * d + bf;
  2903. te[ 1 ] = c * f;
  2904. te[ 5 ] = bf * d + ae;
  2905. te[ 9 ] = af * d - be;
  2906. te[ 2 ] = - d;
  2907. te[ 6 ] = b * c;
  2908. te[ 10 ] = a * c;
  2909. } else if ( euler.order === 'YZX' ) {
  2910. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2911. te[ 0 ] = c * e;
  2912. te[ 4 ] = bd - ac * f;
  2913. te[ 8 ] = bc * f + ad;
  2914. te[ 1 ] = f;
  2915. te[ 5 ] = a * e;
  2916. te[ 9 ] = - b * e;
  2917. te[ 2 ] = - d * e;
  2918. te[ 6 ] = ad * f + bc;
  2919. te[ 10 ] = ac - bd * f;
  2920. } else if ( euler.order === 'XZY' ) {
  2921. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2922. te[ 0 ] = c * e;
  2923. te[ 4 ] = - f;
  2924. te[ 8 ] = d * e;
  2925. te[ 1 ] = ac * f + bd;
  2926. te[ 5 ] = a * e;
  2927. te[ 9 ] = ad * f - bc;
  2928. te[ 2 ] = bc * f - ad;
  2929. te[ 6 ] = b * e;
  2930. te[ 10 ] = bd * f + ac;
  2931. }
  2932. // last column
  2933. te[ 3 ] = 0;
  2934. te[ 7 ] = 0;
  2935. te[ 11 ] = 0;
  2936. // bottom row
  2937. te[ 12 ] = 0;
  2938. te[ 13 ] = 0;
  2939. te[ 14 ] = 0;
  2940. te[ 15 ] = 1;
  2941. return this;
  2942. },
  2943. setRotationFromQuaternion: function ( q ) {
  2944. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2945. return this.makeRotationFromQuaternion( q );
  2946. },
  2947. makeRotationFromQuaternion: function ( q ) {
  2948. var te = this.elements;
  2949. var x = q.x, y = q.y, z = q.z, w = q.w;
  2950. var x2 = x + x, y2 = y + y, z2 = z + z;
  2951. var xx = x * x2, xy = x * y2, xz = x * z2;
  2952. var yy = y * y2, yz = y * z2, zz = z * z2;
  2953. var wx = w * x2, wy = w * y2, wz = w * z2;
  2954. te[ 0 ] = 1 - ( yy + zz );
  2955. te[ 4 ] = xy - wz;
  2956. te[ 8 ] = xz + wy;
  2957. te[ 1 ] = xy + wz;
  2958. te[ 5 ] = 1 - ( xx + zz );
  2959. te[ 9 ] = yz - wx;
  2960. te[ 2 ] = xz - wy;
  2961. te[ 6 ] = yz + wx;
  2962. te[ 10 ] = 1 - ( xx + yy );
  2963. // last column
  2964. te[ 3 ] = 0;
  2965. te[ 7 ] = 0;
  2966. te[ 11 ] = 0;
  2967. // bottom row
  2968. te[ 12 ] = 0;
  2969. te[ 13 ] = 0;
  2970. te[ 14 ] = 0;
  2971. te[ 15 ] = 1;
  2972. return this;
  2973. },
  2974. lookAt: function () {
  2975. var x, y, z;
  2976. return function ( eye, target, up ) {
  2977. if ( x === undefined ) x = new THREE.Vector3();
  2978. if ( y === undefined ) y = new THREE.Vector3();
  2979. if ( z === undefined ) z = new THREE.Vector3();
  2980. var te = this.elements;
  2981. z.subVectors( eye, target ).normalize();
  2982. if ( z.length() === 0 ) {
  2983. z.z = 1;
  2984. }
  2985. x.crossVectors( up, z ).normalize();
  2986. if ( x.length() === 0 ) {
  2987. z.x += 0.0001;
  2988. x.crossVectors( up, z ).normalize();
  2989. }
  2990. y.crossVectors( z, x );
  2991. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2992. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2993. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2994. return this;
  2995. };
  2996. }(),
  2997. multiply: function ( m, n ) {
  2998. if ( n !== undefined ) {
  2999. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3000. return this.multiplyMatrices( m, n );
  3001. }
  3002. return this.multiplyMatrices( this, m );
  3003. },
  3004. multiplyMatrices: function ( a, b ) {
  3005. var ae = a.elements;
  3006. var be = b.elements;
  3007. var te = this.elements;
  3008. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3009. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3010. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3011. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3012. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3013. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3014. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3015. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3016. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3017. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3018. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3019. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3020. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3021. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3022. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3023. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3024. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3025. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3026. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3027. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3028. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3029. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3030. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3031. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3032. return this;
  3033. },
  3034. multiplyToArray: function ( a, b, r ) {
  3035. var te = this.elements;
  3036. this.multiplyMatrices( a, b );
  3037. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3038. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3039. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3040. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3041. return this;
  3042. },
  3043. multiplyScalar: function ( s ) {
  3044. var te = this.elements;
  3045. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3046. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3047. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3048. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3049. return this;
  3050. },
  3051. multiplyVector3: function ( vector ) {
  3052. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  3053. return vector.applyProjection( this );
  3054. },
  3055. multiplyVector4: function ( vector ) {
  3056. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3057. return vector.applyMatrix4( this );
  3058. },
  3059. multiplyVector3Array: function ( a ) {
  3060. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  3061. return this.applyToVector3Array( a );
  3062. },
  3063. applyToVector3Array: function () {
  3064. var v1;
  3065. return function ( array, offset, length ) {
  3066. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3067. if ( offset === undefined ) offset = 0;
  3068. if ( length === undefined ) length = array.length;
  3069. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3070. v1.fromArray( array, j );
  3071. v1.applyMatrix4( this );
  3072. v1.toArray( array, j );
  3073. }
  3074. return array;
  3075. };
  3076. }(),
  3077. applyToBuffer: function () {
  3078. var v1;
  3079. return function applyToBuffer( buffer, offset, length ) {
  3080. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3081. if ( offset === undefined ) offset = 0;
  3082. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3083. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3084. v1.x = buffer.getX( j );
  3085. v1.y = buffer.getY( j );
  3086. v1.z = buffer.getZ( j );
  3087. v1.applyMatrix4( this );
  3088. buffer.setXYZ( v1.x, v1.y, v1.z );
  3089. }
  3090. return buffer;
  3091. };
  3092. }(),
  3093. rotateAxis: function ( v ) {
  3094. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  3095. v.transformDirection( this );
  3096. },
  3097. crossVector: function ( vector ) {
  3098. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3099. return vector.applyMatrix4( this );
  3100. },
  3101. determinant: function () {
  3102. var te = this.elements;
  3103. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3104. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3105. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3106. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3107. //TODO: make this more efficient
  3108. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3109. return (
  3110. n41 * (
  3111. + n14 * n23 * n32
  3112. - n13 * n24 * n32
  3113. - n14 * n22 * n33
  3114. + n12 * n24 * n33
  3115. + n13 * n22 * n34
  3116. - n12 * n23 * n34
  3117. ) +
  3118. n42 * (
  3119. + n11 * n23 * n34
  3120. - n11 * n24 * n33
  3121. + n14 * n21 * n33
  3122. - n13 * n21 * n34
  3123. + n13 * n24 * n31
  3124. - n14 * n23 * n31
  3125. ) +
  3126. n43 * (
  3127. + n11 * n24 * n32
  3128. - n11 * n22 * n34
  3129. - n14 * n21 * n32
  3130. + n12 * n21 * n34
  3131. + n14 * n22 * n31
  3132. - n12 * n24 * n31
  3133. ) +
  3134. n44 * (
  3135. - n13 * n22 * n31
  3136. - n11 * n23 * n32
  3137. + n11 * n22 * n33
  3138. + n13 * n21 * n32
  3139. - n12 * n21 * n33
  3140. + n12 * n23 * n31
  3141. )
  3142. );
  3143. },
  3144. transpose: function () {
  3145. var te = this.elements;
  3146. var tmp;
  3147. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3148. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3149. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3150. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3151. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3152. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3153. return this;
  3154. },
  3155. flattenToArrayOffset: function ( array, offset ) {
  3156. var te = this.elements;
  3157. array[ offset ] = te[ 0 ];
  3158. array[ offset + 1 ] = te[ 1 ];
  3159. array[ offset + 2 ] = te[ 2 ];
  3160. array[ offset + 3 ] = te[ 3 ];
  3161. array[ offset + 4 ] = te[ 4 ];
  3162. array[ offset + 5 ] = te[ 5 ];
  3163. array[ offset + 6 ] = te[ 6 ];
  3164. array[ offset + 7 ] = te[ 7 ];
  3165. array[ offset + 8 ] = te[ 8 ];
  3166. array[ offset + 9 ] = te[ 9 ];
  3167. array[ offset + 10 ] = te[ 10 ];
  3168. array[ offset + 11 ] = te[ 11 ];
  3169. array[ offset + 12 ] = te[ 12 ];
  3170. array[ offset + 13 ] = te[ 13 ];
  3171. array[ offset + 14 ] = te[ 14 ];
  3172. array[ offset + 15 ] = te[ 15 ];
  3173. return array;
  3174. },
  3175. getPosition: function () {
  3176. var v1;
  3177. return function () {
  3178. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3179. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3180. var te = this.elements;
  3181. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3182. };
  3183. }(),
  3184. setPosition: function ( v ) {
  3185. var te = this.elements;
  3186. te[ 12 ] = v.x;
  3187. te[ 13 ] = v.y;
  3188. te[ 14 ] = v.z;
  3189. return this;
  3190. },
  3191. getInverse: function ( m, throwOnInvertible ) {
  3192. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3193. var te = this.elements;
  3194. var me = m.elements;
  3195. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3196. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3197. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3198. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3199. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3200. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3201. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3202. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3203. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3204. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3205. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3206. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3207. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3208. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3209. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3210. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3211. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3212. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3213. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3214. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3215. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3216. if ( det === 0 ) {
  3217. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3218. if ( throwOnInvertible || false ) {
  3219. throw new Error( msg );
  3220. } else {
  3221. console.warn( msg );
  3222. }
  3223. this.identity();
  3224. return this;
  3225. }
  3226. this.multiplyScalar( 1 / det );
  3227. return this;
  3228. },
  3229. translate: function ( v ) {
  3230. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3231. },
  3232. rotateX: function ( angle ) {
  3233. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3234. },
  3235. rotateY: function ( angle ) {
  3236. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3237. },
  3238. rotateZ: function ( angle ) {
  3239. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3240. },
  3241. rotateByAxis: function ( axis, angle ) {
  3242. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3243. },
  3244. scale: function ( v ) {
  3245. var te = this.elements;
  3246. var x = v.x, y = v.y, z = v.z;
  3247. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3248. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3249. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3250. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3251. return this;
  3252. },
  3253. getMaxScaleOnAxis: function () {
  3254. var te = this.elements;
  3255. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3256. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3257. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3258. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  3259. },
  3260. makeTranslation: function ( x, y, z ) {
  3261. this.set(
  3262. 1, 0, 0, x,
  3263. 0, 1, 0, y,
  3264. 0, 0, 1, z,
  3265. 0, 0, 0, 1
  3266. );
  3267. return this;
  3268. },
  3269. makeRotationX: function ( theta ) {
  3270. var c = Math.cos( theta ), s = Math.sin( theta );
  3271. this.set(
  3272. 1, 0, 0, 0,
  3273. 0, c, - s, 0,
  3274. 0, s, c, 0,
  3275. 0, 0, 0, 1
  3276. );
  3277. return this;
  3278. },
  3279. makeRotationY: function ( theta ) {
  3280. var c = Math.cos( theta ), s = Math.sin( theta );
  3281. this.set(
  3282. c, 0, s, 0,
  3283. 0, 1, 0, 0,
  3284. - s, 0, c, 0,
  3285. 0, 0, 0, 1
  3286. );
  3287. return this;
  3288. },
  3289. makeRotationZ: function ( theta ) {
  3290. var c = Math.cos( theta ), s = Math.sin( theta );
  3291. this.set(
  3292. c, - s, 0, 0,
  3293. s, c, 0, 0,
  3294. 0, 0, 1, 0,
  3295. 0, 0, 0, 1
  3296. );
  3297. return this;
  3298. },
  3299. makeRotationAxis: function ( axis, angle ) {
  3300. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3301. var c = Math.cos( angle );
  3302. var s = Math.sin( angle );
  3303. var t = 1 - c;
  3304. var x = axis.x, y = axis.y, z = axis.z;
  3305. var tx = t * x, ty = t * y;
  3306. this.set(
  3307. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3308. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3309. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3310. 0, 0, 0, 1
  3311. );
  3312. return this;
  3313. },
  3314. makeScale: function ( x, y, z ) {
  3315. this.set(
  3316. x, 0, 0, 0,
  3317. 0, y, 0, 0,
  3318. 0, 0, z, 0,
  3319. 0, 0, 0, 1
  3320. );
  3321. return this;
  3322. },
  3323. compose: function ( position, quaternion, scale ) {
  3324. this.makeRotationFromQuaternion( quaternion );
  3325. this.scale( scale );
  3326. this.setPosition( position );
  3327. return this;
  3328. },
  3329. decompose: function () {
  3330. var vector, matrix;
  3331. return function ( position, quaternion, scale ) {
  3332. if ( vector === undefined ) vector = new THREE.Vector3();
  3333. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3334. var te = this.elements;
  3335. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3336. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3337. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3338. // if determine is negative, we need to invert one scale
  3339. var det = this.determinant();
  3340. if ( det < 0 ) {
  3341. sx = - sx;
  3342. }
  3343. position.x = te[ 12 ];
  3344. position.y = te[ 13 ];
  3345. position.z = te[ 14 ];
  3346. // scale the rotation part
  3347. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3348. var invSX = 1 / sx;
  3349. var invSY = 1 / sy;
  3350. var invSZ = 1 / sz;
  3351. matrix.elements[ 0 ] *= invSX;
  3352. matrix.elements[ 1 ] *= invSX;
  3353. matrix.elements[ 2 ] *= invSX;
  3354. matrix.elements[ 4 ] *= invSY;
  3355. matrix.elements[ 5 ] *= invSY;
  3356. matrix.elements[ 6 ] *= invSY;
  3357. matrix.elements[ 8 ] *= invSZ;
  3358. matrix.elements[ 9 ] *= invSZ;
  3359. matrix.elements[ 10 ] *= invSZ;
  3360. quaternion.setFromRotationMatrix( matrix );
  3361. scale.x = sx;
  3362. scale.y = sy;
  3363. scale.z = sz;
  3364. return this;
  3365. };
  3366. }(),
  3367. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3368. var te = this.elements;
  3369. var x = 2 * near / ( right - left );
  3370. var y = 2 * near / ( top - bottom );
  3371. var a = ( right + left ) / ( right - left );
  3372. var b = ( top + bottom ) / ( top - bottom );
  3373. var c = - ( far + near ) / ( far - near );
  3374. var d = - 2 * far * near / ( far - near );
  3375. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3376. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3377. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3378. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3379. return this;
  3380. },
  3381. makePerspective: function ( fov, aspect, near, far ) {
  3382. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3383. var ymin = - ymax;
  3384. var xmin = ymin * aspect;
  3385. var xmax = ymax * aspect;
  3386. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3387. },
  3388. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3389. var te = this.elements;
  3390. var w = right - left;
  3391. var h = top - bottom;
  3392. var p = far - near;
  3393. var x = ( right + left ) / w;
  3394. var y = ( top + bottom ) / h;
  3395. var z = ( far + near ) / p;
  3396. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3397. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3398. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3399. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3400. return this;
  3401. },
  3402. equals: function ( matrix ) {
  3403. var te = this.elements;
  3404. var me = matrix.elements;
  3405. for ( var i = 0; i < 16; i ++ ) {
  3406. if ( te[ i ] !== me[ i ] ) return false;
  3407. }
  3408. return true;
  3409. },
  3410. fromArray: function ( array ) {
  3411. this.elements.set( array );
  3412. return this;
  3413. },
  3414. toArray: function () {
  3415. var te = this.elements;
  3416. return [
  3417. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3418. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3419. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3420. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3421. ];
  3422. }
  3423. };
  3424. // File:src/math/Ray.js
  3425. /**
  3426. * @author bhouston / http://clara.io
  3427. */
  3428. THREE.Ray = function ( origin, direction ) {
  3429. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3430. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3431. };
  3432. THREE.Ray.prototype = {
  3433. constructor: THREE.Ray,
  3434. set: function ( origin, direction ) {
  3435. this.origin.copy( origin );
  3436. this.direction.copy( direction );
  3437. return this;
  3438. },
  3439. clone: function () {
  3440. return new this.constructor().copy( this );
  3441. },
  3442. copy: function ( ray ) {
  3443. this.origin.copy( ray.origin );
  3444. this.direction.copy( ray.direction );
  3445. return this;
  3446. },
  3447. at: function ( t, optionalTarget ) {
  3448. var result = optionalTarget || new THREE.Vector3();
  3449. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3450. },
  3451. recast: function () {
  3452. var v1 = new THREE.Vector3();
  3453. return function ( t ) {
  3454. this.origin.copy( this.at( t, v1 ) );
  3455. return this;
  3456. };
  3457. }(),
  3458. closestPointToPoint: function ( point, optionalTarget ) {
  3459. var result = optionalTarget || new THREE.Vector3();
  3460. result.subVectors( point, this.origin );
  3461. var directionDistance = result.dot( this.direction );
  3462. if ( directionDistance < 0 ) {
  3463. return result.copy( this.origin );
  3464. }
  3465. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3466. },
  3467. distanceToPoint: function ( point ) {
  3468. return Math.sqrt( this.distanceSqToPoint( point ) );
  3469. },
  3470. distanceSqToPoint: function () {
  3471. var v1 = new THREE.Vector3();
  3472. return function ( point ) {
  3473. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3474. // point behind the ray
  3475. if ( directionDistance < 0 ) {
  3476. return this.origin.distanceToSquared( point );
  3477. }
  3478. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3479. return v1.distanceToSquared( point );
  3480. };
  3481. }(),
  3482. distanceSqToSegment: function () {
  3483. var segCenter = new THREE.Vector3();
  3484. var segDir = new THREE.Vector3();
  3485. var diff = new THREE.Vector3();
  3486. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3487. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3488. // It returns the min distance between the ray and the segment
  3489. // defined by v0 and v1
  3490. // It can also set two optional targets :
  3491. // - The closest point on the ray
  3492. // - The closest point on the segment
  3493. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3494. segDir.copy( v1 ).sub( v0 ).normalize();
  3495. diff.copy( this.origin ).sub( segCenter );
  3496. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3497. var a01 = - this.direction.dot( segDir );
  3498. var b0 = diff.dot( this.direction );
  3499. var b1 = - diff.dot( segDir );
  3500. var c = diff.lengthSq();
  3501. var det = Math.abs( 1 - a01 * a01 );
  3502. var s0, s1, sqrDist, extDet;
  3503. if ( det > 0 ) {
  3504. // The ray and segment are not parallel.
  3505. s0 = a01 * b1 - b0;
  3506. s1 = a01 * b0 - b1;
  3507. extDet = segExtent * det;
  3508. if ( s0 >= 0 ) {
  3509. if ( s1 >= - extDet ) {
  3510. if ( s1 <= extDet ) {
  3511. // region 0
  3512. // Minimum at interior points of ray and segment.
  3513. var invDet = 1 / det;
  3514. s0 *= invDet;
  3515. s1 *= invDet;
  3516. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3517. } else {
  3518. // region 1
  3519. s1 = segExtent;
  3520. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3521. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3522. }
  3523. } else {
  3524. // region 5
  3525. s1 = - segExtent;
  3526. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3527. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3528. }
  3529. } else {
  3530. if ( s1 <= - extDet ) {
  3531. // region 4
  3532. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3533. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3534. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3535. } else if ( s1 <= extDet ) {
  3536. // region 3
  3537. s0 = 0;
  3538. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3539. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3540. } else {
  3541. // region 2
  3542. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3543. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3544. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3545. }
  3546. }
  3547. } else {
  3548. // Ray and segment are parallel.
  3549. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3550. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3551. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3552. }
  3553. if ( optionalPointOnRay ) {
  3554. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3555. }
  3556. if ( optionalPointOnSegment ) {
  3557. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3558. }
  3559. return sqrDist;
  3560. };
  3561. }(),
  3562. isIntersectionSphere: function ( sphere ) {
  3563. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3564. },
  3565. intersectSphere: function () {
  3566. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3567. var v1 = new THREE.Vector3();
  3568. return function ( sphere, optionalTarget ) {
  3569. v1.subVectors( sphere.center, this.origin );
  3570. var tca = v1.dot( this.direction );
  3571. var d2 = v1.dot( v1 ) - tca * tca;
  3572. var radius2 = sphere.radius * sphere.radius;
  3573. if ( d2 > radius2 ) return null;
  3574. var thc = Math.sqrt( radius2 - d2 );
  3575. // t0 = first intersect point - entrance on front of sphere
  3576. var t0 = tca - thc;
  3577. // t1 = second intersect point - exit point on back of sphere
  3578. var t1 = tca + thc;
  3579. // test to see if both t0 and t1 are behind the ray - if so, return null
  3580. if ( t0 < 0 && t1 < 0 ) return null;
  3581. // test to see if t0 is behind the ray:
  3582. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3583. // in order to always return an intersect point that is in front of the ray.
  3584. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3585. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3586. return this.at( t0, optionalTarget );
  3587. }
  3588. }(),
  3589. isIntersectionPlane: function ( plane ) {
  3590. // check if the ray lies on the plane first
  3591. var distToPoint = plane.distanceToPoint( this.origin );
  3592. if ( distToPoint === 0 ) {
  3593. return true;
  3594. }
  3595. var denominator = plane.normal.dot( this.direction );
  3596. if ( denominator * distToPoint < 0 ) {
  3597. return true;
  3598. }
  3599. // ray origin is behind the plane (and is pointing behind it)
  3600. return false;
  3601. },
  3602. distanceToPlane: function ( plane ) {
  3603. var denominator = plane.normal.dot( this.direction );
  3604. if ( denominator === 0 ) {
  3605. // line is coplanar, return origin
  3606. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3607. return 0;
  3608. }
  3609. // Null is preferable to undefined since undefined means.... it is undefined
  3610. return null;
  3611. }
  3612. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3613. // Return if the ray never intersects the plane
  3614. return t >= 0 ? t : null;
  3615. },
  3616. intersectPlane: function ( plane, optionalTarget ) {
  3617. var t = this.distanceToPlane( plane );
  3618. if ( t === null ) {
  3619. return null;
  3620. }
  3621. return this.at( t, optionalTarget );
  3622. },
  3623. isIntersectionBox: function () {
  3624. var v = new THREE.Vector3();
  3625. return function ( box ) {
  3626. return this.intersectBox( box, v ) !== null;
  3627. };
  3628. }(),
  3629. intersectBox: function ( box, optionalTarget ) {
  3630. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3631. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3632. var invdirx = 1 / this.direction.x,
  3633. invdiry = 1 / this.direction.y,
  3634. invdirz = 1 / this.direction.z;
  3635. var origin = this.origin;
  3636. if ( invdirx >= 0 ) {
  3637. tmin = ( box.min.x - origin.x ) * invdirx;
  3638. tmax = ( box.max.x - origin.x ) * invdirx;
  3639. } else {
  3640. tmin = ( box.max.x - origin.x ) * invdirx;
  3641. tmax = ( box.min.x - origin.x ) * invdirx;
  3642. }
  3643. if ( invdiry >= 0 ) {
  3644. tymin = ( box.min.y - origin.y ) * invdiry;
  3645. tymax = ( box.max.y - origin.y ) * invdiry;
  3646. } else {
  3647. tymin = ( box.max.y - origin.y ) * invdiry;
  3648. tymax = ( box.min.y - origin.y ) * invdiry;
  3649. }
  3650. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3651. // These lines also handle the case where tmin or tmax is NaN
  3652. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3653. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3654. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3655. if ( invdirz >= 0 ) {
  3656. tzmin = ( box.min.z - origin.z ) * invdirz;
  3657. tzmax = ( box.max.z - origin.z ) * invdirz;
  3658. } else {
  3659. tzmin = ( box.max.z - origin.z ) * invdirz;
  3660. tzmax = ( box.min.z - origin.z ) * invdirz;
  3661. }
  3662. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3663. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3664. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3665. //return point closest to the ray (positive side)
  3666. if ( tmax < 0 ) return null;
  3667. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3668. },
  3669. intersectTriangle: function () {
  3670. // Compute the offset origin, edges, and normal.
  3671. var diff = new THREE.Vector3();
  3672. var edge1 = new THREE.Vector3();
  3673. var edge2 = new THREE.Vector3();
  3674. var normal = new THREE.Vector3();
  3675. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3676. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3677. edge1.subVectors( b, a );
  3678. edge2.subVectors( c, a );
  3679. normal.crossVectors( edge1, edge2 );
  3680. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3681. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3682. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3683. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3684. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3685. var DdN = this.direction.dot( normal );
  3686. var sign;
  3687. if ( DdN > 0 ) {
  3688. if ( backfaceCulling ) return null;
  3689. sign = 1;
  3690. } else if ( DdN < 0 ) {
  3691. sign = - 1;
  3692. DdN = - DdN;
  3693. } else {
  3694. return null;
  3695. }
  3696. diff.subVectors( this.origin, a );
  3697. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3698. // b1 < 0, no intersection
  3699. if ( DdQxE2 < 0 ) {
  3700. return null;
  3701. }
  3702. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3703. // b2 < 0, no intersection
  3704. if ( DdE1xQ < 0 ) {
  3705. return null;
  3706. }
  3707. // b1+b2 > 1, no intersection
  3708. if ( DdQxE2 + DdE1xQ > DdN ) {
  3709. return null;
  3710. }
  3711. // Line intersects triangle, check if ray does.
  3712. var QdN = - sign * diff.dot( normal );
  3713. // t < 0, no intersection
  3714. if ( QdN < 0 ) {
  3715. return null;
  3716. }
  3717. // Ray intersects triangle.
  3718. return this.at( QdN / DdN, optionalTarget );
  3719. };
  3720. }(),
  3721. applyMatrix4: function ( matrix4 ) {
  3722. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3723. this.origin.applyMatrix4( matrix4 );
  3724. this.direction.sub( this.origin );
  3725. this.direction.normalize();
  3726. return this;
  3727. },
  3728. equals: function ( ray ) {
  3729. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3730. }
  3731. };
  3732. // File:src/math/Sphere.js
  3733. /**
  3734. * @author bhouston / http://clara.io
  3735. * @author mrdoob / http://mrdoob.com/
  3736. */
  3737. THREE.Sphere = function ( center, radius ) {
  3738. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3739. this.radius = ( radius !== undefined ) ? radius : 0;
  3740. };
  3741. THREE.Sphere.prototype = {
  3742. constructor: THREE.Sphere,
  3743. set: function ( center, radius ) {
  3744. this.center.copy( center );
  3745. this.radius = radius;
  3746. return this;
  3747. },
  3748. setFromPoints: function () {
  3749. var box = new THREE.Box3();
  3750. return function ( points, optionalCenter ) {
  3751. var center = this.center;
  3752. if ( optionalCenter !== undefined ) {
  3753. center.copy( optionalCenter );
  3754. } else {
  3755. box.setFromPoints( points ).center( center );
  3756. }
  3757. var maxRadiusSq = 0;
  3758. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3759. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3760. }
  3761. this.radius = Math.sqrt( maxRadiusSq );
  3762. return this;
  3763. };
  3764. }(),
  3765. clone: function () {
  3766. return new this.constructor().copy( this );
  3767. },
  3768. copy: function ( sphere ) {
  3769. this.center.copy( sphere.center );
  3770. this.radius = sphere.radius;
  3771. return this;
  3772. },
  3773. empty: function () {
  3774. return ( this.radius <= 0 );
  3775. },
  3776. containsPoint: function ( point ) {
  3777. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3778. },
  3779. distanceToPoint: function ( point ) {
  3780. return ( point.distanceTo( this.center ) - this.radius );
  3781. },
  3782. intersectsSphere: function ( sphere ) {
  3783. var radiusSum = this.radius + sphere.radius;
  3784. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3785. },
  3786. clampPoint: function ( point, optionalTarget ) {
  3787. var deltaLengthSq = this.center.distanceToSquared( point );
  3788. var result = optionalTarget || new THREE.Vector3();
  3789. result.copy( point );
  3790. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3791. result.sub( this.center ).normalize();
  3792. result.multiplyScalar( this.radius ).add( this.center );
  3793. }
  3794. return result;
  3795. },
  3796. getBoundingBox: function ( optionalTarget ) {
  3797. var box = optionalTarget || new THREE.Box3();
  3798. box.set( this.center, this.center );
  3799. box.expandByScalar( this.radius );
  3800. return box;
  3801. },
  3802. applyMatrix4: function ( matrix ) {
  3803. this.center.applyMatrix4( matrix );
  3804. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3805. return this;
  3806. },
  3807. translate: function ( offset ) {
  3808. this.center.add( offset );
  3809. return this;
  3810. },
  3811. equals: function ( sphere ) {
  3812. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3813. }
  3814. };
  3815. // File:src/math/Frustum.js
  3816. /**
  3817. * @author mrdoob / http://mrdoob.com/
  3818. * @author alteredq / http://alteredqualia.com/
  3819. * @author bhouston / http://clara.io
  3820. */
  3821. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3822. this.planes = [
  3823. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3824. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3825. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3826. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3827. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3828. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3829. ];
  3830. };
  3831. THREE.Frustum.prototype = {
  3832. constructor: THREE.Frustum,
  3833. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3834. var planes = this.planes;
  3835. planes[ 0 ].copy( p0 );
  3836. planes[ 1 ].copy( p1 );
  3837. planes[ 2 ].copy( p2 );
  3838. planes[ 3 ].copy( p3 );
  3839. planes[ 4 ].copy( p4 );
  3840. planes[ 5 ].copy( p5 );
  3841. return this;
  3842. },
  3843. clone: function () {
  3844. return new this.constructor().copy( this );
  3845. },
  3846. copy: function ( frustum ) {
  3847. var planes = this.planes;
  3848. for ( var i = 0; i < 6; i ++ ) {
  3849. planes[ i ].copy( frustum.planes[ i ] );
  3850. }
  3851. return this;
  3852. },
  3853. setFromMatrix: function ( m ) {
  3854. var planes = this.planes;
  3855. var me = m.elements;
  3856. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3857. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3858. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3859. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3860. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3861. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3862. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3863. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3864. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3865. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3866. return this;
  3867. },
  3868. intersectsObject: function () {
  3869. var sphere = new THREE.Sphere();
  3870. return function ( object ) {
  3871. var geometry = object.geometry;
  3872. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3873. sphere.copy( geometry.boundingSphere );
  3874. sphere.applyMatrix4( object.matrixWorld );
  3875. return this.intersectsSphere( sphere );
  3876. };
  3877. }(),
  3878. intersectsSphere: function ( sphere ) {
  3879. var planes = this.planes;
  3880. var center = sphere.center;
  3881. var negRadius = - sphere.radius;
  3882. for ( var i = 0; i < 6; i ++ ) {
  3883. var distance = planes[ i ].distanceToPoint( center );
  3884. if ( distance < negRadius ) {
  3885. return false;
  3886. }
  3887. }
  3888. return true;
  3889. },
  3890. intersectsBox: function () {
  3891. var p1 = new THREE.Vector3(),
  3892. p2 = new THREE.Vector3();
  3893. return function ( box ) {
  3894. var planes = this.planes;
  3895. for ( var i = 0; i < 6 ; i ++ ) {
  3896. var plane = planes[ i ];
  3897. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3898. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3899. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3900. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3901. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3902. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3903. var d1 = plane.distanceToPoint( p1 );
  3904. var d2 = plane.distanceToPoint( p2 );
  3905. // if both outside plane, no intersection
  3906. if ( d1 < 0 && d2 < 0 ) {
  3907. return false;
  3908. }
  3909. }
  3910. return true;
  3911. };
  3912. }(),
  3913. containsPoint: function ( point ) {
  3914. var planes = this.planes;
  3915. for ( var i = 0; i < 6; i ++ ) {
  3916. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3917. return false;
  3918. }
  3919. }
  3920. return true;
  3921. }
  3922. };
  3923. // File:src/math/Plane.js
  3924. /**
  3925. * @author bhouston / http://clara.io
  3926. */
  3927. THREE.Plane = function ( normal, constant ) {
  3928. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3929. this.constant = ( constant !== undefined ) ? constant : 0;
  3930. };
  3931. THREE.Plane.prototype = {
  3932. constructor: THREE.Plane,
  3933. set: function ( normal, constant ) {
  3934. this.normal.copy( normal );
  3935. this.constant = constant;
  3936. return this;
  3937. },
  3938. setComponents: function ( x, y, z, w ) {
  3939. this.normal.set( x, y, z );
  3940. this.constant = w;
  3941. return this;
  3942. },
  3943. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3944. this.normal.copy( normal );
  3945. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3946. return this;
  3947. },
  3948. setFromCoplanarPoints: function () {
  3949. var v1 = new THREE.Vector3();
  3950. var v2 = new THREE.Vector3();
  3951. return function ( a, b, c ) {
  3952. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3953. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3954. this.setFromNormalAndCoplanarPoint( normal, a );
  3955. return this;
  3956. };
  3957. }(),
  3958. clone: function () {
  3959. return new this.constructor().copy( this );
  3960. },
  3961. copy: function ( plane ) {
  3962. this.normal.copy( plane.normal );
  3963. this.constant = plane.constant;
  3964. return this;
  3965. },
  3966. normalize: function () {
  3967. // Note: will lead to a divide by zero if the plane is invalid.
  3968. var inverseNormalLength = 1.0 / this.normal.length();
  3969. this.normal.multiplyScalar( inverseNormalLength );
  3970. this.constant *= inverseNormalLength;
  3971. return this;
  3972. },
  3973. negate: function () {
  3974. this.constant *= - 1;
  3975. this.normal.negate();
  3976. return this;
  3977. },
  3978. distanceToPoint: function ( point ) {
  3979. return this.normal.dot( point ) + this.constant;
  3980. },
  3981. distanceToSphere: function ( sphere ) {
  3982. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3983. },
  3984. projectPoint: function ( point, optionalTarget ) {
  3985. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3986. },
  3987. orthoPoint: function ( point, optionalTarget ) {
  3988. var perpendicularMagnitude = this.distanceToPoint( point );
  3989. var result = optionalTarget || new THREE.Vector3();
  3990. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3991. },
  3992. isIntersectionLine: function ( line ) {
  3993. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3994. var startSign = this.distanceToPoint( line.start );
  3995. var endSign = this.distanceToPoint( line.end );
  3996. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3997. },
  3998. intersectLine: function () {
  3999. var v1 = new THREE.Vector3();
  4000. return function ( line, optionalTarget ) {
  4001. var result = optionalTarget || new THREE.Vector3();
  4002. var direction = line.delta( v1 );
  4003. var denominator = this.normal.dot( direction );
  4004. if ( denominator === 0 ) {
  4005. // line is coplanar, return origin
  4006. if ( this.distanceToPoint( line.start ) === 0 ) {
  4007. return result.copy( line.start );
  4008. }
  4009. // Unsure if this is the correct method to handle this case.
  4010. return undefined;
  4011. }
  4012. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4013. if ( t < 0 || t > 1 ) {
  4014. return undefined;
  4015. }
  4016. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4017. };
  4018. }(),
  4019. coplanarPoint: function ( optionalTarget ) {
  4020. var result = optionalTarget || new THREE.Vector3();
  4021. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4022. },
  4023. applyMatrix4: function () {
  4024. var v1 = new THREE.Vector3();
  4025. var v2 = new THREE.Vector3();
  4026. var m1 = new THREE.Matrix3();
  4027. return function ( matrix, optionalNormalMatrix ) {
  4028. // compute new normal based on theory here:
  4029. // http://www.songho.ca/opengl/gl_normaltransform.html
  4030. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4031. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4032. var newCoplanarPoint = this.coplanarPoint( v2 );
  4033. newCoplanarPoint.applyMatrix4( matrix );
  4034. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4035. return this;
  4036. };
  4037. }(),
  4038. translate: function ( offset ) {
  4039. this.constant = this.constant - offset.dot( this.normal );
  4040. return this;
  4041. },
  4042. equals: function ( plane ) {
  4043. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4044. }
  4045. };
  4046. // File:src/math/Math.js
  4047. /**
  4048. * @author alteredq / http://alteredqualia.com/
  4049. * @author mrdoob / http://mrdoob.com/
  4050. */
  4051. THREE.Math = {
  4052. generateUUID: function () {
  4053. // http://www.broofa.com/Tools/Math.uuid.htm
  4054. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4055. var uuid = new Array( 36 );
  4056. var rnd = 0, r;
  4057. return function () {
  4058. for ( var i = 0; i < 36; i ++ ) {
  4059. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4060. uuid[ i ] = '-';
  4061. } else if ( i === 14 ) {
  4062. uuid[ i ] = '4';
  4063. } else {
  4064. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4065. r = rnd & 0xf;
  4066. rnd = rnd >> 4;
  4067. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4068. }
  4069. }
  4070. return uuid.join( '' );
  4071. };
  4072. }(),
  4073. // Clamp value to range <a, b>
  4074. clamp: function ( x, a, b ) {
  4075. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  4076. },
  4077. // Clamp value to range <a, inf)
  4078. clampBottom: function ( x, a ) {
  4079. return x < a ? a : x;
  4080. },
  4081. // compute euclidian modulo of m % n
  4082. // https://en.wikipedia.org/wiki/Modulo_operation
  4083. euclideanModulo: function ( n, m ) {
  4084. return ( ( n % m ) + m ) % m;
  4085. },
  4086. // Linear mapping from range <a1, a2> to range <b1, b2>
  4087. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4088. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4089. },
  4090. // http://en.wikipedia.org/wiki/Smoothstep
  4091. smoothstep: function ( x, min, max ) {
  4092. if ( x <= min ) return 0;
  4093. if ( x >= max ) return 1;
  4094. x = ( x - min ) / ( max - min );
  4095. return x * x * ( 3 - 2 * x );
  4096. },
  4097. smootherstep: function ( x, min, max ) {
  4098. if ( x <= min ) return 0;
  4099. if ( x >= max ) return 1;
  4100. x = ( x - min ) / ( max - min );
  4101. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4102. },
  4103. // Random float from <0, 1> with 16 bits of randomness
  4104. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4105. random16: function () {
  4106. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4107. },
  4108. // Random integer from <low, high> interval
  4109. randInt: function ( low, high ) {
  4110. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4111. },
  4112. // Random float from <low, high> interval
  4113. randFloat: function ( low, high ) {
  4114. return low + Math.random() * ( high - low );
  4115. },
  4116. // Random float from <-range/2, range/2> interval
  4117. randFloatSpread: function ( range ) {
  4118. return range * ( 0.5 - Math.random() );
  4119. },
  4120. degToRad: function () {
  4121. var degreeToRadiansFactor = Math.PI / 180;
  4122. return function ( degrees ) {
  4123. return degrees * degreeToRadiansFactor;
  4124. };
  4125. }(),
  4126. radToDeg: function () {
  4127. var radianToDegreesFactor = 180 / Math.PI;
  4128. return function ( radians ) {
  4129. return radians * radianToDegreesFactor;
  4130. };
  4131. }(),
  4132. isPowerOfTwo: function ( value ) {
  4133. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4134. },
  4135. nextPowerOfTwo: function ( value ) {
  4136. value --;
  4137. value |= value >> 1;
  4138. value |= value >> 2;
  4139. value |= value >> 4;
  4140. value |= value >> 8;
  4141. value |= value >> 16;
  4142. value ++;
  4143. return value;
  4144. }
  4145. };
  4146. // File:src/math/Spline.js
  4147. /**
  4148. * Spline from Tween.js, slightly optimized (and trashed)
  4149. * http://sole.github.com/tween.js/examples/05_spline.html
  4150. *
  4151. * @author mrdoob / http://mrdoob.com/
  4152. * @author alteredq / http://alteredqualia.com/
  4153. */
  4154. THREE.Spline = function ( points ) {
  4155. this.points = points;
  4156. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4157. point, intPoint, weight, w2, w3,
  4158. pa, pb, pc, pd;
  4159. this.initFromArray = function ( a ) {
  4160. this.points = [];
  4161. for ( var i = 0; i < a.length; i ++ ) {
  4162. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4163. }
  4164. };
  4165. this.getPoint = function ( k ) {
  4166. point = ( this.points.length - 1 ) * k;
  4167. intPoint = Math.floor( point );
  4168. weight = point - intPoint;
  4169. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4170. c[ 1 ] = intPoint;
  4171. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4172. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4173. pa = this.points[ c[ 0 ] ];
  4174. pb = this.points[ c[ 1 ] ];
  4175. pc = this.points[ c[ 2 ] ];
  4176. pd = this.points[ c[ 3 ] ];
  4177. w2 = weight * weight;
  4178. w3 = weight * w2;
  4179. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4180. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4181. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4182. return v3;
  4183. };
  4184. this.getControlPointsArray = function () {
  4185. var i, p, l = this.points.length,
  4186. coords = [];
  4187. for ( i = 0; i < l; i ++ ) {
  4188. p = this.points[ i ];
  4189. coords[ i ] = [ p.x, p.y, p.z ];
  4190. }
  4191. return coords;
  4192. };
  4193. // approximate length by summing linear segments
  4194. this.getLength = function ( nSubDivisions ) {
  4195. var i, index, nSamples, position,
  4196. point = 0, intPoint = 0, oldIntPoint = 0,
  4197. oldPosition = new THREE.Vector3(),
  4198. tmpVec = new THREE.Vector3(),
  4199. chunkLengths = [],
  4200. totalLength = 0;
  4201. // first point has 0 length
  4202. chunkLengths[ 0 ] = 0;
  4203. if ( ! nSubDivisions ) nSubDivisions = 100;
  4204. nSamples = this.points.length * nSubDivisions;
  4205. oldPosition.copy( this.points[ 0 ] );
  4206. for ( i = 1; i < nSamples; i ++ ) {
  4207. index = i / nSamples;
  4208. position = this.getPoint( index );
  4209. tmpVec.copy( position );
  4210. totalLength += tmpVec.distanceTo( oldPosition );
  4211. oldPosition.copy( position );
  4212. point = ( this.points.length - 1 ) * index;
  4213. intPoint = Math.floor( point );
  4214. if ( intPoint !== oldIntPoint ) {
  4215. chunkLengths[ intPoint ] = totalLength;
  4216. oldIntPoint = intPoint;
  4217. }
  4218. }
  4219. // last point ends with total length
  4220. chunkLengths[ chunkLengths.length ] = totalLength;
  4221. return { chunks: chunkLengths, total: totalLength };
  4222. };
  4223. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4224. var i, j,
  4225. index, indexCurrent, indexNext,
  4226. realDistance,
  4227. sampling, position,
  4228. newpoints = [],
  4229. tmpVec = new THREE.Vector3(),
  4230. sl = this.getLength();
  4231. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4232. for ( i = 1; i < this.points.length; i ++ ) {
  4233. //tmpVec.copy( this.points[ i - 1 ] );
  4234. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4235. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4236. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4237. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4238. indexNext = i / ( this.points.length - 1 );
  4239. for ( j = 1; j < sampling - 1; j ++ ) {
  4240. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4241. position = this.getPoint( index );
  4242. newpoints.push( tmpVec.copy( position ).clone() );
  4243. }
  4244. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4245. }
  4246. this.points = newpoints;
  4247. };
  4248. // Catmull-Rom
  4249. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4250. var v0 = ( p2 - p0 ) * 0.5,
  4251. v1 = ( p3 - p1 ) * 0.5;
  4252. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4253. }
  4254. };
  4255. // File:src/math/Triangle.js
  4256. /**
  4257. * @author bhouston / http://clara.io
  4258. * @author mrdoob / http://mrdoob.com/
  4259. */
  4260. THREE.Triangle = function ( a, b, c ) {
  4261. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4262. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4263. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4264. };
  4265. THREE.Triangle.normal = function () {
  4266. var v0 = new THREE.Vector3();
  4267. return function ( a, b, c, optionalTarget ) {
  4268. var result = optionalTarget || new THREE.Vector3();
  4269. result.subVectors( c, b );
  4270. v0.subVectors( a, b );
  4271. result.cross( v0 );
  4272. var resultLengthSq = result.lengthSq();
  4273. if ( resultLengthSq > 0 ) {
  4274. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4275. }
  4276. return result.set( 0, 0, 0 );
  4277. };
  4278. }();
  4279. // static/instance method to calculate barycentric coordinates
  4280. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4281. THREE.Triangle.barycoordFromPoint = function () {
  4282. var v0 = new THREE.Vector3();
  4283. var v1 = new THREE.Vector3();
  4284. var v2 = new THREE.Vector3();
  4285. return function ( point, a, b, c, optionalTarget ) {
  4286. v0.subVectors( c, a );
  4287. v1.subVectors( b, a );
  4288. v2.subVectors( point, a );
  4289. var dot00 = v0.dot( v0 );
  4290. var dot01 = v0.dot( v1 );
  4291. var dot02 = v0.dot( v2 );
  4292. var dot11 = v1.dot( v1 );
  4293. var dot12 = v1.dot( v2 );
  4294. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4295. var result = optionalTarget || new THREE.Vector3();
  4296. // collinear or singular triangle
  4297. if ( denom === 0 ) {
  4298. // arbitrary location outside of triangle?
  4299. // not sure if this is the best idea, maybe should be returning undefined
  4300. return result.set( - 2, - 1, - 1 );
  4301. }
  4302. var invDenom = 1 / denom;
  4303. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4304. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4305. // barycentric coordinates must always sum to 1
  4306. return result.set( 1 - u - v, v, u );
  4307. };
  4308. }();
  4309. THREE.Triangle.containsPoint = function () {
  4310. var v1 = new THREE.Vector3();
  4311. return function ( point, a, b, c ) {
  4312. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4313. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4314. };
  4315. }();
  4316. THREE.Triangle.prototype = {
  4317. constructor: THREE.Triangle,
  4318. set: function ( a, b, c ) {
  4319. this.a.copy( a );
  4320. this.b.copy( b );
  4321. this.c.copy( c );
  4322. return this;
  4323. },
  4324. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4325. this.a.copy( points[ i0 ] );
  4326. this.b.copy( points[ i1 ] );
  4327. this.c.copy( points[ i2 ] );
  4328. return this;
  4329. },
  4330. clone: function () {
  4331. return new this.constructor().copy( this );
  4332. },
  4333. copy: function ( triangle ) {
  4334. this.a.copy( triangle.a );
  4335. this.b.copy( triangle.b );
  4336. this.c.copy( triangle.c );
  4337. return this;
  4338. },
  4339. area: function () {
  4340. var v0 = new THREE.Vector3();
  4341. var v1 = new THREE.Vector3();
  4342. return function () {
  4343. v0.subVectors( this.c, this.b );
  4344. v1.subVectors( this.a, this.b );
  4345. return v0.cross( v1 ).length() * 0.5;
  4346. };
  4347. }(),
  4348. midpoint: function ( optionalTarget ) {
  4349. var result = optionalTarget || new THREE.Vector3();
  4350. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4351. },
  4352. normal: function ( optionalTarget ) {
  4353. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4354. },
  4355. plane: function ( optionalTarget ) {
  4356. var result = optionalTarget || new THREE.Plane();
  4357. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4358. },
  4359. barycoordFromPoint: function ( point, optionalTarget ) {
  4360. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4361. },
  4362. containsPoint: function ( point ) {
  4363. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4364. },
  4365. equals: function ( triangle ) {
  4366. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4367. }
  4368. };
  4369. // File:src/core/Clock.js
  4370. /**
  4371. * @author alteredq / http://alteredqualia.com/
  4372. */
  4373. THREE.Clock = function ( autoStart ) {
  4374. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4375. this.startTime = 0;
  4376. this.oldTime = 0;
  4377. this.elapsedTime = 0;
  4378. this.running = false;
  4379. };
  4380. THREE.Clock.prototype = {
  4381. constructor: THREE.Clock,
  4382. _now: function () {
  4383. return self.performance !== undefined && self.performance.now !== undefined
  4384. ? self.performance.now()
  4385. : Date.now();
  4386. },
  4387. start: function () {
  4388. this.startTime = this._now();
  4389. this.oldTime = this.startTime;
  4390. this.running = true;
  4391. },
  4392. stop: function () {
  4393. this.getElapsedTime();
  4394. this.running = false;
  4395. },
  4396. getElapsedTime: function () {
  4397. this.getDelta();
  4398. return this.elapsedTime;
  4399. },
  4400. getDelta: function () {
  4401. var diff = 0;
  4402. if ( this.autoStart && ! this.running ) {
  4403. this.start();
  4404. }
  4405. if ( this.running ) {
  4406. var newTime = this._now();
  4407. diff = 0.001 * ( newTime - this.oldTime );
  4408. this.oldTime = newTime;
  4409. this.elapsedTime += diff;
  4410. }
  4411. return diff;
  4412. }
  4413. };
  4414. // File:src/core/EventDispatcher.js
  4415. /**
  4416. * https://github.com/mrdoob/eventdispatcher.js/
  4417. */
  4418. THREE.EventDispatcher = function () {};
  4419. THREE.EventDispatcher.prototype = {
  4420. constructor: THREE.EventDispatcher,
  4421. apply: function ( object ) {
  4422. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4423. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4424. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4425. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4426. },
  4427. addEventListener: function ( type, listener ) {
  4428. if ( this._listeners === undefined ) this._listeners = {};
  4429. var listeners = this._listeners;
  4430. if ( listeners[ type ] === undefined ) {
  4431. listeners[ type ] = [];
  4432. }
  4433. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4434. listeners[ type ].push( listener );
  4435. }
  4436. },
  4437. hasEventListener: function ( type, listener ) {
  4438. if ( this._listeners === undefined ) return false;
  4439. var listeners = this._listeners;
  4440. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4441. return true;
  4442. }
  4443. return false;
  4444. },
  4445. removeEventListener: function ( type, listener ) {
  4446. if ( this._listeners === undefined ) return;
  4447. var listeners = this._listeners;
  4448. var listenerArray = listeners[ type ];
  4449. if ( listenerArray !== undefined ) {
  4450. var index = listenerArray.indexOf( listener );
  4451. if ( index !== - 1 ) {
  4452. listenerArray.splice( index, 1 );
  4453. }
  4454. }
  4455. },
  4456. dispatchEvent: function ( event ) {
  4457. if ( this._listeners === undefined ) return;
  4458. var listeners = this._listeners;
  4459. var listenerArray = listeners[ event.type ];
  4460. if ( listenerArray !== undefined ) {
  4461. event.target = this;
  4462. var array = [];
  4463. var length = listenerArray.length;
  4464. for ( var i = 0; i < length; i ++ ) {
  4465. array[ i ] = listenerArray[ i ];
  4466. }
  4467. for ( var i = 0; i < length; i ++ ) {
  4468. array[ i ].call( this, event );
  4469. }
  4470. }
  4471. }
  4472. };
  4473. // File:src/core/Raycaster.js
  4474. /**
  4475. * @author mrdoob / http://mrdoob.com/
  4476. * @author bhouston / http://clara.io/
  4477. * @author stephomi / http://stephaneginier.com/
  4478. */
  4479. ( function ( THREE ) {
  4480. THREE.Raycaster = function ( origin, direction, near, far ) {
  4481. this.ray = new THREE.Ray( origin, direction );
  4482. // direction is assumed to be normalized (for accurate distance calculations)
  4483. this.near = near || 0;
  4484. this.far = far || Infinity;
  4485. this.params = {
  4486. Mesh: {},
  4487. Line: {},
  4488. LOD: {},
  4489. Points: { threshold: 1 },
  4490. Sprite: {}
  4491. };
  4492. Object.defineProperties( this.params, {
  4493. PointCloud: {
  4494. get: function () {
  4495. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4496. return this.Points;
  4497. }
  4498. }
  4499. } );
  4500. };
  4501. function descSort( a, b ) {
  4502. return a.distance - b.distance;
  4503. }
  4504. var intersectObject = function ( object, raycaster, intersects, recursive ) {
  4505. if ( object.visible === false ) return;
  4506. object.raycast( raycaster, intersects );
  4507. if ( recursive === true ) {
  4508. var children = object.children;
  4509. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4510. intersectObject( children[ i ], raycaster, intersects, true );
  4511. }
  4512. }
  4513. };
  4514. //
  4515. THREE.Raycaster.prototype = {
  4516. constructor: THREE.Raycaster,
  4517. linePrecision: 1,
  4518. set: function ( origin, direction ) {
  4519. // direction is assumed to be normalized (for accurate distance calculations)
  4520. this.ray.set( origin, direction );
  4521. },
  4522. setFromCamera: function ( coords, camera ) {
  4523. if ( camera instanceof THREE.PerspectiveCamera ) {
  4524. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4525. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4526. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4527. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4528. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4529. } else {
  4530. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4531. }
  4532. },
  4533. intersectObject: function ( object, recursive ) {
  4534. var intersects = [];
  4535. intersectObject( object, this, intersects, recursive );
  4536. intersects.sort( descSort );
  4537. return intersects;
  4538. },
  4539. intersectObjects: function ( objects, recursive ) {
  4540. var intersects = [];
  4541. if ( Array.isArray( objects ) === false ) {
  4542. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4543. return intersects;
  4544. }
  4545. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4546. intersectObject( objects[ i ], this, intersects, recursive );
  4547. }
  4548. intersects.sort( descSort );
  4549. return intersects;
  4550. }
  4551. };
  4552. }( THREE ) );
  4553. // File:src/core/Object3D.js
  4554. /**
  4555. * @author mrdoob / http://mrdoob.com/
  4556. * @author mikael emtinger / http://gomo.se/
  4557. * @author alteredq / http://alteredqualia.com/
  4558. * @author WestLangley / http://github.com/WestLangley
  4559. * @author elephantatwork / www.elephantatwork.ch
  4560. */
  4561. THREE.Object3D = function () {
  4562. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4563. this.uuid = THREE.Math.generateUUID();
  4564. this.name = '';
  4565. this.type = 'Object3D';
  4566. this.parent = null;
  4567. this.children = [];
  4568. this.up = THREE.Object3D.DefaultUp.clone();
  4569. var position = new THREE.Vector3();
  4570. var rotation = new THREE.Euler();
  4571. var quaternion = new THREE.Quaternion();
  4572. var scale = new THREE.Vector3( 1, 1, 1 );
  4573. var onRotationChange = function () {
  4574. quaternion.setFromEuler( rotation, false );
  4575. };
  4576. var onQuaternionChange = function () {
  4577. rotation.setFromQuaternion( quaternion, undefined, false );
  4578. };
  4579. rotation.onChange( onRotationChange );
  4580. quaternion.onChange( onQuaternionChange );
  4581. Object.defineProperties( this, {
  4582. position: {
  4583. enumerable: true,
  4584. value: position
  4585. },
  4586. rotation: {
  4587. enumerable: true,
  4588. value: rotation
  4589. },
  4590. quaternion: {
  4591. enumerable: true,
  4592. value: quaternion
  4593. },
  4594. scale: {
  4595. enumerable: true,
  4596. value: scale
  4597. },
  4598. modelViewMatrix: {
  4599. value: new THREE.Matrix4()
  4600. },
  4601. normalMatrix: {
  4602. value: new THREE.Matrix3()
  4603. }
  4604. } );
  4605. this.rotationAutoUpdate = true;
  4606. this.matrix = new THREE.Matrix4();
  4607. this.matrixWorld = new THREE.Matrix4();
  4608. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  4609. this.matrixWorldNeedsUpdate = false;
  4610. this.visible = true;
  4611. this.castShadow = false;
  4612. this.receiveShadow = false;
  4613. this.frustumCulled = true;
  4614. this.renderOrder = 0;
  4615. this.userData = {};
  4616. };
  4617. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4618. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  4619. THREE.Object3D.prototype = {
  4620. constructor: THREE.Object3D,
  4621. get eulerOrder () {
  4622. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4623. return this.rotation.order;
  4624. },
  4625. set eulerOrder ( value ) {
  4626. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4627. this.rotation.order = value;
  4628. },
  4629. get useQuaternion () {
  4630. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4631. },
  4632. set useQuaternion ( value ) {
  4633. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4634. },
  4635. set renderDepth ( value ) {
  4636. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  4637. },
  4638. applyMatrix: function ( matrix ) {
  4639. this.matrix.multiplyMatrices( matrix, this.matrix );
  4640. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4641. },
  4642. setRotationFromAxisAngle: function ( axis, angle ) {
  4643. // assumes axis is normalized
  4644. this.quaternion.setFromAxisAngle( axis, angle );
  4645. },
  4646. setRotationFromEuler: function ( euler ) {
  4647. this.quaternion.setFromEuler( euler, true );
  4648. },
  4649. setRotationFromMatrix: function ( m ) {
  4650. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4651. this.quaternion.setFromRotationMatrix( m );
  4652. },
  4653. setRotationFromQuaternion: function ( q ) {
  4654. // assumes q is normalized
  4655. this.quaternion.copy( q );
  4656. },
  4657. rotateOnAxis: function () {
  4658. // rotate object on axis in object space
  4659. // axis is assumed to be normalized
  4660. var q1 = new THREE.Quaternion();
  4661. return function ( axis, angle ) {
  4662. q1.setFromAxisAngle( axis, angle );
  4663. this.quaternion.multiply( q1 );
  4664. return this;
  4665. };
  4666. }(),
  4667. rotateX: function () {
  4668. var v1 = new THREE.Vector3( 1, 0, 0 );
  4669. return function ( angle ) {
  4670. return this.rotateOnAxis( v1, angle );
  4671. };
  4672. }(),
  4673. rotateY: function () {
  4674. var v1 = new THREE.Vector3( 0, 1, 0 );
  4675. return function ( angle ) {
  4676. return this.rotateOnAxis( v1, angle );
  4677. };
  4678. }(),
  4679. rotateZ: function () {
  4680. var v1 = new THREE.Vector3( 0, 0, 1 );
  4681. return function ( angle ) {
  4682. return this.rotateOnAxis( v1, angle );
  4683. };
  4684. }(),
  4685. translateOnAxis: function () {
  4686. // translate object by distance along axis in object space
  4687. // axis is assumed to be normalized
  4688. var v1 = new THREE.Vector3();
  4689. return function ( axis, distance ) {
  4690. v1.copy( axis ).applyQuaternion( this.quaternion );
  4691. this.position.add( v1.multiplyScalar( distance ) );
  4692. return this;
  4693. };
  4694. }(),
  4695. translate: function ( distance, axis ) {
  4696. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4697. return this.translateOnAxis( axis, distance );
  4698. },
  4699. translateX: function () {
  4700. var v1 = new THREE.Vector3( 1, 0, 0 );
  4701. return function ( distance ) {
  4702. return this.translateOnAxis( v1, distance );
  4703. };
  4704. }(),
  4705. translateY: function () {
  4706. var v1 = new THREE.Vector3( 0, 1, 0 );
  4707. return function ( distance ) {
  4708. return this.translateOnAxis( v1, distance );
  4709. };
  4710. }(),
  4711. translateZ: function () {
  4712. var v1 = new THREE.Vector3( 0, 0, 1 );
  4713. return function ( distance ) {
  4714. return this.translateOnAxis( v1, distance );
  4715. };
  4716. }(),
  4717. localToWorld: function ( vector ) {
  4718. return vector.applyMatrix4( this.matrixWorld );
  4719. },
  4720. worldToLocal: function () {
  4721. var m1 = new THREE.Matrix4();
  4722. return function ( vector ) {
  4723. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4724. };
  4725. }(),
  4726. lookAt: function () {
  4727. // This routine does not support objects with rotated and/or translated parent(s)
  4728. var m1 = new THREE.Matrix4();
  4729. return function ( vector ) {
  4730. m1.lookAt( vector, this.position, this.up );
  4731. this.quaternion.setFromRotationMatrix( m1 );
  4732. };
  4733. }(),
  4734. add: function ( object ) {
  4735. if ( arguments.length > 1 ) {
  4736. for ( var i = 0; i < arguments.length; i ++ ) {
  4737. this.add( arguments[ i ] );
  4738. }
  4739. return this;
  4740. }
  4741. if ( object === this ) {
  4742. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4743. return this;
  4744. }
  4745. if ( object instanceof THREE.Object3D ) {
  4746. if ( object.parent !== null ) {
  4747. object.parent.remove( object );
  4748. }
  4749. object.parent = this;
  4750. object.dispatchEvent( { type: 'added' } );
  4751. this.children.push( object );
  4752. } else {
  4753. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4754. }
  4755. return this;
  4756. },
  4757. remove: function ( object ) {
  4758. if ( arguments.length > 1 ) {
  4759. for ( var i = 0; i < arguments.length; i ++ ) {
  4760. this.remove( arguments[ i ] );
  4761. }
  4762. }
  4763. var index = this.children.indexOf( object );
  4764. if ( index !== - 1 ) {
  4765. object.parent = null;
  4766. object.dispatchEvent( { type: 'removed' } );
  4767. this.children.splice( index, 1 );
  4768. }
  4769. },
  4770. getChildByName: function ( name ) {
  4771. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4772. return this.getObjectByName( name );
  4773. },
  4774. getObjectById: function ( id ) {
  4775. return this.getObjectByProperty( 'id', id );
  4776. },
  4777. getObjectByName: function ( name ) {
  4778. return this.getObjectByProperty( 'name', name );
  4779. },
  4780. getObjectByProperty: function ( name, value ) {
  4781. if ( this[ name ] === value ) return this;
  4782. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4783. var child = this.children[ i ];
  4784. var object = child.getObjectByProperty( name, value );
  4785. if ( object !== undefined ) {
  4786. return object;
  4787. }
  4788. }
  4789. return undefined;
  4790. },
  4791. getWorldPosition: function ( optionalTarget ) {
  4792. var result = optionalTarget || new THREE.Vector3();
  4793. this.updateMatrixWorld( true );
  4794. return result.setFromMatrixPosition( this.matrixWorld );
  4795. },
  4796. getWorldQuaternion: function () {
  4797. var position = new THREE.Vector3();
  4798. var scale = new THREE.Vector3();
  4799. return function ( optionalTarget ) {
  4800. var result = optionalTarget || new THREE.Quaternion();
  4801. this.updateMatrixWorld( true );
  4802. this.matrixWorld.decompose( position, result, scale );
  4803. return result;
  4804. };
  4805. }(),
  4806. getWorldRotation: function () {
  4807. var quaternion = new THREE.Quaternion();
  4808. return function ( optionalTarget ) {
  4809. var result = optionalTarget || new THREE.Euler();
  4810. this.getWorldQuaternion( quaternion );
  4811. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4812. };
  4813. }(),
  4814. getWorldScale: function () {
  4815. var position = new THREE.Vector3();
  4816. var quaternion = new THREE.Quaternion();
  4817. return function ( optionalTarget ) {
  4818. var result = optionalTarget || new THREE.Vector3();
  4819. this.updateMatrixWorld( true );
  4820. this.matrixWorld.decompose( position, quaternion, result );
  4821. return result;
  4822. };
  4823. }(),
  4824. getWorldDirection: function () {
  4825. var quaternion = new THREE.Quaternion();
  4826. return function ( optionalTarget ) {
  4827. var result = optionalTarget || new THREE.Vector3();
  4828. this.getWorldQuaternion( quaternion );
  4829. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4830. };
  4831. }(),
  4832. raycast: function () {},
  4833. traverse: function ( callback ) {
  4834. callback( this );
  4835. var children = this.children;
  4836. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4837. children[ i ].traverse( callback );
  4838. }
  4839. },
  4840. traverseVisible: function ( callback ) {
  4841. if ( this.visible === false ) return;
  4842. callback( this );
  4843. var children = this.children;
  4844. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4845. children[ i ].traverseVisible( callback );
  4846. }
  4847. },
  4848. traverseAncestors: function ( callback ) {
  4849. var parent = this.parent;
  4850. if ( parent !== null ) {
  4851. callback( parent );
  4852. parent.traverseAncestors( callback );
  4853. }
  4854. },
  4855. updateMatrix: function () {
  4856. this.matrix.compose( this.position, this.quaternion, this.scale );
  4857. this.matrixWorldNeedsUpdate = true;
  4858. },
  4859. updateMatrixWorld: function ( force ) {
  4860. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4861. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4862. if ( this.parent === null ) {
  4863. this.matrixWorld.copy( this.matrix );
  4864. } else {
  4865. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4866. }
  4867. this.matrixWorldNeedsUpdate = false;
  4868. force = true;
  4869. }
  4870. // update children
  4871. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4872. this.children[ i ].updateMatrixWorld( force );
  4873. }
  4874. },
  4875. toJSON: function ( meta ) {
  4876. var isRootObject = ( meta === undefined );
  4877. var data = {};
  4878. var output = { object: data };
  4879. // meta is a hash used to collect geometries, materials.
  4880. // not providing it implies that this is the root object
  4881. // being serialized.
  4882. if ( isRootObject ) {
  4883. // initialize meta obj
  4884. meta = {
  4885. geometries: {},
  4886. materials: {},
  4887. textures: {},
  4888. images: {}
  4889. };
  4890. output.metadata = {
  4891. version: 4.4,
  4892. type: 'Object',
  4893. generator: 'Object3D.toJSON'
  4894. };
  4895. }
  4896. // standard Object3D serialization
  4897. data.uuid = this.uuid;
  4898. data.type = this.type;
  4899. if ( this.name !== '' ) data.name = this.name;
  4900. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4901. if ( this.visible !== true ) data.visible = this.visible;
  4902. data.matrix = this.matrix.toArray();
  4903. if ( this.children.length > 0 ) {
  4904. data.children = [];
  4905. for ( var i = 0; i < this.children.length; i ++ ) {
  4906. data.children.push( this.children[ i ].toJSON( meta ).object );
  4907. }
  4908. }
  4909. if ( isRootObject ) {
  4910. var geometries = extractFromCache( meta.geometries );
  4911. var materials = extractFromCache( meta.materials );
  4912. var textures = extractFromCache( meta.textures );
  4913. var images = extractFromCache( meta.images );
  4914. if ( geometries.length > 0 ) output.geometries = geometries;
  4915. if ( materials.length > 0 ) output.materials = materials;
  4916. if ( textures.length > 0 ) output.textures = textures;
  4917. if ( images.length > 0 ) output.images = images;
  4918. }
  4919. return output;
  4920. // extract data from the cache hash
  4921. // remove metadata on each item
  4922. // and return as array
  4923. function extractFromCache ( cache ) {
  4924. var values = [];
  4925. for ( var key in cache ) {
  4926. var data = cache[ key ];
  4927. delete data.metadata;
  4928. values.push( data );
  4929. }
  4930. return values;
  4931. }
  4932. },
  4933. clone: function ( recursive ) {
  4934. return new this.constructor().copy( this, recursive );
  4935. },
  4936. copy: function ( source, recursive ) {
  4937. if ( recursive === undefined ) recursive = true;
  4938. this.name = source.name;
  4939. this.up.copy( source.up );
  4940. this.position.copy( source.position );
  4941. this.quaternion.copy( source.quaternion );
  4942. this.scale.copy( source.scale );
  4943. this.rotationAutoUpdate = source.rotationAutoUpdate;
  4944. this.matrix.copy( source.matrix );
  4945. this.matrixWorld.copy( source.matrixWorld );
  4946. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4947. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4948. this.visible = source.visible;
  4949. this.castShadow = source.castShadow;
  4950. this.receiveShadow = source.receiveShadow;
  4951. this.frustumCulled = source.frustumCulled;
  4952. this.renderOrder = source.renderOrder;
  4953. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4954. if ( recursive === true ) {
  4955. for ( var i = 0; i < source.children.length; i ++ ) {
  4956. var child = source.children[ i ];
  4957. this.add( child.clone() );
  4958. }
  4959. }
  4960. return this;
  4961. }
  4962. };
  4963. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4964. THREE.Object3DIdCount = 0;
  4965. // File:src/core/Face3.js
  4966. /**
  4967. * @author mrdoob / http://mrdoob.com/
  4968. * @author alteredq / http://alteredqualia.com/
  4969. */
  4970. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  4971. this.a = a;
  4972. this.b = b;
  4973. this.c = c;
  4974. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  4975. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4976. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  4977. this.vertexColors = Array.isArray( color ) ? color : [];
  4978. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4979. };
  4980. THREE.Face3.prototype = {
  4981. constructor: THREE.Face3,
  4982. clone: function () {
  4983. return new this.constructor().copy( this );
  4984. },
  4985. copy: function ( source ) {
  4986. this.a = source.a;
  4987. this.b = source.b;
  4988. this.c = source.c;
  4989. this.normal.copy( source.normal );
  4990. this.color.copy( source.color );
  4991. this.materialIndex = source.materialIndex;
  4992. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4993. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4994. }
  4995. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4996. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4997. }
  4998. return this;
  4999. }
  5000. };
  5001. // File:src/core/Face4.js
  5002. /**
  5003. * @author mrdoob / http://mrdoob.com/
  5004. */
  5005. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  5006. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  5007. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  5008. };
  5009. // File:src/core/BufferAttribute.js
  5010. /**
  5011. * @author mrdoob / http://mrdoob.com/
  5012. */
  5013. THREE.BufferAttribute = function ( array, itemSize ) {
  5014. this.uuid = THREE.Math.generateUUID();
  5015. this.array = array;
  5016. this.itemSize = itemSize;
  5017. this.dynamic = false;
  5018. this.updateRange = { offset: 0, count: - 1 };
  5019. this.version = 0;
  5020. };
  5021. THREE.BufferAttribute.prototype = {
  5022. constructor: THREE.BufferAttribute,
  5023. get length() {
  5024. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5025. return this.array.length;
  5026. },
  5027. get count() {
  5028. return this.array.length / this.itemSize;
  5029. },
  5030. set needsUpdate( value ) {
  5031. if ( value === true ) this.version ++;
  5032. },
  5033. setDynamic: function ( value ) {
  5034. this.dynamic = value;
  5035. return this;
  5036. },
  5037. copy: function ( source ) {
  5038. this.array = new source.array.constructor( source.array );
  5039. this.itemSize = source.itemSize;
  5040. this.dynamic = source.dynamic;
  5041. return this;
  5042. },
  5043. copyAt: function ( index1, attribute, index2 ) {
  5044. index1 *= this.itemSize;
  5045. index2 *= attribute.itemSize;
  5046. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5047. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5048. }
  5049. return this;
  5050. },
  5051. copyArray: function ( array ) {
  5052. this.array.set( array );
  5053. return this;
  5054. },
  5055. copyColorsArray: function ( colors ) {
  5056. var array = this.array, offset = 0;
  5057. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5058. var color = colors[ i ];
  5059. if ( color === undefined ) {
  5060. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5061. color = new THREE.Color();
  5062. }
  5063. array[ offset ++ ] = color.r;
  5064. array[ offset ++ ] = color.g;
  5065. array[ offset ++ ] = color.b;
  5066. }
  5067. return this;
  5068. },
  5069. copyIndicesArray: function ( indices ) {
  5070. var array = this.array, offset = 0;
  5071. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5072. var index = indices[ i ];
  5073. array[ offset ++ ] = index.a;
  5074. array[ offset ++ ] = index.b;
  5075. array[ offset ++ ] = index.c;
  5076. }
  5077. return this;
  5078. },
  5079. copyVector2sArray: function ( vectors ) {
  5080. var array = this.array, offset = 0;
  5081. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5082. var vector = vectors[ i ];
  5083. if ( vector === undefined ) {
  5084. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5085. vector = new THREE.Vector2();
  5086. }
  5087. array[ offset ++ ] = vector.x;
  5088. array[ offset ++ ] = vector.y;
  5089. }
  5090. return this;
  5091. },
  5092. copyVector3sArray: function ( vectors ) {
  5093. var array = this.array, offset = 0;
  5094. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5095. var vector = vectors[ i ];
  5096. if ( vector === undefined ) {
  5097. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5098. vector = new THREE.Vector3();
  5099. }
  5100. array[ offset ++ ] = vector.x;
  5101. array[ offset ++ ] = vector.y;
  5102. array[ offset ++ ] = vector.z;
  5103. }
  5104. return this;
  5105. },
  5106. copyVector4sArray: function ( vectors ) {
  5107. var array = this.array, offset = 0;
  5108. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5109. var vector = vectors[ i ];
  5110. if ( vector === undefined ) {
  5111. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5112. vector = new THREE.Vector4();
  5113. }
  5114. array[ offset ++ ] = vector.x;
  5115. array[ offset ++ ] = vector.y;
  5116. array[ offset ++ ] = vector.z;
  5117. array[ offset ++ ] = vector.w;
  5118. }
  5119. return this;
  5120. },
  5121. set: function ( value, offset ) {
  5122. if ( offset === undefined ) offset = 0;
  5123. this.array.set( value, offset );
  5124. return this;
  5125. },
  5126. getX: function ( index ) {
  5127. return this.array[ index * this.itemSize ];
  5128. },
  5129. setX: function ( index, x ) {
  5130. this.array[ index * this.itemSize ] = x;
  5131. return this;
  5132. },
  5133. getY: function ( index ) {
  5134. return this.array[ index * this.itemSize + 1 ];
  5135. },
  5136. setY: function ( index, y ) {
  5137. this.array[ index * this.itemSize + 1 ] = y;
  5138. return this;
  5139. },
  5140. getZ: function ( index ) {
  5141. return this.array[ index * this.itemSize + 2 ];
  5142. },
  5143. setZ: function ( index, z ) {
  5144. this.array[ index * this.itemSize + 2 ] = z;
  5145. return this;
  5146. },
  5147. getW: function ( index ) {
  5148. return this.array[ index * this.itemSize + 3 ];
  5149. },
  5150. setW: function ( index, w ) {
  5151. this.array[ index * this.itemSize + 3 ] = w;
  5152. return this;
  5153. },
  5154. setXY: function ( index, x, y ) {
  5155. index *= this.itemSize;
  5156. this.array[ index + 0 ] = x;
  5157. this.array[ index + 1 ] = y;
  5158. return this;
  5159. },
  5160. setXYZ: function ( index, x, y, z ) {
  5161. index *= this.itemSize;
  5162. this.array[ index + 0 ] = x;
  5163. this.array[ index + 1 ] = y;
  5164. this.array[ index + 2 ] = z;
  5165. return this;
  5166. },
  5167. setXYZW: function ( index, x, y, z, w ) {
  5168. index *= this.itemSize;
  5169. this.array[ index + 0 ] = x;
  5170. this.array[ index + 1 ] = y;
  5171. this.array[ index + 2 ] = z;
  5172. this.array[ index + 3 ] = w;
  5173. return this;
  5174. },
  5175. clone: function () {
  5176. return new this.constructor().copy( this );
  5177. }
  5178. };
  5179. //
  5180. THREE.Int8Attribute = function ( array, itemSize ) {
  5181. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5182. };
  5183. THREE.Uint8Attribute = function ( array, itemSize ) {
  5184. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5185. };
  5186. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5187. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5188. };
  5189. THREE.Int16Attribute = function ( array, itemSize ) {
  5190. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5191. };
  5192. THREE.Uint16Attribute = function ( array, itemSize ) {
  5193. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5194. };
  5195. THREE.Int32Attribute = function ( array, itemSize ) {
  5196. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5197. };
  5198. THREE.Uint32Attribute = function ( array, itemSize ) {
  5199. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5200. };
  5201. THREE.Float32Attribute = function ( array, itemSize ) {
  5202. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5203. };
  5204. THREE.Float64Attribute = function ( array, itemSize ) {
  5205. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5206. };
  5207. // Deprecated
  5208. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5209. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5210. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5211. };
  5212. // File:src/core/InstancedBufferAttribute.js
  5213. /**
  5214. * @author benaadams / https://twitter.com/ben_a_adams
  5215. */
  5216. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5217. THREE.BufferAttribute.call( this, array, itemSize );
  5218. this.meshPerAttribute = meshPerAttribute || 1;
  5219. };
  5220. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5221. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5222. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5223. THREE.BufferAttribute.prototype.copy.call( this, source );
  5224. this.meshPerAttribute = source.meshPerAttribute;
  5225. return this;
  5226. };
  5227. // File:src/core/InterleavedBuffer.js
  5228. /**
  5229. * @author benaadams / https://twitter.com/ben_a_adams
  5230. */
  5231. THREE.InterleavedBuffer = function ( array, stride ) {
  5232. this.uuid = THREE.Math.generateUUID();
  5233. this.array = array;
  5234. this.stride = stride;
  5235. this.dynamic = false;
  5236. this.updateRange = { offset: 0, count: - 1 };
  5237. this.version = 0;
  5238. };
  5239. THREE.InterleavedBuffer.prototype = {
  5240. constructor: THREE.InterleavedBuffer,
  5241. get length () {
  5242. return this.array.length;
  5243. },
  5244. get count () {
  5245. return this.array.length / this.stride;
  5246. },
  5247. set needsUpdate( value ) {
  5248. if ( value === true ) this.version ++;
  5249. },
  5250. setDynamic: function ( value ) {
  5251. this.dynamic = value;
  5252. return this;
  5253. },
  5254. copy: function ( source ) {
  5255. this.array = new source.array.constructor( source.array );
  5256. this.stride = source.stride;
  5257. this.dynamic = source.dynamic;
  5258. },
  5259. copyAt: function ( index1, attribute, index2 ) {
  5260. index1 *= this.stride;
  5261. index2 *= attribute.stride;
  5262. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5263. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5264. }
  5265. return this;
  5266. },
  5267. set: function ( value, offset ) {
  5268. if ( offset === undefined ) offset = 0;
  5269. this.array.set( value, offset );
  5270. return this;
  5271. },
  5272. clone: function () {
  5273. return new this.constructor().copy( this );
  5274. }
  5275. };
  5276. // File:src/core/InstancedInterleavedBuffer.js
  5277. /**
  5278. * @author benaadams / https://twitter.com/ben_a_adams
  5279. */
  5280. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5281. THREE.InterleavedBuffer.call( this, array, stride );
  5282. this.meshPerAttribute = meshPerAttribute || 1;
  5283. };
  5284. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5285. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5286. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5287. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5288. this.meshPerAttribute = source.meshPerAttribute;
  5289. return this;
  5290. };
  5291. // File:src/core/InterleavedBufferAttribute.js
  5292. /**
  5293. * @author benaadams / https://twitter.com/ben_a_adams
  5294. */
  5295. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5296. this.uuid = THREE.Math.generateUUID();
  5297. this.data = interleavedBuffer;
  5298. this.itemSize = itemSize;
  5299. this.offset = offset;
  5300. };
  5301. THREE.InterleavedBufferAttribute.prototype = {
  5302. constructor: THREE.InterleavedBufferAttribute,
  5303. get length() {
  5304. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5305. return this.array.length;
  5306. },
  5307. get count() {
  5308. return this.data.array.length / this.data.stride;
  5309. },
  5310. setX: function ( index, x ) {
  5311. this.data.array[ index * this.data.stride + this.offset ] = x;
  5312. return this;
  5313. },
  5314. setY: function ( index, y ) {
  5315. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5316. return this;
  5317. },
  5318. setZ: function ( index, z ) {
  5319. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5320. return this;
  5321. },
  5322. setW: function ( index, w ) {
  5323. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5324. return this;
  5325. },
  5326. getX: function ( index ) {
  5327. return this.data.array[ index * this.data.stride + this.offset ];
  5328. },
  5329. getY: function ( index ) {
  5330. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5331. },
  5332. getZ: function ( index ) {
  5333. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5334. },
  5335. getW: function ( index ) {
  5336. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5337. },
  5338. setXY: function ( index, x, y ) {
  5339. index = index * this.data.stride + this.offset;
  5340. this.data.array[ index + 0 ] = x;
  5341. this.data.array[ index + 1 ] = y;
  5342. return this;
  5343. },
  5344. setXYZ: function ( index, x, y, z ) {
  5345. index = index * this.data.stride + this.offset;
  5346. this.data.array[ index + 0 ] = x;
  5347. this.data.array[ index + 1 ] = y;
  5348. this.data.array[ index + 2 ] = z;
  5349. return this;
  5350. },
  5351. setXYZW: function ( index, x, y, z, w ) {
  5352. index = index * this.data.stride + this.offset;
  5353. this.data.array[ index + 0 ] = x;
  5354. this.data.array[ index + 1 ] = y;
  5355. this.data.array[ index + 2 ] = z;
  5356. this.data.array[ index + 3 ] = w;
  5357. return this;
  5358. }
  5359. };
  5360. // File:src/core/Geometry.js
  5361. /**
  5362. * @author mrdoob / http://mrdoob.com/
  5363. * @author kile / http://kile.stravaganza.org/
  5364. * @author alteredq / http://alteredqualia.com/
  5365. * @author mikael emtinger / http://gomo.se/
  5366. * @author zz85 / http://www.lab4games.net/zz85/blog
  5367. * @author bhouston / http://clara.io
  5368. */
  5369. THREE.Geometry = function () {
  5370. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5371. this.uuid = THREE.Math.generateUUID();
  5372. this.name = '';
  5373. this.type = 'Geometry';
  5374. this.vertices = [];
  5375. this.colors = [];
  5376. this.faces = [];
  5377. this.faceVertexUvs = [ [] ];
  5378. this.morphTargets = [];
  5379. this.morphColors = [];
  5380. this.morphNormals = [];
  5381. this.skinWeights = [];
  5382. this.skinIndices = [];
  5383. this.lineDistances = [];
  5384. this.boundingBox = null;
  5385. this.boundingSphere = null;
  5386. // update flags
  5387. this.verticesNeedUpdate = false;
  5388. this.elementsNeedUpdate = false;
  5389. this.uvsNeedUpdate = false;
  5390. this.normalsNeedUpdate = false;
  5391. this.colorsNeedUpdate = false;
  5392. this.lineDistancesNeedUpdate = false;
  5393. this.groupsNeedUpdate = false;
  5394. };
  5395. THREE.Geometry.prototype = {
  5396. constructor: THREE.Geometry,
  5397. applyMatrix: function ( matrix ) {
  5398. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5399. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5400. var vertex = this.vertices[ i ];
  5401. vertex.applyMatrix4( matrix );
  5402. }
  5403. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5404. var face = this.faces[ i ];
  5405. face.normal.applyMatrix3( normalMatrix ).normalize();
  5406. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5407. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5408. }
  5409. }
  5410. if ( this.boundingBox !== null ) {
  5411. this.computeBoundingBox();
  5412. }
  5413. if ( this.boundingSphere !== null ) {
  5414. this.computeBoundingSphere();
  5415. }
  5416. this.verticesNeedUpdate = true;
  5417. this.normalsNeedUpdate = true;
  5418. },
  5419. rotateX: function () {
  5420. // rotate geometry around world x-axis
  5421. var m1;
  5422. return function rotateX( angle ) {
  5423. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5424. m1.makeRotationX( angle );
  5425. this.applyMatrix( m1 );
  5426. return this;
  5427. };
  5428. }(),
  5429. rotateY: function () {
  5430. // rotate geometry around world y-axis
  5431. var m1;
  5432. return function rotateY( angle ) {
  5433. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5434. m1.makeRotationY( angle );
  5435. this.applyMatrix( m1 );
  5436. return this;
  5437. };
  5438. }(),
  5439. rotateZ: function () {
  5440. // rotate geometry around world z-axis
  5441. var m1;
  5442. return function rotateZ( angle ) {
  5443. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5444. m1.makeRotationZ( angle );
  5445. this.applyMatrix( m1 );
  5446. return this;
  5447. };
  5448. }(),
  5449. translate: function () {
  5450. // translate geometry
  5451. var m1;
  5452. return function translate( x, y, z ) {
  5453. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5454. m1.makeTranslation( x, y, z );
  5455. this.applyMatrix( m1 );
  5456. return this;
  5457. };
  5458. }(),
  5459. scale: function () {
  5460. // scale geometry
  5461. var m1;
  5462. return function scale( x, y, z ) {
  5463. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5464. m1.makeScale( x, y, z );
  5465. this.applyMatrix( m1 );
  5466. return this;
  5467. };
  5468. }(),
  5469. lookAt: function () {
  5470. var obj;
  5471. return function lookAt( vector ) {
  5472. if ( obj === undefined ) obj = new THREE.Object3D();
  5473. obj.lookAt( vector );
  5474. obj.updateMatrix();
  5475. this.applyMatrix( obj.matrix );
  5476. };
  5477. }(),
  5478. fromBufferGeometry: function ( geometry ) {
  5479. var scope = this;
  5480. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5481. var attributes = geometry.attributes;
  5482. var vertices = attributes.position.array;
  5483. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5484. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5485. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5486. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5487. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5488. var tempNormals = [];
  5489. var tempUVs = [];
  5490. var tempUVs2 = [];
  5491. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5492. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5493. if ( normals !== undefined ) {
  5494. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5495. }
  5496. if ( colors !== undefined ) {
  5497. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5498. }
  5499. if ( uvs !== undefined ) {
  5500. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5501. }
  5502. if ( uvs2 !== undefined ) {
  5503. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5504. }
  5505. }
  5506. function addFace( a, b, c ) {
  5507. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5508. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5509. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5510. scope.faces.push( face );
  5511. if ( uvs !== undefined ) {
  5512. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5513. }
  5514. if ( uvs2 !== undefined ) {
  5515. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5516. }
  5517. };
  5518. if ( indices !== undefined ) {
  5519. var groups = geometry.groups;
  5520. if ( groups.length > 0 ) {
  5521. for ( var i = 0; i < groups.length; i ++ ) {
  5522. var group = groups[ i ];
  5523. var start = group.start;
  5524. var count = group.count;
  5525. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5526. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
  5527. }
  5528. }
  5529. } else {
  5530. for ( var i = 0; i < indices.length; i += 3 ) {
  5531. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5532. }
  5533. }
  5534. } else {
  5535. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5536. addFace( i, i + 1, i + 2 );
  5537. }
  5538. }
  5539. this.computeFaceNormals();
  5540. if ( geometry.boundingBox !== null ) {
  5541. this.boundingBox = geometry.boundingBox.clone();
  5542. }
  5543. if ( geometry.boundingSphere !== null ) {
  5544. this.boundingSphere = geometry.boundingSphere.clone();
  5545. }
  5546. return this;
  5547. },
  5548. center: function () {
  5549. this.computeBoundingBox();
  5550. var offset = this.boundingBox.center().negate();
  5551. this.translate( offset.x, offset.y, offset.z );
  5552. return offset;
  5553. },
  5554. normalize: function () {
  5555. this.computeBoundingSphere();
  5556. var center = this.boundingSphere.center;
  5557. var radius = this.boundingSphere.radius;
  5558. var s = radius === 0 ? 1 : 1.0 / radius;
  5559. var matrix = new THREE.Matrix4();
  5560. matrix.set(
  5561. s, 0, 0, - s * center.x,
  5562. 0, s, 0, - s * center.y,
  5563. 0, 0, s, - s * center.z,
  5564. 0, 0, 0, 1
  5565. );
  5566. this.applyMatrix( matrix );
  5567. return this;
  5568. },
  5569. computeFaceNormals: function () {
  5570. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5571. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5572. var face = this.faces[ f ];
  5573. var vA = this.vertices[ face.a ];
  5574. var vB = this.vertices[ face.b ];
  5575. var vC = this.vertices[ face.c ];
  5576. cb.subVectors( vC, vB );
  5577. ab.subVectors( vA, vB );
  5578. cb.cross( ab );
  5579. cb.normalize();
  5580. face.normal.copy( cb );
  5581. }
  5582. },
  5583. computeVertexNormals: function ( areaWeighted ) {
  5584. var v, vl, f, fl, face, vertices;
  5585. vertices = new Array( this.vertices.length );
  5586. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5587. vertices[ v ] = new THREE.Vector3();
  5588. }
  5589. if ( areaWeighted ) {
  5590. // vertex normals weighted by triangle areas
  5591. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5592. var vA, vB, vC;
  5593. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5594. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5595. face = this.faces[ f ];
  5596. vA = this.vertices[ face.a ];
  5597. vB = this.vertices[ face.b ];
  5598. vC = this.vertices[ face.c ];
  5599. cb.subVectors( vC, vB );
  5600. ab.subVectors( vA, vB );
  5601. cb.cross( ab );
  5602. vertices[ face.a ].add( cb );
  5603. vertices[ face.b ].add( cb );
  5604. vertices[ face.c ].add( cb );
  5605. }
  5606. } else {
  5607. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5608. face = this.faces[ f ];
  5609. vertices[ face.a ].add( face.normal );
  5610. vertices[ face.b ].add( face.normal );
  5611. vertices[ face.c ].add( face.normal );
  5612. }
  5613. }
  5614. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5615. vertices[ v ].normalize();
  5616. }
  5617. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5618. face = this.faces[ f ];
  5619. var vertexNormals = face.vertexNormals;
  5620. if ( vertexNormals.length === 3 ) {
  5621. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5622. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5623. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5624. } else {
  5625. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5626. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5627. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5628. }
  5629. }
  5630. },
  5631. computeMorphNormals: function () {
  5632. var i, il, f, fl, face;
  5633. // save original normals
  5634. // - create temp variables on first access
  5635. // otherwise just copy (for faster repeated calls)
  5636. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5637. face = this.faces[ f ];
  5638. if ( ! face.__originalFaceNormal ) {
  5639. face.__originalFaceNormal = face.normal.clone();
  5640. } else {
  5641. face.__originalFaceNormal.copy( face.normal );
  5642. }
  5643. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5644. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5645. if ( ! face.__originalVertexNormals[ i ] ) {
  5646. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5647. } else {
  5648. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5649. }
  5650. }
  5651. }
  5652. // use temp geometry to compute face and vertex normals for each morph
  5653. var tmpGeo = new THREE.Geometry();
  5654. tmpGeo.faces = this.faces;
  5655. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5656. // create on first access
  5657. if ( ! this.morphNormals[ i ] ) {
  5658. this.morphNormals[ i ] = {};
  5659. this.morphNormals[ i ].faceNormals = [];
  5660. this.morphNormals[ i ].vertexNormals = [];
  5661. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5662. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5663. var faceNormal, vertexNormals;
  5664. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5665. faceNormal = new THREE.Vector3();
  5666. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5667. dstNormalsFace.push( faceNormal );
  5668. dstNormalsVertex.push( vertexNormals );
  5669. }
  5670. }
  5671. var morphNormals = this.morphNormals[ i ];
  5672. // set vertices to morph target
  5673. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5674. // compute morph normals
  5675. tmpGeo.computeFaceNormals();
  5676. tmpGeo.computeVertexNormals();
  5677. // store morph normals
  5678. var faceNormal, vertexNormals;
  5679. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5680. face = this.faces[ f ];
  5681. faceNormal = morphNormals.faceNormals[ f ];
  5682. vertexNormals = morphNormals.vertexNormals[ f ];
  5683. faceNormal.copy( face.normal );
  5684. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5685. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5686. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5687. }
  5688. }
  5689. // restore original normals
  5690. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5691. face = this.faces[ f ];
  5692. face.normal = face.__originalFaceNormal;
  5693. face.vertexNormals = face.__originalVertexNormals;
  5694. }
  5695. },
  5696. computeTangents: function () {
  5697. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  5698. },
  5699. computeLineDistances: function () {
  5700. var d = 0;
  5701. var vertices = this.vertices;
  5702. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5703. if ( i > 0 ) {
  5704. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5705. }
  5706. this.lineDistances[ i ] = d;
  5707. }
  5708. },
  5709. computeBoundingBox: function () {
  5710. if ( this.boundingBox === null ) {
  5711. this.boundingBox = new THREE.Box3();
  5712. }
  5713. this.boundingBox.setFromPoints( this.vertices );
  5714. },
  5715. computeBoundingSphere: function () {
  5716. if ( this.boundingSphere === null ) {
  5717. this.boundingSphere = new THREE.Sphere();
  5718. }
  5719. this.boundingSphere.setFromPoints( this.vertices );
  5720. },
  5721. merge: function ( geometry, matrix, materialIndexOffset ) {
  5722. if ( geometry instanceof THREE.Geometry === false ) {
  5723. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5724. return;
  5725. }
  5726. var normalMatrix,
  5727. vertexOffset = this.vertices.length,
  5728. vertices1 = this.vertices,
  5729. vertices2 = geometry.vertices,
  5730. faces1 = this.faces,
  5731. faces2 = geometry.faces,
  5732. uvs1 = this.faceVertexUvs[ 0 ],
  5733. uvs2 = geometry.faceVertexUvs[ 0 ];
  5734. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5735. if ( matrix !== undefined ) {
  5736. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5737. }
  5738. // vertices
  5739. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5740. var vertex = vertices2[ i ];
  5741. var vertexCopy = vertex.clone();
  5742. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5743. vertices1.push( vertexCopy );
  5744. }
  5745. // faces
  5746. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5747. var face = faces2[ i ], faceCopy, normal, color,
  5748. faceVertexNormals = face.vertexNormals,
  5749. faceVertexColors = face.vertexColors;
  5750. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5751. faceCopy.normal.copy( face.normal );
  5752. if ( normalMatrix !== undefined ) {
  5753. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5754. }
  5755. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5756. normal = faceVertexNormals[ j ].clone();
  5757. if ( normalMatrix !== undefined ) {
  5758. normal.applyMatrix3( normalMatrix ).normalize();
  5759. }
  5760. faceCopy.vertexNormals.push( normal );
  5761. }
  5762. faceCopy.color.copy( face.color );
  5763. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5764. color = faceVertexColors[ j ];
  5765. faceCopy.vertexColors.push( color.clone() );
  5766. }
  5767. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5768. faces1.push( faceCopy );
  5769. }
  5770. // uvs
  5771. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5772. var uv = uvs2[ i ], uvCopy = [];
  5773. if ( uv === undefined ) {
  5774. continue;
  5775. }
  5776. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5777. uvCopy.push( uv[ j ].clone() );
  5778. }
  5779. uvs1.push( uvCopy );
  5780. }
  5781. },
  5782. mergeMesh: function ( mesh ) {
  5783. if ( mesh instanceof THREE.Mesh === false ) {
  5784. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5785. return;
  5786. }
  5787. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5788. this.merge( mesh.geometry, mesh.matrix );
  5789. },
  5790. /*
  5791. * Checks for duplicate vertices with hashmap.
  5792. * Duplicated vertices are removed
  5793. * and faces' vertices are updated.
  5794. */
  5795. mergeVertices: function () {
  5796. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5797. var unique = [], changes = [];
  5798. var v, key;
  5799. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5800. var precision = Math.pow( 10, precisionPoints );
  5801. var i, il, face;
  5802. var indices, j, jl;
  5803. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5804. v = this.vertices[ i ];
  5805. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5806. if ( verticesMap[ key ] === undefined ) {
  5807. verticesMap[ key ] = i;
  5808. unique.push( this.vertices[ i ] );
  5809. changes[ i ] = unique.length - 1;
  5810. } else {
  5811. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5812. changes[ i ] = changes[ verticesMap[ key ] ];
  5813. }
  5814. }
  5815. // if faces are completely degenerate after merging vertices, we
  5816. // have to remove them from the geometry.
  5817. var faceIndicesToRemove = [];
  5818. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5819. face = this.faces[ i ];
  5820. face.a = changes[ face.a ];
  5821. face.b = changes[ face.b ];
  5822. face.c = changes[ face.c ];
  5823. indices = [ face.a, face.b, face.c ];
  5824. var dupIndex = - 1;
  5825. // if any duplicate vertices are found in a Face3
  5826. // we have to remove the face as nothing can be saved
  5827. for ( var n = 0; n < 3; n ++ ) {
  5828. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5829. dupIndex = n;
  5830. faceIndicesToRemove.push( i );
  5831. break;
  5832. }
  5833. }
  5834. }
  5835. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5836. var idx = faceIndicesToRemove[ i ];
  5837. this.faces.splice( idx, 1 );
  5838. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5839. this.faceVertexUvs[ j ].splice( idx, 1 );
  5840. }
  5841. }
  5842. // Use unique set of vertices
  5843. var diff = this.vertices.length - unique.length;
  5844. this.vertices = unique;
  5845. return diff;
  5846. },
  5847. sortFacesByMaterialIndex: function () {
  5848. function materialIndexSort( a, b ) {
  5849. return a.materialIndex - b.materialIndex;
  5850. }
  5851. this.faces.sort( materialIndexSort );
  5852. },
  5853. toJSON: function () {
  5854. var data = {
  5855. metadata: {
  5856. version: 4.4,
  5857. type: 'Geometry',
  5858. generator: 'Geometry.toJSON'
  5859. }
  5860. };
  5861. // standard Geometry serialization
  5862. data.uuid = this.uuid;
  5863. data.type = this.type;
  5864. if ( this.name !== '' ) data.name = this.name;
  5865. if ( this.parameters !== undefined ) {
  5866. var parameters = this.parameters;
  5867. for ( var key in parameters ) {
  5868. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5869. }
  5870. return data;
  5871. }
  5872. var vertices = [];
  5873. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5874. var vertex = this.vertices[ i ];
  5875. vertices.push( vertex.x, vertex.y, vertex.z );
  5876. }
  5877. var faces = [];
  5878. var normals = [];
  5879. var normalsHash = {};
  5880. var colors = [];
  5881. var colorsHash = {};
  5882. var uvs = [];
  5883. var uvsHash = {};
  5884. for ( var i = 0; i < this.faces.length; i ++ ) {
  5885. var face = this.faces[ i ];
  5886. var hasMaterial = false; // face.materialIndex !== undefined;
  5887. var hasFaceUv = false; // deprecated
  5888. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5889. var hasFaceNormal = face.normal.length() > 0;
  5890. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5891. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5892. var hasFaceVertexColor = face.vertexColors.length > 0;
  5893. var faceType = 0;
  5894. faceType = setBit( faceType, 0, 0 );
  5895. faceType = setBit( faceType, 1, hasMaterial );
  5896. faceType = setBit( faceType, 2, hasFaceUv );
  5897. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5898. faceType = setBit( faceType, 4, hasFaceNormal );
  5899. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5900. faceType = setBit( faceType, 6, hasFaceColor );
  5901. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5902. faces.push( faceType );
  5903. faces.push( face.a, face.b, face.c );
  5904. if ( hasFaceVertexUv ) {
  5905. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5906. faces.push(
  5907. getUvIndex( faceVertexUvs[ 0 ] ),
  5908. getUvIndex( faceVertexUvs[ 1 ] ),
  5909. getUvIndex( faceVertexUvs[ 2 ] )
  5910. );
  5911. }
  5912. if ( hasFaceNormal ) {
  5913. faces.push( getNormalIndex( face.normal ) );
  5914. }
  5915. if ( hasFaceVertexNormal ) {
  5916. var vertexNormals = face.vertexNormals;
  5917. faces.push(
  5918. getNormalIndex( vertexNormals[ 0 ] ),
  5919. getNormalIndex( vertexNormals[ 1 ] ),
  5920. getNormalIndex( vertexNormals[ 2 ] )
  5921. );
  5922. }
  5923. if ( hasFaceColor ) {
  5924. faces.push( getColorIndex( face.color ) );
  5925. }
  5926. if ( hasFaceVertexColor ) {
  5927. var vertexColors = face.vertexColors;
  5928. faces.push(
  5929. getColorIndex( vertexColors[ 0 ] ),
  5930. getColorIndex( vertexColors[ 1 ] ),
  5931. getColorIndex( vertexColors[ 2 ] )
  5932. );
  5933. }
  5934. }
  5935. function setBit( value, position, enabled ) {
  5936. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  5937. }
  5938. function getNormalIndex( normal ) {
  5939. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5940. if ( normalsHash[ hash ] !== undefined ) {
  5941. return normalsHash[ hash ];
  5942. }
  5943. normalsHash[ hash ] = normals.length / 3;
  5944. normals.push( normal.x, normal.y, normal.z );
  5945. return normalsHash[ hash ];
  5946. }
  5947. function getColorIndex( color ) {
  5948. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5949. if ( colorsHash[ hash ] !== undefined ) {
  5950. return colorsHash[ hash ];
  5951. }
  5952. colorsHash[ hash ] = colors.length;
  5953. colors.push( color.getHex() );
  5954. return colorsHash[ hash ];
  5955. }
  5956. function getUvIndex( uv ) {
  5957. var hash = uv.x.toString() + uv.y.toString();
  5958. if ( uvsHash[ hash ] !== undefined ) {
  5959. return uvsHash[ hash ];
  5960. }
  5961. uvsHash[ hash ] = uvs.length / 2;
  5962. uvs.push( uv.x, uv.y );
  5963. return uvsHash[ hash ];
  5964. }
  5965. data.data = {};
  5966. data.data.vertices = vertices;
  5967. data.data.normals = normals;
  5968. if ( colors.length > 0 ) data.data.colors = colors;
  5969. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  5970. data.data.faces = faces;
  5971. return data;
  5972. },
  5973. clone: function () {
  5974. return new this.constructor().copy( this );
  5975. },
  5976. copy: function ( source ) {
  5977. this.vertices = [];
  5978. this.faces = [];
  5979. this.faceVertexUvs = [ [] ];
  5980. var vertices = source.vertices;
  5981. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5982. this.vertices.push( vertices[ i ].clone() );
  5983. }
  5984. var faces = source.faces;
  5985. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  5986. this.faces.push( faces[ i ].clone() );
  5987. }
  5988. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  5989. var faceVertexUvs = source.faceVertexUvs[ i ];
  5990. if ( this.faceVertexUvs[ i ] === undefined ) {
  5991. this.faceVertexUvs[ i ] = [];
  5992. }
  5993. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  5994. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  5995. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  5996. var uv = uvs[ k ];
  5997. uvsCopy.push( uv.clone() );
  5998. }
  5999. this.faceVertexUvs[ i ].push( uvsCopy );
  6000. }
  6001. }
  6002. return this;
  6003. },
  6004. dispose: function () {
  6005. this.dispatchEvent( { type: 'dispose' } );
  6006. }
  6007. };
  6008. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6009. THREE.GeometryIdCount = 0;
  6010. // File:src/core/DirectGeometry.js
  6011. /**
  6012. * @author mrdoob / http://mrdoob.com/
  6013. */
  6014. THREE.DirectGeometry = function () {
  6015. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6016. this.uuid = THREE.Math.generateUUID();
  6017. this.name = '';
  6018. this.type = 'DirectGeometry';
  6019. this.indices = [];
  6020. this.vertices = [];
  6021. this.normals = [];
  6022. this.colors = [];
  6023. this.uvs = [];
  6024. this.uvs2 = [];
  6025. this.groups = [];
  6026. this.morphTargets = {};
  6027. this.skinWeights = [];
  6028. this.skinIndices = [];
  6029. // this.lineDistances = [];
  6030. this.boundingBox = null;
  6031. this.boundingSphere = null;
  6032. // update flags
  6033. this.verticesNeedUpdate = false;
  6034. this.normalsNeedUpdate = false;
  6035. this.colorsNeedUpdate = false;
  6036. this.uvsNeedUpdate = false;
  6037. this.groupsNeedUpdate = false;
  6038. };
  6039. THREE.DirectGeometry.prototype = {
  6040. constructor: THREE.DirectGeometry,
  6041. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6042. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6043. computeFaceNormals: function () {
  6044. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6045. },
  6046. computeVertexNormals: function () {
  6047. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6048. },
  6049. computeGroups: function ( geometry ) {
  6050. var group;
  6051. var groups = [];
  6052. var materialIndex;
  6053. var faces = geometry.faces;
  6054. for ( var i = 0; i < faces.length; i ++ ) {
  6055. var face = faces[ i ];
  6056. // materials
  6057. if ( face.materialIndex !== materialIndex ) {
  6058. materialIndex = face.materialIndex;
  6059. if ( group !== undefined ) {
  6060. group.count = ( i * 3 ) - group.start;
  6061. groups.push( group );
  6062. }
  6063. group = {
  6064. start: i * 3,
  6065. materialIndex: materialIndex
  6066. };
  6067. }
  6068. }
  6069. if ( group !== undefined ) {
  6070. group.count = ( i * 3 ) - group.start;
  6071. groups.push( group );
  6072. }
  6073. this.groups = groups;
  6074. },
  6075. fromGeometry: function ( geometry ) {
  6076. var faces = geometry.faces;
  6077. var vertices = geometry.vertices;
  6078. var faceVertexUvs = geometry.faceVertexUvs;
  6079. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6080. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6081. // morphs
  6082. var morphTargets = geometry.morphTargets;
  6083. var morphTargetsLength = morphTargets.length;
  6084. if ( morphTargetsLength > 0 ) {
  6085. var morphTargetsPosition = [];
  6086. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6087. morphTargetsPosition[ i ] = [];
  6088. }
  6089. this.morphTargets.position = morphTargetsPosition;
  6090. }
  6091. var morphNormals = geometry.morphNormals;
  6092. var morphNormalsLength = morphNormals.length;
  6093. if ( morphNormalsLength > 0 ) {
  6094. var morphTargetsNormal = [];
  6095. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6096. morphTargetsNormal[ i ] = [];
  6097. }
  6098. this.morphTargets.normal = morphTargetsNormal;
  6099. }
  6100. // skins
  6101. var skinIndices = geometry.skinIndices;
  6102. var skinWeights = geometry.skinWeights;
  6103. var hasSkinIndices = skinIndices.length === vertices.length;
  6104. var hasSkinWeights = skinWeights.length === vertices.length;
  6105. //
  6106. for ( var i = 0; i < faces.length; i ++ ) {
  6107. var face = faces[ i ];
  6108. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6109. var vertexNormals = face.vertexNormals;
  6110. if ( vertexNormals.length === 3 ) {
  6111. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6112. } else {
  6113. var normal = face.normal;
  6114. this.normals.push( normal, normal, normal );
  6115. }
  6116. var vertexColors = face.vertexColors;
  6117. if ( vertexColors.length === 3 ) {
  6118. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6119. } else {
  6120. var color = face.color;
  6121. this.colors.push( color, color, color );
  6122. }
  6123. if ( hasFaceVertexUv === true ) {
  6124. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6125. if ( vertexUvs !== undefined ) {
  6126. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6127. } else {
  6128. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6129. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6130. }
  6131. }
  6132. if ( hasFaceVertexUv2 === true ) {
  6133. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6134. if ( vertexUvs !== undefined ) {
  6135. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6136. } else {
  6137. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6138. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6139. }
  6140. }
  6141. // morphs
  6142. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6143. var morphTarget = morphTargets[ j ].vertices;
  6144. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6145. }
  6146. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6147. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6148. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6149. }
  6150. // skins
  6151. if ( hasSkinIndices ) {
  6152. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6153. }
  6154. if ( hasSkinWeights ) {
  6155. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6156. }
  6157. }
  6158. this.computeGroups( geometry );
  6159. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6160. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6161. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6162. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6163. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6164. return this;
  6165. },
  6166. dispose: function () {
  6167. this.dispatchEvent( { type: 'dispose' } );
  6168. }
  6169. };
  6170. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6171. // File:src/core/BufferGeometry.js
  6172. /**
  6173. * @author alteredq / http://alteredqualia.com/
  6174. * @author mrdoob / http://mrdoob.com/
  6175. */
  6176. THREE.BufferGeometry = function () {
  6177. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6178. this.uuid = THREE.Math.generateUUID();
  6179. this.name = '';
  6180. this.type = 'BufferGeometry';
  6181. this.index = null;
  6182. this.attributes = {};
  6183. this.morphAttributes = {};
  6184. this.groups = [];
  6185. this.boundingBox = null;
  6186. this.boundingSphere = null;
  6187. this.drawRange = { start: 0, count: Infinity };
  6188. };
  6189. THREE.BufferGeometry.prototype = {
  6190. constructor: THREE.BufferGeometry,
  6191. addIndex: function ( index ) {
  6192. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  6193. this.setIndex( index );
  6194. },
  6195. getIndex: function () {
  6196. return this.index;
  6197. },
  6198. setIndex: function ( index ) {
  6199. this.index = index;
  6200. },
  6201. addAttribute: function ( name, attribute ) {
  6202. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6203. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6204. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6205. return;
  6206. }
  6207. if ( name === 'index' ) {
  6208. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6209. this.setIndex( attribute );
  6210. return;
  6211. }
  6212. this.attributes[ name ] = attribute;
  6213. },
  6214. getAttribute: function ( name ) {
  6215. return this.attributes[ name ];
  6216. },
  6217. removeAttribute: function ( name ) {
  6218. delete this.attributes[ name ];
  6219. },
  6220. get drawcalls() {
  6221. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  6222. return this.groups;
  6223. },
  6224. get offsets() {
  6225. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  6226. return this.groups;
  6227. },
  6228. addDrawCall: function ( start, count, indexOffset ) {
  6229. if ( indexOffset !== undefined ) {
  6230. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  6231. }
  6232. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  6233. this.addGroup( start, count );
  6234. },
  6235. clearDrawCalls: function () {
  6236. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  6237. this.clearGroups();
  6238. },
  6239. addGroup: function ( start, count, materialIndex ) {
  6240. this.groups.push( {
  6241. start: start,
  6242. count: count,
  6243. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6244. } );
  6245. },
  6246. clearGroups: function () {
  6247. this.groups = [];
  6248. },
  6249. setDrawRange: function ( start, count ) {
  6250. this.drawRange.start = start;
  6251. this.drawRange.count = count;
  6252. },
  6253. applyMatrix: function ( matrix ) {
  6254. var position = this.attributes.position;
  6255. if ( position !== undefined ) {
  6256. matrix.applyToVector3Array( position.array );
  6257. position.needsUpdate = true;
  6258. }
  6259. var normal = this.attributes.normal;
  6260. if ( normal !== undefined ) {
  6261. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6262. normalMatrix.applyToVector3Array( normal.array );
  6263. normal.needsUpdate = true;
  6264. }
  6265. if ( this.boundingBox !== null ) {
  6266. this.computeBoundingBox();
  6267. }
  6268. if ( this.boundingSphere !== null ) {
  6269. this.computeBoundingSphere();
  6270. }
  6271. },
  6272. rotateX: function () {
  6273. // rotate geometry around world x-axis
  6274. var m1;
  6275. return function rotateX( angle ) {
  6276. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6277. m1.makeRotationX( angle );
  6278. this.applyMatrix( m1 );
  6279. return this;
  6280. };
  6281. }(),
  6282. rotateY: function () {
  6283. // rotate geometry around world y-axis
  6284. var m1;
  6285. return function rotateY( angle ) {
  6286. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6287. m1.makeRotationY( angle );
  6288. this.applyMatrix( m1 );
  6289. return this;
  6290. };
  6291. }(),
  6292. rotateZ: function () {
  6293. // rotate geometry around world z-axis
  6294. var m1;
  6295. return function rotateZ( angle ) {
  6296. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6297. m1.makeRotationZ( angle );
  6298. this.applyMatrix( m1 );
  6299. return this;
  6300. };
  6301. }(),
  6302. translate: function () {
  6303. // translate geometry
  6304. var m1;
  6305. return function translate( x, y, z ) {
  6306. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6307. m1.makeTranslation( x, y, z );
  6308. this.applyMatrix( m1 );
  6309. return this;
  6310. };
  6311. }(),
  6312. scale: function () {
  6313. // scale geometry
  6314. var m1;
  6315. return function scale( x, y, z ) {
  6316. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6317. m1.makeScale( x, y, z );
  6318. this.applyMatrix( m1 );
  6319. return this;
  6320. };
  6321. }(),
  6322. lookAt: function () {
  6323. var obj;
  6324. return function lookAt( vector ) {
  6325. if ( obj === undefined ) obj = new THREE.Object3D();
  6326. obj.lookAt( vector );
  6327. obj.updateMatrix();
  6328. this.applyMatrix( obj.matrix );
  6329. };
  6330. }(),
  6331. center: function () {
  6332. this.computeBoundingBox();
  6333. var offset = this.boundingBox.center().negate();
  6334. this.translate( offset.x, offset.y, offset.z );
  6335. return offset;
  6336. },
  6337. setFromObject: function ( object ) {
  6338. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6339. var geometry = object.geometry;
  6340. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6341. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6342. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6343. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6344. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6345. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6346. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6347. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6348. }
  6349. if ( geometry.boundingSphere !== null ) {
  6350. this.boundingSphere = geometry.boundingSphere.clone();
  6351. }
  6352. if ( geometry.boundingBox !== null ) {
  6353. this.boundingBox = geometry.boundingBox.clone();
  6354. }
  6355. } else if ( object instanceof THREE.Mesh ) {
  6356. if ( geometry instanceof THREE.Geometry ) {
  6357. this.fromGeometry( geometry );
  6358. }
  6359. }
  6360. return this;
  6361. },
  6362. updateFromObject: function ( object ) {
  6363. var geometry = object.geometry;
  6364. if ( object instanceof THREE.Mesh ) {
  6365. var direct = geometry.__directGeometry;
  6366. if ( direct === undefined ) {
  6367. return this.fromGeometry( geometry );
  6368. }
  6369. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6370. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6371. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6372. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6373. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6374. geometry.verticesNeedUpdate = false;
  6375. geometry.normalsNeedUpdate = false;
  6376. geometry.colorsNeedUpdate = false;
  6377. geometry.uvsNeedUpdate = false;
  6378. geometry.groupsNeedUpdate = false;
  6379. geometry = direct;
  6380. }
  6381. if ( geometry.verticesNeedUpdate === true ) {
  6382. var attribute = this.attributes.position;
  6383. if ( attribute !== undefined ) {
  6384. attribute.copyVector3sArray( geometry.vertices );
  6385. attribute.needsUpdate = true;
  6386. }
  6387. geometry.verticesNeedUpdate = false;
  6388. }
  6389. if ( geometry.normalsNeedUpdate === true ) {
  6390. var attribute = this.attributes.normal;
  6391. if ( attribute !== undefined ) {
  6392. attribute.copyVector3sArray( geometry.normals );
  6393. attribute.needsUpdate = true;
  6394. }
  6395. geometry.normalsNeedUpdate = false;
  6396. }
  6397. if ( geometry.colorsNeedUpdate === true ) {
  6398. var attribute = this.attributes.color;
  6399. if ( attribute !== undefined ) {
  6400. attribute.copyColorsArray( geometry.colors );
  6401. attribute.needsUpdate = true;
  6402. }
  6403. geometry.colorsNeedUpdate = false;
  6404. }
  6405. if ( geometry.lineDistancesNeedUpdate ) {
  6406. var attribute = this.attributes.lineDistance;
  6407. if ( attribute !== undefined ) {
  6408. attribute.copyArray( geometry.lineDistances );
  6409. attribute.needsUpdate = true;
  6410. }
  6411. geometry.lineDistancesNeedUpdate = false;
  6412. }
  6413. if ( geometry.groupsNeedUpdate ) {
  6414. geometry.computeGroups( object.geometry );
  6415. this.groups = geometry.groups;
  6416. geometry.groupsNeedUpdate = false;
  6417. }
  6418. return this;
  6419. },
  6420. fromGeometry: function ( geometry ) {
  6421. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6422. return this.fromDirectGeometry( geometry.__directGeometry );
  6423. },
  6424. fromDirectGeometry: function ( geometry ) {
  6425. var positions = new Float32Array( geometry.vertices.length * 3 );
  6426. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6427. if ( geometry.normals.length > 0 ) {
  6428. var normals = new Float32Array( geometry.normals.length * 3 );
  6429. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6430. }
  6431. if ( geometry.colors.length > 0 ) {
  6432. var colors = new Float32Array( geometry.colors.length * 3 );
  6433. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6434. }
  6435. if ( geometry.uvs.length > 0 ) {
  6436. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6437. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6438. }
  6439. if ( geometry.uvs2.length > 0 ) {
  6440. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6441. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6442. }
  6443. if ( geometry.indices.length > 0 ) {
  6444. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6445. var indices = new TypeArray( geometry.indices.length * 3 );
  6446. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6447. }
  6448. // groups
  6449. this.groups = geometry.groups;
  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 index = this.index;
  6538. var attributes = this.attributes;
  6539. var groups = this.groups;
  6540. if ( attributes.position ) {
  6541. var positions = attributes.position.array;
  6542. if ( attributes.normal === undefined ) {
  6543. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6544. } else {
  6545. // reset existing normals to zero
  6546. var normals = attributes.normal.array;
  6547. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6548. normals[ i ] = 0;
  6549. }
  6550. }
  6551. var normals = attributes.normal.array;
  6552. var vA, vB, vC,
  6553. pA = new THREE.Vector3(),
  6554. pB = new THREE.Vector3(),
  6555. pC = new THREE.Vector3(),
  6556. cb = new THREE.Vector3(),
  6557. ab = new THREE.Vector3();
  6558. // indexed elements
  6559. if ( index ) {
  6560. var indices = index.array;
  6561. if ( groups.length === 0 ) {
  6562. this.addGroup( 0, indices.length );
  6563. }
  6564. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6565. var group = groups[ j ];
  6566. var start = group.start;
  6567. var count = group.count;
  6568. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6569. vA = indices[ i + 0 ] * 3;
  6570. vB = indices[ i + 1 ] * 3;
  6571. vC = indices[ i + 2 ] * 3;
  6572. pA.fromArray( positions, vA );
  6573. pB.fromArray( positions, vB );
  6574. pC.fromArray( positions, vC );
  6575. cb.subVectors( pC, pB );
  6576. ab.subVectors( pA, pB );
  6577. cb.cross( ab );
  6578. normals[ vA ] += cb.x;
  6579. normals[ vA + 1 ] += cb.y;
  6580. normals[ vA + 2 ] += cb.z;
  6581. normals[ vB ] += cb.x;
  6582. normals[ vB + 1 ] += cb.y;
  6583. normals[ vB + 2 ] += cb.z;
  6584. normals[ vC ] += cb.x;
  6585. normals[ vC + 1 ] += cb.y;
  6586. normals[ vC + 2 ] += cb.z;
  6587. }
  6588. }
  6589. } else {
  6590. // non-indexed elements (unconnected triangle soup)
  6591. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6592. pA.fromArray( positions, i );
  6593. pB.fromArray( positions, i + 3 );
  6594. pC.fromArray( positions, i + 6 );
  6595. cb.subVectors( pC, pB );
  6596. ab.subVectors( pA, pB );
  6597. cb.cross( ab );
  6598. normals[ i ] = cb.x;
  6599. normals[ i + 1 ] = cb.y;
  6600. normals[ i + 2 ] = cb.z;
  6601. normals[ i + 3 ] = cb.x;
  6602. normals[ i + 4 ] = cb.y;
  6603. normals[ i + 5 ] = cb.z;
  6604. normals[ i + 6 ] = cb.x;
  6605. normals[ i + 7 ] = cb.y;
  6606. normals[ i + 8 ] = cb.z;
  6607. }
  6608. }
  6609. this.normalizeNormals();
  6610. attributes.normal.needsUpdate = true;
  6611. }
  6612. },
  6613. computeTangents: function () {
  6614. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  6615. },
  6616. computeOffsets: function ( size ) {
  6617. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.')
  6618. },
  6619. merge: function ( geometry, offset ) {
  6620. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6621. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6622. return;
  6623. }
  6624. if ( offset === undefined ) offset = 0;
  6625. var attributes = this.attributes;
  6626. for ( var key in attributes ) {
  6627. if ( geometry.attributes[ key ] === undefined ) continue;
  6628. var attribute1 = attributes[ key ];
  6629. var attributeArray1 = attribute1.array;
  6630. var attribute2 = geometry.attributes[ key ];
  6631. var attributeArray2 = attribute2.array;
  6632. var attributeSize = attribute2.itemSize;
  6633. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6634. attributeArray1[ j ] = attributeArray2[ i ];
  6635. }
  6636. }
  6637. return this;
  6638. },
  6639. normalizeNormals: function () {
  6640. var normals = this.attributes.normal.array;
  6641. var x, y, z, n;
  6642. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6643. x = normals[ i ];
  6644. y = normals[ i + 1 ];
  6645. z = normals[ i + 2 ];
  6646. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6647. normals[ i ] *= n;
  6648. normals[ i + 1 ] *= n;
  6649. normals[ i + 2 ] *= n;
  6650. }
  6651. },
  6652. toJSON: function () {
  6653. var data = {
  6654. metadata: {
  6655. version: 4.4,
  6656. type: 'BufferGeometry',
  6657. generator: 'BufferGeometry.toJSON'
  6658. }
  6659. };
  6660. // standard BufferGeometry serialization
  6661. data.uuid = this.uuid;
  6662. data.type = this.type;
  6663. if ( this.name !== '' ) data.name = this.name;
  6664. if ( this.parameters !== undefined ) {
  6665. var parameters = this.parameters;
  6666. for ( var key in parameters ) {
  6667. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6668. }
  6669. return data;
  6670. }
  6671. data.data = { attributes: {} };
  6672. var index = this.index;
  6673. if ( index !== null ) {
  6674. var array = Array.prototype.slice.call( index.array );
  6675. data.data.index = {
  6676. type: index.array.constructor.name,
  6677. array: array
  6678. };
  6679. }
  6680. var attributes = this.attributes;
  6681. for ( var key in attributes ) {
  6682. var attribute = attributes[ key ];
  6683. var array = Array.prototype.slice.call( attribute.array );
  6684. data.data.attributes[ key ] = {
  6685. itemSize: attribute.itemSize,
  6686. type: attribute.array.constructor.name,
  6687. array: array
  6688. };
  6689. }
  6690. var groups = this.groups;
  6691. if ( groups.length > 0 ) {
  6692. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6693. }
  6694. var boundingSphere = this.boundingSphere;
  6695. if ( boundingSphere !== null ) {
  6696. data.data.boundingSphere = {
  6697. center: boundingSphere.center.toArray(),
  6698. radius: boundingSphere.radius
  6699. };
  6700. }
  6701. return data;
  6702. },
  6703. clone: function () {
  6704. return new this.constructor().copy( this );
  6705. },
  6706. copy: function ( source ) {
  6707. var index = source.index;
  6708. if ( index !== null ) {
  6709. this.setIndex( index.clone() );
  6710. }
  6711. var attributes = source.attributes;
  6712. for ( var name in attributes ) {
  6713. var attribute = attributes[ name ];
  6714. this.addAttribute( name, attribute.clone() );
  6715. }
  6716. var groups = source.groups;
  6717. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6718. var group = groups[ i ];
  6719. this.addGroup( group.start, group.count );
  6720. }
  6721. return this;
  6722. },
  6723. dispose: function () {
  6724. this.dispatchEvent( { type: 'dispose' } );
  6725. }
  6726. };
  6727. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6728. THREE.BufferGeometry.MaxIndex = 65535;
  6729. // File:src/core/InstancedBufferGeometry.js
  6730. /**
  6731. * @author benaadams / https://twitter.com/ben_a_adams
  6732. */
  6733. THREE.InstancedBufferGeometry = function () {
  6734. THREE.BufferGeometry.call( this );
  6735. this.type = 'InstancedBufferGeometry';
  6736. this.maxInstancedCount = undefined;
  6737. };
  6738. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6739. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6740. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  6741. this.groups.push( {
  6742. start: start,
  6743. count: count,
  6744. instances: instances
  6745. } );
  6746. };
  6747. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  6748. var index = source.index;
  6749. if ( index !== null ) {
  6750. this.setIndex( index.clone() );
  6751. }
  6752. var attributes = source.attributes;
  6753. for ( var name in attributes ) {
  6754. var attribute = attributes[ name ];
  6755. this.addAttribute( name, attribute.clone() );
  6756. }
  6757. var groups = source.groups;
  6758. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6759. var group = groups[ i ];
  6760. this.addGroup( group.start, group.count, group.instances );
  6761. }
  6762. return this;
  6763. };
  6764. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6765. // File:src/animation/AnimationAction.js
  6766. /**
  6767. *
  6768. * A clip that has been explicitly scheduled.
  6769. *
  6770. * @author Ben Houston / http://clara.io/
  6771. * @author David Sarno / http://lighthaus.us/
  6772. */
  6773. THREE.AnimationAction = function ( clip, startTime, timeScale, weight, loop ) {
  6774. if( clip === undefined ) throw new Error( 'clip is null' );
  6775. this.clip = clip;
  6776. this.localRoot = null;
  6777. this.startTime = startTime || 0;
  6778. this.timeScale = timeScale || 1;
  6779. this.weight = weight || 1;
  6780. this.loop = loop || THREE.LoopRepeat;
  6781. this.loopCount = 0;
  6782. this.enabled = true; // allow for easy disabling of the action.
  6783. this.actionTime = - this.startTime;
  6784. this.clipTime = 0;
  6785. this.propertyBindings = [];
  6786. };
  6787. /*
  6788. THREE.LoopOnce = 2200;
  6789. THREE.LoopRepeat = 2201;
  6790. THREE.LoopPingPing = 2202;
  6791. */
  6792. THREE.AnimationAction.prototype = {
  6793. constructor: THREE.AnimationAction,
  6794. setLocalRoot: function( localRoot ) {
  6795. this.localRoot = localRoot;
  6796. return this;
  6797. },
  6798. updateTime: function( clipDeltaTime ) {
  6799. var previousClipTime = this.clipTime;
  6800. var previousLoopCount = this.loopCount;
  6801. var previousActionTime = this.actionTime;
  6802. var duration = this.clip.duration;
  6803. this.actionTime = this.actionTime + clipDeltaTime;
  6804. if( this.loop === THREE.LoopOnce ) {
  6805. this.loopCount = 0;
  6806. this.clipTime = Math.min( Math.max( this.actionTime, 0 ), duration );
  6807. // if time is changed since last time, see if we have hit a start/end limit
  6808. if( this.clipTime !== previousClipTime ) {
  6809. if( this.clipTime === duration ) {
  6810. this.mixer.dispatchEvent( { type: 'finished', action: this, direction: 1 } );
  6811. }
  6812. else if( this.clipTime === 0 ) {
  6813. this.mixer.dispatchEvent( { type: 'finished', action: this, direction: -1 } );
  6814. }
  6815. }
  6816. return this.clipTime;
  6817. }
  6818. this.loopCount = Math.floor( this.actionTime / duration );
  6819. var newClipTime = this.actionTime - this.loopCount * duration;
  6820. newClipTime = newClipTime % duration;
  6821. // if we are ping pong looping, ensure that we go backwards when appropriate
  6822. if( this.loop == THREE.LoopPingPong ) {
  6823. if( Math.abs( this.loopCount % 2 ) === 1 ) {
  6824. newClipTime = duration - newClipTime;
  6825. }
  6826. }
  6827. this.clipTime = newClipTime;
  6828. if( this.loopCount !== previousLoopCount ) {
  6829. this.mixer.dispatchEvent( { type: 'loop', action: this, loopDelta: ( this.loopCount - this.loopCount ) } );
  6830. }
  6831. return this.clipTime;
  6832. },
  6833. syncWith: function( action ) {
  6834. this.actionTime = action.actionTime;
  6835. this.timeScale = action.timeScale;
  6836. return this;
  6837. },
  6838. warpToDuration: function( duration ) {
  6839. this.timeScale = this.clip.duration / duration;
  6840. return this;
  6841. },
  6842. init: function( time ) {
  6843. this.clipTime = time - this.startTime;
  6844. return this;
  6845. },
  6846. update: function( clipDeltaTime ) {
  6847. this.updateTime( clipDeltaTime );
  6848. var clipResults = this.clip.getAt( this.clipTime );
  6849. return clipResults;
  6850. },
  6851. getTimeScaleAt: function( time ) {
  6852. if( this.timeScale.getAt ) {
  6853. // pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
  6854. return this.timeScale.getAt( time );
  6855. }
  6856. return this.timeScale;
  6857. },
  6858. getWeightAt: function( time ) {
  6859. if( this.weight.getAt ) {
  6860. // pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
  6861. return this.weight.getAt( time );
  6862. }
  6863. return this.weight;
  6864. }
  6865. };
  6866. // File:src/animation/AnimationClip.js
  6867. /**
  6868. *
  6869. * Reusable set of Tracks that represent an animation.
  6870. *
  6871. * @author Ben Houston / http://clara.io/
  6872. * @author David Sarno / http://lighthaus.us/
  6873. */
  6874. THREE.AnimationClip = function ( name, duration, tracks ) {
  6875. this.name = name;
  6876. this.tracks = tracks;
  6877. this.duration = ( duration !== undefined ) ? duration : -1;
  6878. // this means it should figure out its duration by scanning the tracks
  6879. if( this.duration < 0 ) {
  6880. for( var i = 0; i < this.tracks.length; i ++ ) {
  6881. var track = this.tracks[i];
  6882. this.duration = Math.max( track.keys[ track.keys.length - 1 ].time );
  6883. }
  6884. }
  6885. // maybe only do these on demand, as doing them here could potentially slow down loading
  6886. // but leaving these here during development as this ensures a lot of testing of these functions
  6887. this.trim();
  6888. this.optimize();
  6889. this.results = [];
  6890. };
  6891. THREE.AnimationClip.prototype = {
  6892. constructor: THREE.AnimationClip,
  6893. getAt: function( clipTime ) {
  6894. clipTime = Math.max( 0, Math.min( clipTime, this.duration ) );
  6895. for( var i = 0; i < this.tracks.length; i ++ ) {
  6896. var track = this.tracks[ i ];
  6897. this.results[ i ] = track.getAt( clipTime );
  6898. }
  6899. return this.results;
  6900. },
  6901. trim: function() {
  6902. for( var i = 0; i < this.tracks.length; i ++ ) {
  6903. this.tracks[ i ].trim( 0, this.duration );
  6904. }
  6905. return this;
  6906. },
  6907. optimize: function() {
  6908. for( var i = 0; i < this.tracks.length; i ++ ) {
  6909. this.tracks[ i ].optimize();
  6910. }
  6911. return this;
  6912. }
  6913. };
  6914. THREE.AnimationClip.CreateFromMorphTargetSequence = function( name, morphTargetSequence, fps ) {
  6915. var numMorphTargets = morphTargetSequence.length;
  6916. var tracks = [];
  6917. for( var i = 0; i < numMorphTargets; i ++ ) {
  6918. var keys = [];
  6919. keys.push( { time: ( i + numMorphTargets - 1 ) % numMorphTargets, value: 0 } );
  6920. keys.push( { time: i, value: 1 } );
  6921. keys.push( { time: ( i + 1 ) % numMorphTargets, value: 0 } );
  6922. keys.sort( THREE.KeyframeTrack.keyComparer );
  6923. // if there is a key at the first frame, duplicate it as the last frame as well for perfect loop.
  6924. if( keys[0].time === 0 ) {
  6925. keys.push( {
  6926. time: numMorphTargets,
  6927. value: keys[0].value
  6928. });
  6929. }
  6930. tracks.push( new THREE.NumberKeyframeTrack( '.morphTargetInfluences[' + morphTargetSequence[i].name + ']', keys ).scale( 1.0 / fps ) );
  6931. }
  6932. return new THREE.AnimationClip( name, -1, tracks );
  6933. };
  6934. THREE.AnimationClip.findByName = function( clipArray, name ) {
  6935. for( var i = 0; i < clipArray.length; i ++ ) {
  6936. if( clipArray[i].name === name ) {
  6937. return clipArray[i];
  6938. }
  6939. }
  6940. return null;
  6941. };
  6942. THREE.AnimationClip.CreateClipsFromMorphTargetSequences = function( morphTargets, fps ) {
  6943. var animationToMorphTargets = {};
  6944. // tested with https://regex101.com/ on trick sequences such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  6945. var pattern = /^([\w-]*?)([\d]+)$/;
  6946. // sort morph target names into animation groups based patterns like Walk_001, Walk_002, Run_001, Run_002
  6947. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  6948. var morphTarget = morphTargets[ i ];
  6949. var parts = morphTarget.name.match( pattern );
  6950. if ( parts && parts.length > 1 ) {
  6951. var name = parts[ 1 ];
  6952. var animationMorphTargets = animationToMorphTargets[ name ];
  6953. if( ! animationMorphTargets ) {
  6954. animationToMorphTargets[ name ] = animationMorphTargets = [];
  6955. }
  6956. animationMorphTargets.push( morphTarget );
  6957. }
  6958. }
  6959. var clips = [];
  6960. for( var name in animationToMorphTargets ) {
  6961. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  6962. }
  6963. return clips;
  6964. };
  6965. // parse the standard JSON format for clips
  6966. THREE.AnimationClip.parse = function( json ) {
  6967. var tracks = [];
  6968. for( var i = 0; i < json.tracks.length; i ++ ) {
  6969. tracks.push( THREE.KeyframeTrack.parse( json.tracks[i] ).scale( 1.0 / json.fps ) );
  6970. }
  6971. return new THREE.AnimationClip( json.name, json.duration, tracks );
  6972. };
  6973. // parse the animation.hierarchy format
  6974. THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
  6975. if( ! animation ) {
  6976. console.error( " no animation in JSONLoader data" );
  6977. return null;
  6978. }
  6979. var convertTrack = function( trackName, animationKeys, propertyName, trackType, animationKeyToValueFunc ) {
  6980. var keys = [];
  6981. for( var k = 0; k < animationKeys.length; k ++ ) {
  6982. var animationKey = animationKeys[k];
  6983. if( animationKey[propertyName] !== undefined ) {
  6984. keys.push( { time: animationKey.time, value: animationKeyToValueFunc( animationKey ) } );
  6985. }
  6986. }
  6987. // only return track if there are actually keys.
  6988. if( keys.length > 0 ) {
  6989. return new trackType( trackName, keys );
  6990. }
  6991. return null;
  6992. };
  6993. var tracks = [];
  6994. var clipName = animation.name || 'default';
  6995. var duration = animation.length || -1; // automatic length determination in AnimationClip.
  6996. var fps = animation.fps || 30;
  6997. var hierarchyTracks = animation.hierarchy || [];
  6998. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  6999. var animationKeys = hierarchyTracks[ h ].keys;
  7000. // skip empty tracks
  7001. if( ! animationKeys || animationKeys.length == 0 ) {
  7002. continue;
  7003. }
  7004. // process morph targets in a way exactly compatible with AnimationHandler.init( animation )
  7005. if( animationKeys[0].morphTargets ) {
  7006. // figure out all morph targets used in this track
  7007. var morphTargetNames = {};
  7008. for( var k = 0; k < animationKeys.length; k ++ ) {
  7009. if( animationKeys[k].morphTargets ) {
  7010. for( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7011. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7012. }
  7013. }
  7014. }
  7015. // create a track for each morph target with all zero morphTargetInfluences except for the keys in which the morphTarget is named.
  7016. for( var morphTargetName in morphTargetNames ) {
  7017. var keys = [];
  7018. for( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7019. var animationKey = animationKeys[k];
  7020. keys.push( {
  7021. time: animationKey.time,
  7022. value: (( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7023. });
  7024. }
  7025. tracks.push( new THREE.NumberKeyframeTrack( nodeName + '.morphTargetInfluence[' + morphTargetName + ']', keys ) );
  7026. }
  7027. duration = morphTargetNames.length * ( fps || 1.0 );
  7028. }
  7029. else {
  7030. var boneName = nodeName + '.bones[' + bones[ h ].name + ']';
  7031. // track contains positions...
  7032. var positionTrack = convertTrack( boneName + '.position', animationKeys, 'pos', THREE.VectorKeyframeTrack, function( animationKey ) {
  7033. return new THREE.Vector3().fromArray( animationKey.pos )
  7034. } );
  7035. if( positionTrack ) tracks.push( positionTrack );
  7036. // track contains quaternions...
  7037. var quaternionTrack = convertTrack( boneName + '.quaternion', animationKeys, 'rot', THREE.QuaternionKeyframeTrack, function( animationKey ) {
  7038. if( animationKey.rot.slerp ) {
  7039. return animationKey.rot.clone();
  7040. }
  7041. else {
  7042. return new THREE.Quaternion().fromArray( animationKey.rot );
  7043. }
  7044. } );
  7045. if( quaternionTrack ) tracks.push( quaternionTrack );
  7046. // track contains quaternions...
  7047. var scaleTrack = convertTrack( boneName + '.scale', animationKeys, 'scl', THREE.VectorKeyframeTrack, function( animationKey ) {
  7048. return new THREE.Vector3().fromArray( animationKey.scl )
  7049. } );
  7050. if( scaleTrack ) tracks.push( scaleTrack );
  7051. }
  7052. }
  7053. if( tracks.length === 0 ) {
  7054. return null;
  7055. }
  7056. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7057. return clip;
  7058. };
  7059. // File:src/animation/AnimationMixer.js
  7060. /**
  7061. *
  7062. * Mixes together the AnimationClips scheduled by AnimationActions and applies them to the root and subtree
  7063. *
  7064. *
  7065. * @author Ben Houston / http://clara.io/
  7066. * @author David Sarno / http://lighthaus.us/
  7067. */
  7068. THREE.AnimationMixer = function( root ) {
  7069. this.root = root;
  7070. this.time = 0;
  7071. this.timeScale = 1.0;
  7072. this.actions = [];
  7073. this.propertyBindingMap = {};
  7074. };
  7075. THREE.AnimationMixer.prototype = {
  7076. constructor: THREE.AnimationMixer,
  7077. addAction: function( action ) {
  7078. // TODO: check for duplicate action names? Or provide each action with a UUID?
  7079. this.actions.push( action );
  7080. action.init( this.time );
  7081. action.mixer = this;
  7082. var tracks = action.clip.tracks;
  7083. var root = action.localRoot || this.root;
  7084. for( var i = 0; i < tracks.length; i ++ ) {
  7085. var track = tracks[ i ];
  7086. var propertyBindingKey = root.uuid + '-' + track.name;
  7087. var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
  7088. if( propertyBinding === undefined ) {
  7089. propertyBinding = new THREE.PropertyBinding( root, track.name );
  7090. this.propertyBindingMap[ propertyBindingKey ] = propertyBinding;
  7091. }
  7092. // push in the same order as the tracks.
  7093. action.propertyBindings.push( propertyBinding );
  7094. // track usages of shared property bindings, because if we leave too many around, the mixer can get slow
  7095. propertyBinding.referenceCount += 1;
  7096. }
  7097. },
  7098. removeAllActions: function() {
  7099. for( var i = 0; i < this.actions.length; i ++ ) {
  7100. this.actions[i].mixer = null;
  7101. }
  7102. // unbind all property bindings
  7103. for( var properyBindingKey in this.propertyBindingMap ) {
  7104. this.propertyBindingMap[ properyBindingKey ].unbind();
  7105. }
  7106. this.actions = [];
  7107. this.propertyBindingMap = {};
  7108. return this;
  7109. },
  7110. removeAction: function( action ) {
  7111. var index = this.actions.indexOf( action );
  7112. if ( index !== - 1 ) {
  7113. this.actions.splice( index, 1 );
  7114. action.mixer = null;
  7115. }
  7116. // remove unused property bindings because if we leave them around the mixer can get slow
  7117. var root = action.localRoot || this.root;
  7118. var tracks = action.clip.tracks;
  7119. for( var i = 0; i < tracks.length; i ++ ) {
  7120. var track = tracks[ i ];
  7121. var propertyBindingKey = root.uuid + '-' + track.name;
  7122. var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
  7123. propertyBinding.referenceCount -= 1;
  7124. if( propertyBinding.referenceCount <= 0 ) {
  7125. propertyBinding.unbind();
  7126. delete this.propertyBindingMap[ propertyBindingKey ];
  7127. }
  7128. }
  7129. return this;
  7130. },
  7131. // can be optimized if needed
  7132. findActionByName: function( name ) {
  7133. for( var i = 0; i < this.actions.length; i ++ ) {
  7134. if( this.actions[i].name === name ) return this.actions[i];
  7135. }
  7136. return null;
  7137. },
  7138. play: function( action, optionalFadeInDuration ) {
  7139. action.startTime = this.time;
  7140. this.addAction( action );
  7141. return this;
  7142. },
  7143. fadeOut: function( action, duration ) {
  7144. var keys = [];
  7145. keys.push( { time: this.time, value: 1 } );
  7146. keys.push( { time: this.time + duration, value: 0 } );
  7147. action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
  7148. return this;
  7149. },
  7150. fadeIn: function( action, duration ) {
  7151. var keys = [];
  7152. keys.push( { time: this.time, value: 0 } );
  7153. keys.push( { time: this.time + duration, value: 1 } );
  7154. action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
  7155. return this;
  7156. },
  7157. warp: function( action, startTimeScale, endTimeScale, duration ) {
  7158. var keys = [];
  7159. keys.push( { time: this.time, value: startTimeScale } );
  7160. keys.push( { time: this.time + duration, value: endTimeScale } );
  7161. action.timeScale = new THREE.NumberKeyframeTrack( "timeScale", keys );
  7162. return this;
  7163. },
  7164. crossFade: function( fadeOutAction, fadeInAction, duration, warp ) {
  7165. this.fadeOut( fadeOutAction, duration );
  7166. this.fadeIn( fadeInAction, duration );
  7167. if( warp ) {
  7168. var startEndRatio = fadeOutAction.clip.duration / fadeInAction.clip.duration;
  7169. var endStartRatio = 1.0 / startEndRatio;
  7170. this.warp( fadeOutAction, 1.0, startEndRatio, duration );
  7171. this.warp( fadeInAction, endStartRatio, 1.0, duration );
  7172. }
  7173. return this;
  7174. },
  7175. update: function( deltaTime ) {
  7176. var mixerDeltaTime = deltaTime * this.timeScale;
  7177. this.time += mixerDeltaTime;
  7178. for( var i = 0; i < this.actions.length; i ++ ) {
  7179. var action = this.actions[i];
  7180. var weight = action.getWeightAt( this.time );
  7181. var actionTimeScale = action.getTimeScaleAt( this.time );
  7182. var actionDeltaTime = mixerDeltaTime * actionTimeScale;
  7183. var actionResults = action.update( actionDeltaTime );
  7184. if( action.weight <= 0 || ! action.enabled ) continue;
  7185. for( var j = 0; j < actionResults.length; j ++ ) {
  7186. var name = action.clip.tracks[j].name;
  7187. action.propertyBindings[ j ].accumulate( actionResults[j], weight );
  7188. }
  7189. }
  7190. // apply to nodes
  7191. for( var propertyBindingKey in this.propertyBindingMap ) {
  7192. this.propertyBindingMap[ propertyBindingKey ].apply();
  7193. }
  7194. return this;
  7195. }
  7196. };
  7197. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7198. // File:src/animation/AnimationUtils.js
  7199. /**
  7200. * @author Ben Houston / http://clara.io/
  7201. * @author David Sarno / http://lighthaus.us/
  7202. */
  7203. THREE.AnimationUtils = {
  7204. getEqualsFunc: function( exemplarValue ) {
  7205. if( exemplarValue.equals ) {
  7206. return function equals_object( a, b ) {
  7207. return a.equals( b );
  7208. }
  7209. }
  7210. return function equals_primitive( a, b ) {
  7211. return ( a === b );
  7212. };
  7213. },
  7214. clone: function( exemplarValue ) {
  7215. var typeName = typeof exemplarValue;
  7216. if( typeName === "object" ) {
  7217. if( exemplarValue.clone ) {
  7218. return exemplarValue.clone();
  7219. }
  7220. console.error( "can not figure out how to copy exemplarValue", exemplarValue );
  7221. }
  7222. return exemplarValue;
  7223. },
  7224. lerp: function( a, b, alpha, interTrack ) {
  7225. var lerpFunc = THREE.AnimationUtils.getLerpFunc( a, interTrack );
  7226. return lerpFunc( a, b, alpha );
  7227. },
  7228. lerp_object: function( a, b, alpha ) {
  7229. return a.lerp( b, alpha );
  7230. },
  7231. slerp_object: function( a, b, alpha ) {
  7232. return a.slerp( b, alpha );
  7233. },
  7234. lerp_number: function( a, b, alpha ) {
  7235. return a * ( 1 - alpha ) + b * alpha;
  7236. },
  7237. lerp_boolean: function( a, b, alpha ) {
  7238. return ( alpha < 0.5 ) ? a : b;
  7239. },
  7240. lerp_boolean_immediate: function( a, b, alpha ) {
  7241. return a;
  7242. },
  7243. lerp_string: function( a, b, alpha ) {
  7244. return ( alpha < 0.5 ) ? a : b;
  7245. },
  7246. lerp_string_immediate: function( a, b, alpha ) {
  7247. return a;
  7248. },
  7249. // NOTE: this is an accumulator function that modifies the first argument (e.g. a). This is to minimize memory alocations.
  7250. getLerpFunc: function( exemplarValue, interTrack ) {
  7251. if( exemplarValue === undefined || exemplarValue === null ) throw new Error( "examplarValue is null" );
  7252. var typeName = typeof exemplarValue;
  7253. switch( typeName ) {
  7254. case "object": {
  7255. if( exemplarValue.lerp ) {
  7256. return THREE.AnimationUtils.lerp_object;
  7257. }
  7258. if( exemplarValue.slerp ) {
  7259. return THREE.AnimationUtils.slerp_object;
  7260. }
  7261. break;
  7262. }
  7263. case "number": {
  7264. return THREE.AnimationUtils.lerp_number;
  7265. }
  7266. case "boolean": {
  7267. if( interTrack ) {
  7268. return THREE.AnimationUtils.lerp_boolean;
  7269. }
  7270. else {
  7271. return THREE.AnimationUtils.lerp_boolean_immediate;
  7272. }
  7273. }
  7274. case "string": {
  7275. if( interTrack ) {
  7276. return THREE.AnimationUtils.lerp_string;
  7277. }
  7278. else {
  7279. return THREE.AnimationUtils.lerp_string_immediate;
  7280. }
  7281. }
  7282. };
  7283. }
  7284. };
  7285. // File:src/animation/KeyframeTrack.js
  7286. /**
  7287. *
  7288. * A Track that returns a keyframe interpolated value, currently linearly interpolated
  7289. *
  7290. * @author Ben Houston / http://clara.io/
  7291. * @author David Sarno / http://lighthaus.us/
  7292. */
  7293. THREE.KeyframeTrack = function ( name, keys ) {
  7294. if( name === undefined ) throw new Error( "track name is undefined" );
  7295. if( keys === undefined || keys.length === 0 ) throw new Error( "no keys in track named " + name );
  7296. this.name = name;
  7297. this.keys = keys; // time in seconds, value as value
  7298. // the index of the last result, used as a starting point for local search.
  7299. this.lastIndex = 0;
  7300. this.validate();
  7301. this.optimize();
  7302. };
  7303. THREE.KeyframeTrack.prototype = {
  7304. constructor: THREE.KeyframeTrack,
  7305. getAt: function( time ) {
  7306. // this can not go higher than this.keys.length.
  7307. while( ( this.lastIndex < this.keys.length ) && ( time >= this.keys[this.lastIndex].time ) ) {
  7308. this.lastIndex ++;
  7309. };
  7310. // this can not go lower than 0.
  7311. while( ( this.lastIndex > 0 ) && ( time < this.keys[this.lastIndex - 1].time ) ) {
  7312. this.lastIndex --;
  7313. }
  7314. if( this.lastIndex >= this.keys.length ) {
  7315. this.setResult( this.keys[ this.keys.length - 1 ].value );
  7316. return this.result;
  7317. }
  7318. if( this.lastIndex === 0 ) {
  7319. this.setResult( this.keys[ 0 ].value );
  7320. return this.result;
  7321. }
  7322. var prevKey = this.keys[ this.lastIndex - 1 ];
  7323. this.setResult( prevKey.value );
  7324. // if true, means that prev/current keys are identical, thus no interpolation required.
  7325. if( prevKey.constantToNext ) {
  7326. return this.result;
  7327. }
  7328. // linear interpolation to start with
  7329. var currentKey = this.keys[ this.lastIndex ];
  7330. var alpha = ( time - prevKey.time ) / ( currentKey.time - prevKey.time );
  7331. this.result = this.lerpValues( this.result, currentKey.value, alpha );
  7332. return this.result;
  7333. },
  7334. // move all keyframes either forwards or backwards in time
  7335. shift: function( timeOffset ) {
  7336. if( timeOffset !== 0.0 ) {
  7337. for( var i = 0; i < this.keys.length; i ++ ) {
  7338. this.keys[i].time += timeOffset;
  7339. }
  7340. }
  7341. return this;
  7342. },
  7343. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  7344. scale: function( timeScale ) {
  7345. if( timeScale !== 1.0 ) {
  7346. for( var i = 0; i < this.keys.length; i ++ ) {
  7347. this.keys[i].time *= timeScale;
  7348. }
  7349. }
  7350. return this;
  7351. },
  7352. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  7353. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  7354. trim: function( startTime, endTime ) {
  7355. var firstKeysToRemove = 0;
  7356. for( var i = 1; i < this.keys.length; i ++ ) {
  7357. if( this.keys[i] <= startTime ) {
  7358. firstKeysToRemove ++;
  7359. }
  7360. }
  7361. var lastKeysToRemove = 0;
  7362. for( var i = this.keys.length - 2; i > 0; i ++ ) {
  7363. if( this.keys[i] >= endTime ) {
  7364. lastKeysToRemove ++;
  7365. }
  7366. else {
  7367. break;
  7368. }
  7369. }
  7370. // remove last keys first because it doesn't affect the position of the first keys (the otherway around doesn't work as easily)
  7371. if( ( firstKeysToRemove + lastKeysToRemove ) > 0 ) {
  7372. this.keys = this.keys.splice( firstKeysToRemove, this.keys.length - lastKeysToRemove - firstKeysToRemove );;
  7373. }
  7374. return this;
  7375. },
  7376. /* NOTE: This is commented out because we really shouldn't have to handle unsorted key lists
  7377. Tracks with out of order keys should be considered to be invalid. - bhouston
  7378. sort: function() {
  7379. this.keys.sort( THREE.KeyframeTrack.keyComparer );
  7380. return this;
  7381. },*/
  7382. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  7383. // One could eventually ensure that all key.values in a track are all of the same type (otherwise interpolation makes no sense.)
  7384. validate: function() {
  7385. var prevKey = null;
  7386. if( this.keys.length === 0 ) {
  7387. console.error( " track is empty, no keys", this );
  7388. return;
  7389. }
  7390. for( var i = 0; i < this.keys.length; i ++ ) {
  7391. var currKey = this.keys[i];
  7392. if( ! currKey ) {
  7393. console.error( " key is null in track", this, i );
  7394. return;
  7395. }
  7396. if( ( typeof currKey.time ) !== 'number' || Number.isNaN( currKey.time ) ) {
  7397. console.error( " key.time is not a valid number", this, i, currKey );
  7398. return;
  7399. }
  7400. if( currKey.value === undefined || currKey.value === null) {
  7401. console.error( " key.value is null in track", this, i, currKey );
  7402. return;
  7403. }
  7404. if( prevKey && prevKey.time > currKey.time ) {
  7405. console.error( " key.time is less than previous key time, out of order keys", this, i, currKey, prevKey );
  7406. return;
  7407. }
  7408. prevKey = currKey;
  7409. }
  7410. return this;
  7411. },
  7412. // currently only removes equivalent sequential keys (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0), which are common in morph target animations
  7413. optimize: function() {
  7414. var newKeys = [];
  7415. var prevKey = this.keys[0];
  7416. newKeys.push( prevKey );
  7417. var equalsFunc = THREE.AnimationUtils.getEqualsFunc( prevKey.value );
  7418. for( var i = 1; i < this.keys.length - 1; i ++ ) {
  7419. var currKey = this.keys[i];
  7420. var nextKey = this.keys[i+1];
  7421. // if prevKey & currKey are the same time, remove currKey. If you want immediate adjacent keys, use an epsilon offset
  7422. // it is not possible to have two keys at the same time as we sort them. The sort is not stable on keys with the same time.
  7423. if( ( prevKey.time === currKey.time ) ) {
  7424. continue;
  7425. }
  7426. // remove completely unnecessary keyframes that are the same as their prev and next keys
  7427. if( this.compareValues( prevKey.value, currKey.value ) && this.compareValues( currKey.value, nextKey.value ) ) {
  7428. continue;
  7429. }
  7430. // determine if interpolation is required
  7431. prevKey.constantToNext = this.compareValues( prevKey.value, currKey.value );
  7432. newKeys.push( currKey );
  7433. prevKey = currKey;
  7434. }
  7435. newKeys.push( this.keys[ this.keys.length - 1 ] );
  7436. this.keys = newKeys;
  7437. return this;
  7438. }
  7439. };
  7440. THREE.KeyframeTrack.keyComparer = function keyComparator(key0, key1) {
  7441. return key0.time - key1.time;
  7442. };
  7443. THREE.KeyframeTrack.parse = function( json ) {
  7444. if( json.type === undefined ) throw new Error( "track type undefined, can not parse" );
  7445. var trackType = THREE.KeyframeTrack.GetTrackTypeForTypeName( json.type );
  7446. return trackType.parse( json );
  7447. };
  7448. THREE.KeyframeTrack.GetTrackTypeForTypeName = function( typeName ) {
  7449. switch( typeName.toLowerCase() ) {
  7450. case "vector":
  7451. case "vector2":
  7452. case "vector3":
  7453. case "vector4":
  7454. return THREE.VectorKeyframeTrack;
  7455. case "quaternion":
  7456. return THREE.QuaternionKeyframeTrack;
  7457. case "integer":
  7458. case "scalar":
  7459. case "double":
  7460. case "float":
  7461. case "number":
  7462. return THREE.NumberKeyframeTrack;
  7463. case "bool":
  7464. case "boolean":
  7465. return THREE.BooleanKeyframeTrack;
  7466. case "string":
  7467. return THREE.StringKeyframeTrack;
  7468. };
  7469. throw new Error( "Unsupported typeName: " + typeName );
  7470. };
  7471. // File:src/animation/PropertyBinding.js
  7472. /**
  7473. *
  7474. * A track bound to a real value in the scene graph.
  7475. *
  7476. * @author Ben Houston / http://clara.io/
  7477. * @author David Sarno / http://lighthaus.us/
  7478. */
  7479. THREE.PropertyBinding = function ( rootNode, trackName ) {
  7480. this.rootNode = rootNode;
  7481. this.trackName = trackName;
  7482. this.referenceCount = 0;
  7483. this.originalValue = null; // the value of the property before it was controlled by this binding
  7484. var parseResults = THREE.PropertyBinding.parseTrackName( trackName );
  7485. this.directoryName = parseResults.directoryName;
  7486. this.nodeName = parseResults.nodeName;
  7487. this.objectName = parseResults.objectName;
  7488. this.objectIndex = parseResults.objectIndex;
  7489. this.propertyName = parseResults.propertyName;
  7490. this.propertyIndex = parseResults.propertyIndex;
  7491. this.node = THREE.PropertyBinding.findNode( rootNode, this.nodeName ) || rootNode;
  7492. this.cumulativeValue = null;
  7493. this.cumulativeWeight = 0;
  7494. };
  7495. THREE.PropertyBinding.prototype = {
  7496. constructor: THREE.PropertyBinding,
  7497. reset: function() {
  7498. this.cumulativeValue = null;
  7499. this.cumulativeWeight = 0;
  7500. },
  7501. accumulate: function( value, weight ) {
  7502. if( ! this.isBound ) this.bind();
  7503. if( this.cumulativeWeight === 0 ) {
  7504. if( weight > 0 ) {
  7505. if( this.cumulativeValue === null ) {
  7506. this.cumulativeValue = THREE.AnimationUtils.clone( value );
  7507. }
  7508. this.cumulativeWeight = weight;
  7509. }
  7510. }
  7511. else {
  7512. var lerpAlpha = weight / ( this.cumulativeWeight + weight );
  7513. this.cumulativeValue = this.lerpValue( this.cumulativeValue, value, lerpAlpha );
  7514. this.cumulativeWeight += weight;
  7515. }
  7516. },
  7517. unbind: function() {
  7518. if( ! this.isBound ) return;
  7519. this.setValue( this.originalValue );
  7520. this.setValue = null;
  7521. this.getValue = null;
  7522. this.lerpValue = null;
  7523. this.equalsValue = null;
  7524. this.triggerDirty = null;
  7525. this.isBound = false;
  7526. },
  7527. // bind to the real property in the scene graph, remember original value, memorize various accessors for speed/inefficiency
  7528. bind: function() {
  7529. if( this.isBound ) return;
  7530. var targetObject = this.node;
  7531. // ensure there is a value node
  7532. if( ! targetObject ) {
  7533. console.error( " trying to update node for track: " + this.trackName + " but it wasn't found." );
  7534. return;
  7535. }
  7536. if( this.objectName ) {
  7537. // special case were we need to reach deeper into the hierarchy to get the face materials....
  7538. if( this.objectName === "materials" ) {
  7539. if( ! targetObject.material ) {
  7540. console.error( ' can not bind to material as node does not have a material', this );
  7541. return;
  7542. }
  7543. if( ! targetObject.material.materials ) {
  7544. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  7545. return;
  7546. }
  7547. targetObject = targetObject.material.materials;
  7548. }
  7549. else if( this.objectName === "bones" ) {
  7550. if( ! targetObject.skeleton ) {
  7551. console.error( ' can not bind to bones as node does not have a skeleton', this );
  7552. return;
  7553. }
  7554. // potential future optimization: skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  7555. targetObject = targetObject.skeleton.bones;
  7556. // support resolving morphTarget names into indices.
  7557. for( var i = 0; i < targetObject.length; i ++ ) {
  7558. if( targetObject[i].name === this.objectIndex ) {
  7559. this.objectIndex = i;
  7560. break;
  7561. }
  7562. }
  7563. }
  7564. else {
  7565. if( targetObject[ this.objectName ] === undefined ) {
  7566. console.error( ' can not bind to objectName of node, undefined', this );
  7567. return;
  7568. }
  7569. targetObject = targetObject[ this.objectName ];
  7570. }
  7571. if( this.objectIndex !== undefined ) {
  7572. if( targetObject[ this.objectIndex ] === undefined ) {
  7573. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  7574. return;
  7575. }
  7576. targetObject = targetObject[ this.objectIndex ];
  7577. }
  7578. }
  7579. // special case mappings
  7580. var nodeProperty = targetObject[ this.propertyName ];
  7581. if( ! nodeProperty ) {
  7582. console.error( " trying to update property for track: " + this.nodeName + '.' + this.propertyName + " but it wasn't found.", targetObject );
  7583. return;
  7584. }
  7585. // access a sub element of the property array (only primitives are supported right now)
  7586. if( this.propertyIndex !== undefined ) {
  7587. if( this.propertyName === "morphTargetInfluences" ) {
  7588. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  7589. // support resolving morphTarget names into indices.
  7590. if( ! targetObject.geometry ) {
  7591. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  7592. }
  7593. if( ! targetObject.geometry.morphTargets ) {
  7594. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  7595. }
  7596. for( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  7597. if( targetObject.geometry.morphTargets[i].name === this.propertyIndex ) {
  7598. this.propertyIndex = i;
  7599. break;
  7600. }
  7601. }
  7602. }
  7603. this.setValue = function setValue_propertyIndexed( value ) {
  7604. if( ! this.equalsValue( nodeProperty[ this.propertyIndex ], value ) ) {
  7605. nodeProperty[ this.propertyIndex ] = value;
  7606. return true;
  7607. }
  7608. return false;
  7609. };
  7610. this.getValue = function getValue_propertyIndexed() {
  7611. return nodeProperty[ this.propertyIndex ];
  7612. };
  7613. }
  7614. // must use copy for Object3D.Euler/Quaternion
  7615. else if( nodeProperty.copy ) {
  7616. this.setValue = function setValue_propertyObject( value ) {
  7617. if( ! this.equalsValue( nodeProperty, value ) ) {
  7618. nodeProperty.copy( value );
  7619. return true;
  7620. }
  7621. return false;
  7622. }
  7623. this.getValue = function getValue_propertyObject() {
  7624. return nodeProperty;
  7625. };
  7626. }
  7627. // otherwise just set the property directly on the node (do not use nodeProperty as it may not be a reference object)
  7628. else {
  7629. this.setValue = function setValue_property( value ) {
  7630. if( ! this.equalsValue( targetObject[ this.propertyName ], value ) ) {
  7631. targetObject[ this.propertyName ] = value;
  7632. return true;
  7633. }
  7634. return false;
  7635. }
  7636. this.getValue = function getValue_property() {
  7637. return targetObject[ this.propertyName ];
  7638. };
  7639. }
  7640. // trigger node dirty
  7641. if( targetObject.needsUpdate !== undefined ) { // material
  7642. this.triggerDirty = function triggerDirty_needsUpdate() {
  7643. this.node.needsUpdate = true;
  7644. }
  7645. }
  7646. else if( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  7647. this.triggerDirty = function triggerDirty_matrixWorldNeedsUpdate() {
  7648. targetObject.matrixWorldNeedsUpdate = true;
  7649. }
  7650. }
  7651. this.originalValue = this.getValue();
  7652. this.equalsValue = THREE.AnimationUtils.getEqualsFunc( this.originalValue );
  7653. this.lerpValue = THREE.AnimationUtils.getLerpFunc( this.originalValue, true );
  7654. this.isBound = true;
  7655. },
  7656. apply: function() {
  7657. // for speed capture the setter pattern as a closure (sort of a memoization pattern: https://en.wikipedia.org/wiki/Memoization)
  7658. if( ! this.isBound ) this.bind();
  7659. // early exit if there is nothing to apply.
  7660. if( this.cumulativeWeight > 0 ) {
  7661. // blend with original value
  7662. if( this.cumulativeWeight < 1 ) {
  7663. var remainingWeight = 1 - this.cumulativeWeight;
  7664. var lerpAlpha = remainingWeight / ( this.cumulativeWeight + remainingWeight );
  7665. this.cumulativeValue = this.lerpValue( this.cumulativeValue, this.originalValue, lerpAlpha );
  7666. }
  7667. var valueChanged = this.setValue( this.cumulativeValue );
  7668. if( valueChanged && this.triggerDirty ) {
  7669. this.triggerDirty();
  7670. }
  7671. // reset accumulator
  7672. this.cumulativeValue = null;
  7673. this.cumulativeWeight = 0;
  7674. }
  7675. }
  7676. };
  7677. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  7678. // matches strings in the form of:
  7679. // nodeName.property
  7680. // nodeName.property[accessor]
  7681. // nodeName.material.property[accessor]
  7682. // uuid.property[accessor]
  7683. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  7684. // parentName/nodeName.property
  7685. // parentName/parentName/nodeName.property[index]
  7686. // .bone[Armature.DEF_cog].position
  7687. // created and tested via https://regex101.com/#javascript
  7688. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  7689. var matches = re.exec(trackName);
  7690. if( ! matches ) {
  7691. throw new Error( "cannot parse trackName at all: " + trackName );
  7692. }
  7693. if (matches.index === re.lastIndex) {
  7694. re.lastIndex++;
  7695. }
  7696. var results = {
  7697. directoryName: matches[1],
  7698. nodeName: matches[3], // allowed to be null, specified root node.
  7699. objectName: matches[5],
  7700. objectIndex: matches[7],
  7701. propertyName: matches[9],
  7702. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  7703. };
  7704. if( results.propertyName === null || results.propertyName.length === 0 ) {
  7705. throw new Error( "can not parse propertyName from trackName: " + trackName );
  7706. }
  7707. return results;
  7708. };
  7709. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  7710. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  7711. return root;
  7712. }
  7713. // search into skeleton bones.
  7714. if( root.skeleton ) {
  7715. var searchSkeleton = function( skeleton ) {
  7716. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  7717. var bone = skeleton.bones[i];
  7718. if( bone.name === nodeName ) {
  7719. return bone;
  7720. }
  7721. }
  7722. return null;
  7723. };
  7724. var bone = searchSkeleton( root.skeleton );
  7725. if( bone ) {
  7726. return bone;
  7727. }
  7728. }
  7729. // search into node subtree.
  7730. if( root.children ) {
  7731. var searchNodeSubtree = function( children ) {
  7732. for( var i = 0; i < children.length; i ++ ) {
  7733. var childNode = children[i];
  7734. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  7735. return childNode;
  7736. }
  7737. var result = searchNodeSubtree( childNode.children );
  7738. if( result ) return result;
  7739. }
  7740. return null;
  7741. };
  7742. var subTreeNode = searchNodeSubtree( root.children );
  7743. if( subTreeNode ) {
  7744. return subTreeNode;
  7745. }
  7746. }
  7747. return null;
  7748. }
  7749. // File:src/animation/tracks/VectorKeyframeTrack.js
  7750. /**
  7751. *
  7752. * A Track that interpolates Vectors
  7753. *
  7754. * @author Ben Houston / http://clara.io/
  7755. * @author David Sarno / http://lighthaus.us/
  7756. */
  7757. THREE.VectorKeyframeTrack = function ( name, keys ) {
  7758. THREE.KeyframeTrack.call( this, name, keys );
  7759. // local cache of value type to avoid allocations during runtime.
  7760. this.result = this.keys[0].value.clone();
  7761. };
  7762. THREE.VectorKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7763. THREE.VectorKeyframeTrack.prototype.constructor = THREE.VectorKeyframeTrack;
  7764. THREE.VectorKeyframeTrack.prototype.setResult = function( value ) {
  7765. this.result.copy( value );
  7766. };
  7767. // memoization of the lerp function for speed.
  7768. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7769. THREE.VectorKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7770. return value0.lerp( value1, alpha );
  7771. };
  7772. THREE.VectorKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7773. return value0.equals( value1 );
  7774. };
  7775. THREE.VectorKeyframeTrack.prototype.clone = function() {
  7776. var clonedKeys = [];
  7777. for( var i = 0; i < this.keys.length; i ++ ) {
  7778. var key = this.keys[i];
  7779. clonedKeys.push( {
  7780. time: key.time,
  7781. value: key.value.clone()
  7782. } );
  7783. }
  7784. return new THREE.VectorKeyframeTrack( this.name, clonedKeys );
  7785. };
  7786. THREE.VectorKeyframeTrack.parse = function( json ) {
  7787. var elementCount = json.keys[0].value.length;
  7788. var valueType = THREE[ 'Vector' + elementCount ];
  7789. var keys = [];
  7790. for( var i = 0; i < json.keys.length; i ++ ) {
  7791. var jsonKey = json.keys[i];
  7792. keys.push( {
  7793. value: new valueType().fromArray( jsonKey.value ),
  7794. time: jsonKey.time
  7795. } );
  7796. }
  7797. return new THREE.VectorKeyframeTrack( json.name, keys );
  7798. };
  7799. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  7800. /**
  7801. *
  7802. * A Track that interpolates Quaternion
  7803. *
  7804. * @author Ben Houston / http://clara.io/
  7805. * @author David Sarno / http://lighthaus.us/
  7806. */
  7807. THREE.QuaternionKeyframeTrack = function ( name, keys ) {
  7808. THREE.KeyframeTrack.call( this, name, keys );
  7809. // local cache of value type to avoid allocations during runtime.
  7810. this.result = this.keys[0].value.clone();
  7811. };
  7812. THREE.QuaternionKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7813. THREE.QuaternionKeyframeTrack.prototype.constructor = THREE.QuaternionKeyframeTrack;
  7814. THREE.QuaternionKeyframeTrack.prototype.setResult = function( value ) {
  7815. this.result.copy( value );
  7816. };
  7817. // memoization of the lerp function for speed.
  7818. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7819. THREE.QuaternionKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7820. return value0.slerp( value1, alpha );
  7821. };
  7822. THREE.QuaternionKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7823. return value0.equals( value1 );
  7824. };
  7825. THREE.QuaternionKeyframeTrack.prototype.multiply = function( quat ) {
  7826. for( var i = 0; i < this.keys.length; i ++ ) {
  7827. this.keys[i].value.multiply( quat );
  7828. }
  7829. return this;
  7830. };
  7831. THREE.QuaternionKeyframeTrack.prototype.clone = function() {
  7832. var clonedKeys = [];
  7833. for( var i = 0; i < this.keys.length; i ++ ) {
  7834. var key = this.keys[i];
  7835. clonedKeys.push( {
  7836. time: key.time,
  7837. value: key.value.clone()
  7838. } );
  7839. }
  7840. return new THREE.QuaternionKeyframeTrack( this.name, clonedKeys );
  7841. };
  7842. THREE.QuaternionKeyframeTrack.parse = function( json ) {
  7843. var keys = [];
  7844. for( var i = 0; i < json.keys.length; i ++ ) {
  7845. var jsonKey = json.keys[i];
  7846. keys.push( {
  7847. value: new THREE.Quaternion().fromArray( jsonKey.value ),
  7848. time: jsonKey.time
  7849. } );
  7850. }
  7851. return new THREE.QuaternionKeyframeTrack( json.name, keys );
  7852. };
  7853. // File:src/animation/tracks/StringKeyframeTrack.js
  7854. /**
  7855. *
  7856. * A Track that interpolates Strings
  7857. *
  7858. * @author Ben Houston / http://clara.io/
  7859. * @author David Sarno / http://lighthaus.us/
  7860. */
  7861. THREE.StringKeyframeTrack = function ( name, keys ) {
  7862. THREE.KeyframeTrack.call( this, name, keys );
  7863. // local cache of value type to avoid allocations during runtime.
  7864. this.result = this.keys[0].value;
  7865. };
  7866. THREE.StringKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7867. THREE.StringKeyframeTrack.prototype.constructor = THREE.StringKeyframeTrack;
  7868. THREE.StringKeyframeTrack.prototype.setResult = function( value ) {
  7869. this.result = value;
  7870. };
  7871. // memoization of the lerp function for speed.
  7872. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7873. THREE.StringKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7874. return ( alpha < 1.0 ) ? value0 : value1;
  7875. };
  7876. THREE.StringKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7877. return ( value0 === value1 );
  7878. };
  7879. THREE.StringKeyframeTrack.prototype.clone = function() {
  7880. var clonedKeys = [];
  7881. for( var i = 0; i < this.keys.length; i ++ ) {
  7882. var key = this.keys[i];
  7883. clonedKeys.push( {
  7884. time: key.time,
  7885. value: key.value
  7886. } );
  7887. }
  7888. return new THREE.StringKeyframeTrack( this.name, clonedKeys );
  7889. };
  7890. THREE.StringKeyframeTrack.parse = function( json ) {
  7891. return new THREE.StringKeyframeTrack( json.name, json.keys );
  7892. };
  7893. // File:src/animation/tracks/BooleanKeyframeTrack.js
  7894. /**
  7895. *
  7896. * A Track that interpolates Boolean
  7897. *
  7898. * @author Ben Houston / http://clara.io/
  7899. * @author David Sarno / http://lighthaus.us/
  7900. */
  7901. THREE.BooleanKeyframeTrack = function ( name, keys ) {
  7902. THREE.KeyframeTrack.call( this, name, keys );
  7903. // local cache of value type to avoid allocations during runtime.
  7904. this.result = this.keys[0].value;
  7905. };
  7906. THREE.BooleanKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7907. THREE.BooleanKeyframeTrack.prototype.constructor = THREE.BooleanKeyframeTrack;
  7908. THREE.BooleanKeyframeTrack.prototype.setResult = function( value ) {
  7909. this.result = value;
  7910. };
  7911. // memoization of the lerp function for speed.
  7912. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7913. THREE.BooleanKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7914. return ( alpha < 1.0 ) ? value0 : value1;
  7915. };
  7916. THREE.BooleanKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7917. return ( value0 === value1 );
  7918. };
  7919. THREE.BooleanKeyframeTrack.prototype.clone = function() {
  7920. var clonedKeys = [];
  7921. for( var i = 0; i < this.keys.length; i ++ ) {
  7922. var key = this.keys[i];
  7923. clonedKeys.push( {
  7924. time: key.time,
  7925. value: key.value
  7926. } );
  7927. }
  7928. return new THREE.BooleanKeyframeTrack( this.name, clonedKeys );
  7929. };
  7930. THREE.BooleanKeyframeTrack.parse = function( json ) {
  7931. return new THREE.BooleanKeyframeTrack( json.name, json.keys );
  7932. };
  7933. // File:src/animation/tracks/NumberKeyframeTrack.js
  7934. /**
  7935. *
  7936. * A Track that interpolates Numbers
  7937. *
  7938. * @author Ben Houston / http://clara.io/
  7939. * @author David Sarno / http://lighthaus.us/
  7940. */
  7941. THREE.NumberKeyframeTrack = function ( name, keys ) {
  7942. THREE.KeyframeTrack.call( this, name, keys );
  7943. // local cache of value type to avoid allocations during runtime.
  7944. this.result = this.keys[0].value;
  7945. };
  7946. THREE.NumberKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7947. THREE.NumberKeyframeTrack.prototype.constructor = THREE.NumberKeyframeTrack;
  7948. THREE.NumberKeyframeTrack.prototype.setResult = function( value ) {
  7949. this.result = value;
  7950. };
  7951. // memoization of the lerp function for speed.
  7952. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7953. THREE.NumberKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7954. return value0 * ( 1 - alpha ) + value1 * alpha;
  7955. };
  7956. THREE.NumberKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7957. return ( value0 === value1 );
  7958. };
  7959. THREE.NumberKeyframeTrack.prototype.clone = function() {
  7960. var clonedKeys = [];
  7961. for( var i = 0; i < this.keys.length; i ++ ) {
  7962. var key = this.keys[i];
  7963. clonedKeys.push( {
  7964. time: key.time,
  7965. value: key.value
  7966. } );
  7967. }
  7968. return new THREE.NumberKeyframeTrack( this.name, clonedKeys );
  7969. };
  7970. THREE.NumberKeyframeTrack.parse = function( json ) {
  7971. return new THREE.NumberKeyframeTrack( json.name, json.keys );
  7972. };
  7973. // File:src/cameras/Camera.js
  7974. /**
  7975. * @author mrdoob / http://mrdoob.com/
  7976. * @author mikael emtinger / http://gomo.se/
  7977. * @author WestLangley / http://github.com/WestLangley
  7978. */
  7979. THREE.Camera = function () {
  7980. THREE.Object3D.call( this );
  7981. this.type = 'Camera';
  7982. this.matrixWorldInverse = new THREE.Matrix4();
  7983. this.projectionMatrix = new THREE.Matrix4();
  7984. };
  7985. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  7986. THREE.Camera.prototype.constructor = THREE.Camera;
  7987. THREE.Camera.prototype.getWorldDirection = function () {
  7988. var quaternion = new THREE.Quaternion();
  7989. return function ( optionalTarget ) {
  7990. var result = optionalTarget || new THREE.Vector3();
  7991. this.getWorldQuaternion( quaternion );
  7992. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  7993. };
  7994. }();
  7995. THREE.Camera.prototype.lookAt = function () {
  7996. // This routine does not support cameras with rotated and/or translated parent(s)
  7997. var m1 = new THREE.Matrix4();
  7998. return function ( vector ) {
  7999. m1.lookAt( this.position, vector, this.up );
  8000. this.quaternion.setFromRotationMatrix( m1 );
  8001. };
  8002. }();
  8003. THREE.Camera.prototype.clone = function () {
  8004. return new this.constructor().copy( this );
  8005. };
  8006. THREE.Camera.prototype.copy = function ( source ) {
  8007. THREE.Object3D.prototype.copy.call( this, source );
  8008. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  8009. this.projectionMatrix.copy( source.projectionMatrix );
  8010. return this;
  8011. };
  8012. // File:src/cameras/CubeCamera.js
  8013. /**
  8014. * Camera for rendering cube maps
  8015. * - renders scene into axis-aligned cube
  8016. *
  8017. * @author alteredq / http://alteredqualia.com/
  8018. */
  8019. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  8020. THREE.Object3D.call( this );
  8021. this.type = 'CubeCamera';
  8022. var fov = 90, aspect = 1;
  8023. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8024. cameraPX.up.set( 0, - 1, 0 );
  8025. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  8026. this.add( cameraPX );
  8027. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8028. cameraNX.up.set( 0, - 1, 0 );
  8029. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  8030. this.add( cameraNX );
  8031. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8032. cameraPY.up.set( 0, 0, 1 );
  8033. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  8034. this.add( cameraPY );
  8035. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8036. cameraNY.up.set( 0, 0, - 1 );
  8037. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  8038. this.add( cameraNY );
  8039. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8040. cameraPZ.up.set( 0, - 1, 0 );
  8041. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  8042. this.add( cameraPZ );
  8043. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8044. cameraNZ.up.set( 0, - 1, 0 );
  8045. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  8046. this.add( cameraNZ );
  8047. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  8048. this.updateCubeMap = function ( renderer, scene ) {
  8049. if ( this.parent === null ) this.updateMatrixWorld();
  8050. var renderTarget = this.renderTarget;
  8051. var generateMipmaps = renderTarget.generateMipmaps;
  8052. renderTarget.generateMipmaps = false;
  8053. renderTarget.activeCubeFace = 0;
  8054. renderer.render( scene, cameraPX, renderTarget );
  8055. renderTarget.activeCubeFace = 1;
  8056. renderer.render( scene, cameraNX, renderTarget );
  8057. renderTarget.activeCubeFace = 2;
  8058. renderer.render( scene, cameraPY, renderTarget );
  8059. renderTarget.activeCubeFace = 3;
  8060. renderer.render( scene, cameraNY, renderTarget );
  8061. renderTarget.activeCubeFace = 4;
  8062. renderer.render( scene, cameraPZ, renderTarget );
  8063. renderTarget.generateMipmaps = generateMipmaps;
  8064. renderTarget.activeCubeFace = 5;
  8065. renderer.render( scene, cameraNZ, renderTarget );
  8066. renderer.setRenderTarget( null );
  8067. };
  8068. };
  8069. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  8070. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  8071. // File:src/cameras/OrthographicCamera.js
  8072. /**
  8073. * @author alteredq / http://alteredqualia.com/
  8074. */
  8075. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  8076. THREE.Camera.call( this );
  8077. this.type = 'OrthographicCamera';
  8078. this.zoom = 1;
  8079. this.left = left;
  8080. this.right = right;
  8081. this.top = top;
  8082. this.bottom = bottom;
  8083. this.near = ( near !== undefined ) ? near : 0.1;
  8084. this.far = ( far !== undefined ) ? far : 2000;
  8085. this.updateProjectionMatrix();
  8086. };
  8087. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  8088. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  8089. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  8090. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  8091. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  8092. var cx = ( this.right + this.left ) / 2;
  8093. var cy = ( this.top + this.bottom ) / 2;
  8094. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  8095. };
  8096. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  8097. THREE.Camera.prototype.copy.call( this, source );
  8098. this.left = source.left;
  8099. this.right = source.right;
  8100. this.top = source.top;
  8101. this.bottom = source.bottom;
  8102. this.near = source.near;
  8103. this.far = source.far;
  8104. this.zoom = source.zoom;
  8105. return this;
  8106. };
  8107. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  8108. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8109. data.object.zoom = this.zoom;
  8110. data.object.left = this.left;
  8111. data.object.right = this.right;
  8112. data.object.top = this.top;
  8113. data.object.bottom = this.bottom;
  8114. data.object.near = this.near;
  8115. data.object.far = this.far;
  8116. return data;
  8117. };
  8118. // File:src/cameras/PerspectiveCamera.js
  8119. /**
  8120. * @author mrdoob / http://mrdoob.com/
  8121. * @author greggman / http://games.greggman.com/
  8122. * @author zz85 / http://www.lab4games.net/zz85/blog
  8123. */
  8124. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  8125. THREE.Camera.call( this );
  8126. this.type = 'PerspectiveCamera';
  8127. this.zoom = 1;
  8128. this.fov = fov !== undefined ? fov : 50;
  8129. this.aspect = aspect !== undefined ? aspect : 1;
  8130. this.near = near !== undefined ? near : 0.1;
  8131. this.far = far !== undefined ? far : 2000;
  8132. this.updateProjectionMatrix();
  8133. };
  8134. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  8135. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  8136. /**
  8137. * Uses Focal Length (in mm) to estimate and set FOV
  8138. * 35mm (full-frame) camera is used if frame size is not specified;
  8139. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  8140. */
  8141. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  8142. if ( frameHeight === undefined ) frameHeight = 24;
  8143. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  8144. this.updateProjectionMatrix();
  8145. };
  8146. /**
  8147. * Sets an offset in a larger frustum. This is useful for multi-window or
  8148. * multi-monitor/multi-machine setups.
  8149. *
  8150. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8151. * the monitors are in grid like this
  8152. *
  8153. * +---+---+---+
  8154. * | A | B | C |
  8155. * +---+---+---+
  8156. * | D | E | F |
  8157. * +---+---+---+
  8158. *
  8159. * then for each monitor you would call it like this
  8160. *
  8161. * var w = 1920;
  8162. * var h = 1080;
  8163. * var fullWidth = w * 3;
  8164. * var fullHeight = h * 2;
  8165. *
  8166. * --A--
  8167. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8168. * --B--
  8169. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8170. * --C--
  8171. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8172. * --D--
  8173. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8174. * --E--
  8175. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8176. * --F--
  8177. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8178. *
  8179. * Note there is no reason monitors have to be the same size or in a grid.
  8180. */
  8181. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  8182. this.fullWidth = fullWidth;
  8183. this.fullHeight = fullHeight;
  8184. this.x = x;
  8185. this.y = y;
  8186. this.width = width;
  8187. this.height = height;
  8188. this.updateProjectionMatrix();
  8189. };
  8190. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  8191. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  8192. if ( this.fullWidth ) {
  8193. var aspect = this.fullWidth / this.fullHeight;
  8194. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  8195. var bottom = - top;
  8196. var left = aspect * bottom;
  8197. var right = aspect * top;
  8198. var width = Math.abs( right - left );
  8199. var height = Math.abs( top - bottom );
  8200. this.projectionMatrix.makeFrustum(
  8201. left + this.x * width / this.fullWidth,
  8202. left + ( this.x + this.width ) * width / this.fullWidth,
  8203. top - ( this.y + this.height ) * height / this.fullHeight,
  8204. top - this.y * height / this.fullHeight,
  8205. this.near,
  8206. this.far
  8207. );
  8208. } else {
  8209. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  8210. }
  8211. };
  8212. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  8213. THREE.Camera.prototype.copy.call( this, source );
  8214. this.fov = source.fov;
  8215. this.aspect = source.aspect;
  8216. this.near = source.near;
  8217. this.far = source.far;
  8218. this.zoom = source.zoom;
  8219. return this;
  8220. };
  8221. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  8222. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8223. data.object.zoom = this.zoom;
  8224. data.object.fov = this.fov;
  8225. data.object.aspect = this.aspect;
  8226. data.object.near = this.near;
  8227. data.object.far = this.far;
  8228. return data;
  8229. };
  8230. // File:src/lights/Light.js
  8231. /**
  8232. * @author mrdoob / http://mrdoob.com/
  8233. * @author alteredq / http://alteredqualia.com/
  8234. */
  8235. THREE.Light = function ( color ) {
  8236. THREE.Object3D.call( this );
  8237. this.type = 'Light';
  8238. this.color = new THREE.Color( color );
  8239. };
  8240. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  8241. THREE.Light.prototype.constructor = THREE.Light;
  8242. THREE.Light.prototype.copy = function ( source ) {
  8243. THREE.Object3D.prototype.copy.call( this, source );
  8244. this.color.copy( source.color );
  8245. return this;
  8246. };
  8247. // File:src/lights/AmbientLight.js
  8248. /**
  8249. * @author mrdoob / http://mrdoob.com/
  8250. */
  8251. THREE.AmbientLight = function ( color ) {
  8252. THREE.Light.call( this, color );
  8253. this.type = 'AmbientLight';
  8254. };
  8255. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  8256. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  8257. THREE.AmbientLight.prototype.toJSON = function ( meta ) {
  8258. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8259. data.object.color = this.color.getHex();
  8260. return data;
  8261. };
  8262. // File:src/lights/DirectionalLight.js
  8263. /**
  8264. * @author mrdoob / http://mrdoob.com/
  8265. * @author alteredq / http://alteredqualia.com/
  8266. */
  8267. THREE.DirectionalLight = function ( color, intensity ) {
  8268. THREE.Light.call( this, color );
  8269. this.type = 'DirectionalLight';
  8270. this.position.set( 0, 1, 0 );
  8271. this.updateMatrix();
  8272. this.target = new THREE.Object3D();
  8273. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8274. this.castShadow = false;
  8275. this.onlyShadow = false;
  8276. this.shadowCameraNear = 50;
  8277. this.shadowCameraFar = 5000;
  8278. this.shadowCameraLeft = - 500;
  8279. this.shadowCameraRight = 500;
  8280. this.shadowCameraTop = 500;
  8281. this.shadowCameraBottom = - 500;
  8282. this.shadowCameraVisible = false;
  8283. this.shadowBias = 0;
  8284. this.shadowDarkness = 0.5;
  8285. this.shadowMapWidth = 512;
  8286. this.shadowMapHeight = 512;
  8287. this.shadowMap = null;
  8288. this.shadowMapSize = null;
  8289. this.shadowCamera = null;
  8290. this.shadowMatrix = null;
  8291. };
  8292. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  8293. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  8294. THREE.DirectionalLight.prototype.copy = function ( source ) {
  8295. THREE.Light.prototype.copy.call( this, source );
  8296. this.intensity = source.intensity;
  8297. this.target = source.target.clone();
  8298. this.castShadow = source.castShadow;
  8299. this.onlyShadow = source.onlyShadow;
  8300. this.shadowCameraNear = source.shadowCameraNear;
  8301. this.shadowCameraFar = source.shadowCameraFar;
  8302. this.shadowCameraLeft = source.shadowCameraLeft;
  8303. this.shadowCameraRight = source.shadowCameraRight;
  8304. this.shadowCameraTop = source.shadowCameraTop;
  8305. this.shadowCameraBottom = source.shadowCameraBottom;
  8306. this.shadowCameraVisible = source.shadowCameraVisible;
  8307. this.shadowBias = source.shadowBias;
  8308. this.shadowDarkness = source.shadowDarkness;
  8309. this.shadowMapWidth = source.shadowMapWidth;
  8310. this.shadowMapHeight = source.shadowMapHeight;
  8311. return this;
  8312. };
  8313. THREE.DirectionalLight.prototype.toJSON = function ( meta ) {
  8314. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8315. data.object.color = this.color.getHex();
  8316. data.object.intensity = this.intensity;
  8317. return data;
  8318. };
  8319. // File:src/lights/HemisphereLight.js
  8320. /**
  8321. * @author alteredq / http://alteredqualia.com/
  8322. */
  8323. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  8324. THREE.Light.call( this, skyColor );
  8325. this.type = 'HemisphereLight';
  8326. this.position.set( 0, 1, 0 );
  8327. this.updateMatrix();
  8328. this.groundColor = new THREE.Color( groundColor );
  8329. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8330. };
  8331. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  8332. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  8333. THREE.HemisphereLight.prototype.copy = function ( source ) {
  8334. THREE.Light.prototype.copy.call( this, source );
  8335. this.groundColor.copy( source.groundColor );
  8336. this.intensity = source.intensity;
  8337. return this;
  8338. };
  8339. THREE.HemisphereLight.prototype.toJSON = function ( meta ) {
  8340. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8341. data.object.color = this.color.getHex();
  8342. data.object.groundColor = this.groundColor.getHex();
  8343. data.object.intensity = this.intensity;
  8344. return data;
  8345. };
  8346. // File:src/lights/PointLight.js
  8347. /**
  8348. * @author mrdoob / http://mrdoob.com/
  8349. */
  8350. THREE.PointLight = function ( color, intensity, distance, decay ) {
  8351. THREE.Light.call( this, color );
  8352. this.type = 'PointLight';
  8353. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8354. this.distance = ( distance !== undefined ) ? distance : 0;
  8355. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  8356. this.castShadow = false;
  8357. this.onlyShadow = false;
  8358. //
  8359. this.shadowCameraNear = 1;
  8360. this.shadowCameraFar = 500;
  8361. this.shadowCameraFov = 90;
  8362. this.shadowCameraVisible = false;
  8363. this.shadowBias = 0;
  8364. this.shadowDarkness = 0.5;
  8365. this.shadowMapWidth = 512;
  8366. this.shadowMapHeight = 512;
  8367. //
  8368. this.shadowMap = null;
  8369. this.shadowMapSize = null;
  8370. this.shadowCamera = null;
  8371. this.shadowMatrix = null;
  8372. };
  8373. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  8374. THREE.PointLight.prototype.constructor = THREE.PointLight;
  8375. THREE.PointLight.prototype.copy = function ( source ) {
  8376. THREE.Light.prototype.copy.call( this, source );
  8377. this.intensity = source.intensity;
  8378. this.distance = source.distance;
  8379. this.decay = source.decay;
  8380. this.castShadow = source.castShadow;
  8381. this.onlyShadow = source.onlyShadow;
  8382. this.shadowCameraNear = source.shadowCameraNear;
  8383. this.shadowCameraFar = source.shadowCameraFar;
  8384. this.shadowCameraFov = source.shadowCameraFov;
  8385. this.shadowCameraVisible = source.shadowCameraVisible;
  8386. this.shadowBias = source.shadowBias;
  8387. this.shadowDarkness = source.shadowDarkness;
  8388. this.shadowMapWidth = source.shadowMapWidth;
  8389. this.shadowMapHeight = source.shadowMapHeight;
  8390. return this;
  8391. };
  8392. THREE.PointLight.prototype.toJSON = function ( meta ) {
  8393. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8394. data.object.color = this.color.getHex();
  8395. data.object.intensity = this.intensity;
  8396. data.object.distance = this.distance;
  8397. data.object.decay = this.decay;
  8398. return data;
  8399. };
  8400. // File:src/lights/SpotLight.js
  8401. /**
  8402. * @author alteredq / http://alteredqualia.com/
  8403. */
  8404. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  8405. THREE.Light.call( this, color );
  8406. this.type = 'SpotLight';
  8407. this.position.set( 0, 1, 0 );
  8408. this.updateMatrix();
  8409. this.target = new THREE.Object3D();
  8410. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8411. this.distance = ( distance !== undefined ) ? distance : 0;
  8412. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  8413. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  8414. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  8415. this.castShadow = false;
  8416. this.onlyShadow = false;
  8417. this.shadowCameraNear = 50;
  8418. this.shadowCameraFar = 5000;
  8419. this.shadowCameraFov = 50;
  8420. this.shadowCameraVisible = false;
  8421. this.shadowBias = 0;
  8422. this.shadowDarkness = 0.5;
  8423. this.shadowMapWidth = 512;
  8424. this.shadowMapHeight = 512;
  8425. this.shadowMap = null;
  8426. this.shadowMapSize = null;
  8427. this.shadowCamera = null;
  8428. this.shadowMatrix = null;
  8429. };
  8430. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  8431. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  8432. THREE.SpotLight.prototype.copy = function ( source ) {
  8433. THREE.Light.prototype.copy.call( this, source );
  8434. this.intensity = source.intensity;
  8435. this.distance = source.distance;
  8436. this.angle = source.angle;
  8437. this.exponent = source.exponent;
  8438. this.decay = source.decay;
  8439. this.target = source.target.clone();
  8440. this.castShadow = source.castShadow;
  8441. this.onlyShadow = source.onlyShadow;
  8442. this.shadowCameraNear = source.shadowCameraNear;
  8443. this.shadowCameraFar = source.shadowCameraFar;
  8444. this.shadowCameraFov = source.shadowCameraFov;
  8445. this.shadowCameraVisible = source.shadowCameraVisible;
  8446. this.shadowBias = source.shadowBias;
  8447. this.shadowDarkness = source.shadowDarkness;
  8448. this.shadowMapWidth = source.shadowMapWidth;
  8449. this.shadowMapHeight = source.shadowMapHeight;
  8450. return this;
  8451. }
  8452. THREE.SpotLight.prototype.toJSON = function ( meta ) {
  8453. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8454. data.object.color = this.color.getHex();
  8455. data.object.intensity = this.intensity;
  8456. data.object.distance = this.distance;
  8457. data.object.angle = this.angle;
  8458. data.object.exponent = this.exponent;
  8459. data.object.decay = this.decay;
  8460. return data;
  8461. };
  8462. // File:src/loaders/Cache.js
  8463. /**
  8464. * @author mrdoob / http://mrdoob.com/
  8465. */
  8466. THREE.Cache = {
  8467. enabled: false,
  8468. files: {},
  8469. add: function ( key, file ) {
  8470. if ( this.enabled === false ) return;
  8471. // console.log( 'THREE.Cache', 'Adding key:', key );
  8472. this.files[ key ] = file;
  8473. },
  8474. get: function ( key ) {
  8475. if ( this.enabled === false ) return;
  8476. // console.log( 'THREE.Cache', 'Checking key:', key );
  8477. return this.files[ key ];
  8478. },
  8479. remove: function ( key ) {
  8480. delete this.files[ key ];
  8481. },
  8482. clear: function () {
  8483. this.files = {};
  8484. }
  8485. };
  8486. // File:src/loaders/Loader.js
  8487. /**
  8488. * @author alteredq / http://alteredqualia.com/
  8489. */
  8490. THREE.Loader = function () {
  8491. this.onLoadStart = function () {};
  8492. this.onLoadProgress = function () {};
  8493. this.onLoadComplete = function () {};
  8494. };
  8495. THREE.Loader.prototype = {
  8496. constructor: THREE.Loader,
  8497. crossOrigin: undefined,
  8498. extractUrlBase: function ( url ) {
  8499. var parts = url.split( '/' );
  8500. if ( parts.length === 1 ) return './';
  8501. parts.pop();
  8502. return parts.join( '/' ) + '/';
  8503. },
  8504. initMaterials: function ( materials, texturePath, crossOrigin ) {
  8505. var array = [];
  8506. for ( var i = 0; i < materials.length; ++ i ) {
  8507. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  8508. }
  8509. return array;
  8510. },
  8511. createMaterial: ( function () {
  8512. var imageLoader;
  8513. return function createMaterial( m, texturePath, crossOrigin ) {
  8514. var scope = this;
  8515. if ( crossOrigin === undefined && scope.crossOrigin !== undefined ) crossOrigin = scope.crossOrigin;
  8516. if ( imageLoader === undefined ) imageLoader = new THREE.ImageLoader();
  8517. function nearest_pow2( n ) {
  8518. var l = Math.log( n ) / Math.LN2;
  8519. return Math.pow( 2, Math.round( l ) );
  8520. }
  8521. function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
  8522. var fullPath = texturePath + sourceFile;
  8523. var texture;
  8524. var loader = THREE.Loader.Handlers.get( fullPath );
  8525. if ( loader !== null ) {
  8526. texture = loader.load( fullPath );
  8527. } else {
  8528. texture = new THREE.Texture();
  8529. loader = imageLoader;
  8530. loader.setCrossOrigin( crossOrigin );
  8531. loader.load( fullPath, function ( image ) {
  8532. if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
  8533. THREE.Math.isPowerOfTwo( image.height ) === false ) {
  8534. var width = nearest_pow2( image.width );
  8535. var height = nearest_pow2( image.height );
  8536. var canvas = document.createElement( 'canvas' );
  8537. canvas.width = width;
  8538. canvas.height = height;
  8539. var context = canvas.getContext( '2d' );
  8540. context.drawImage( image, 0, 0, width, height );
  8541. texture.image = canvas;
  8542. } else {
  8543. texture.image = image;
  8544. }
  8545. texture.needsUpdate = true;
  8546. } );
  8547. }
  8548. texture.sourceFile = sourceFile;
  8549. if ( repeat ) {
  8550. texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
  8551. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  8552. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  8553. }
  8554. if ( offset ) {
  8555. texture.offset.set( offset[ 0 ], offset[ 1 ] );
  8556. }
  8557. if ( wrap ) {
  8558. var wrapMap = {
  8559. 'repeat': THREE.RepeatWrapping,
  8560. 'mirror': THREE.MirroredRepeatWrapping
  8561. };
  8562. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
  8563. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
  8564. }
  8565. if ( anisotropy ) {
  8566. texture.anisotropy = anisotropy;
  8567. }
  8568. where[ name ] = texture;
  8569. }
  8570. function rgb2hex( rgb ) {
  8571. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  8572. }
  8573. // defaults
  8574. var mtype = 'MeshLambertMaterial';
  8575. var mpars = {};
  8576. // parameters from model file
  8577. if ( m.shading ) {
  8578. var shading = m.shading.toLowerCase();
  8579. if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
  8580. else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
  8581. }
  8582. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  8583. mpars.blending = THREE[ m.blending ];
  8584. }
  8585. if ( m.transparent !== undefined ) {
  8586. mpars.transparent = m.transparent;
  8587. }
  8588. if ( m.opacity !== undefined && m.opacity < 1.0 ) {
  8589. mpars.transparent = true;
  8590. }
  8591. if ( m.depthTest !== undefined ) {
  8592. mpars.depthTest = m.depthTest;
  8593. }
  8594. if ( m.depthWrite !== undefined ) {
  8595. mpars.depthWrite = m.depthWrite;
  8596. }
  8597. if ( m.visible !== undefined ) {
  8598. mpars.visible = m.visible;
  8599. }
  8600. if ( m.flipSided !== undefined ) {
  8601. mpars.side = THREE.BackSide;
  8602. }
  8603. if ( m.doubleSided !== undefined ) {
  8604. mpars.side = THREE.DoubleSide;
  8605. }
  8606. if ( m.wireframe !== undefined ) {
  8607. mpars.wireframe = m.wireframe;
  8608. }
  8609. if ( m.vertexColors !== undefined ) {
  8610. if ( m.vertexColors === 'face' ) {
  8611. mpars.vertexColors = THREE.FaceColors;
  8612. } else if ( m.vertexColors ) {
  8613. mpars.vertexColors = THREE.VertexColors;
  8614. }
  8615. }
  8616. // colors
  8617. if ( m.colorDiffuse ) {
  8618. mpars.color = rgb2hex( m.colorDiffuse );
  8619. } else if ( m.DbgColor ) {
  8620. mpars.color = m.DbgColor;
  8621. }
  8622. if ( m.colorEmissive ) {
  8623. mpars.emissive = rgb2hex( m.colorEmissive );
  8624. }
  8625. if ( mtype === 'MeshPhongMaterial' ) {
  8626. if ( m.colorSpecular ) {
  8627. mpars.specular = rgb2hex( m.colorSpecular );
  8628. }
  8629. if ( m.specularCoef ) {
  8630. mpars.shininess = m.specularCoef;
  8631. }
  8632. }
  8633. // modifiers
  8634. if ( m.transparency !== undefined ) {
  8635. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  8636. m.opacity = m.transparency;
  8637. }
  8638. if ( m.opacity !== undefined ) {
  8639. mpars.opacity = m.opacity;
  8640. }
  8641. // textures
  8642. if ( texturePath ) {
  8643. if ( m.mapDiffuse ) {
  8644. create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  8645. }
  8646. if ( m.mapLight ) {
  8647. create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  8648. }
  8649. if ( m.mapAO ) {
  8650. create_texture( mpars, 'aoMap', m.mapAO, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  8651. }
  8652. if ( m.mapBump ) {
  8653. create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  8654. }
  8655. if ( m.mapNormal ) {
  8656. create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  8657. }
  8658. if ( m.mapSpecular ) {
  8659. create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  8660. }
  8661. if ( m.mapAlpha ) {
  8662. create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  8663. }
  8664. }
  8665. //
  8666. if ( m.mapBumpScale ) {
  8667. mpars.bumpScale = m.mapBumpScale;
  8668. }
  8669. if ( m.mapNormalFactor ) {
  8670. mpars.normalScale = new THREE.Vector2( m.mapNormalFactor, m.mapNormalFactor );
  8671. }
  8672. var material = new THREE[ mtype ]( mpars );
  8673. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  8674. return material;
  8675. };
  8676. } )()
  8677. };
  8678. THREE.Loader.Handlers = {
  8679. handlers: [],
  8680. add: function ( regex, loader ) {
  8681. this.handlers.push( regex, loader );
  8682. },
  8683. get: function ( file ) {
  8684. for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
  8685. var regex = this.handlers[ i ];
  8686. var loader = this.handlers[ i + 1 ];
  8687. if ( regex.test( file ) ) {
  8688. return loader;
  8689. }
  8690. }
  8691. return null;
  8692. }
  8693. };
  8694. // File:src/loaders/XHRLoader.js
  8695. /**
  8696. * @author mrdoob / http://mrdoob.com/
  8697. */
  8698. THREE.XHRLoader = function ( manager ) {
  8699. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8700. };
  8701. THREE.XHRLoader.prototype = {
  8702. constructor: THREE.XHRLoader,
  8703. load: function ( url, onLoad, onProgress, onError ) {
  8704. var scope = this;
  8705. var cached = THREE.Cache.get( url );
  8706. if ( cached !== undefined ) {
  8707. if ( onLoad ) {
  8708. setTimeout( function () {
  8709. onLoad( cached );
  8710. }, 0 );
  8711. }
  8712. return cached;
  8713. }
  8714. var request = new XMLHttpRequest();
  8715. request.open( 'GET', url, true );
  8716. request.addEventListener( 'load', function ( event ) {
  8717. THREE.Cache.add( url, this.response );
  8718. if ( onLoad ) onLoad( this.response );
  8719. scope.manager.itemEnd( url );
  8720. }, false );
  8721. if ( onProgress !== undefined ) {
  8722. request.addEventListener( 'progress', function ( event ) {
  8723. onProgress( event );
  8724. }, false );
  8725. }
  8726. request.addEventListener( 'error', function ( event ) {
  8727. if ( onError ) onError( event );
  8728. scope.manager.itemError( url );
  8729. }, false );
  8730. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  8731. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  8732. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  8733. request.send( null );
  8734. scope.manager.itemStart( url );
  8735. return request;
  8736. },
  8737. setResponseType: function ( value ) {
  8738. this.responseType = value;
  8739. },
  8740. setCrossOrigin: function ( value ) {
  8741. this.crossOrigin = value;
  8742. },
  8743. setWithCredentials: function ( value ) {
  8744. this.withCredentials = value;
  8745. }
  8746. };
  8747. // File:src/loaders/ImageLoader.js
  8748. /**
  8749. * @author mrdoob / http://mrdoob.com/
  8750. */
  8751. THREE.ImageLoader = function ( manager ) {
  8752. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8753. };
  8754. THREE.ImageLoader.prototype = {
  8755. constructor: THREE.ImageLoader,
  8756. load: function ( url, onLoad, onProgress, onError ) {
  8757. var scope = this;
  8758. var cached = THREE.Cache.get( url );
  8759. if ( cached !== undefined ) {
  8760. if ( onLoad ) {
  8761. setTimeout( function () {
  8762. onLoad( cached );
  8763. }, 0 );
  8764. }
  8765. return cached;
  8766. }
  8767. var image = document.createElement( 'img' );
  8768. image.addEventListener( 'load', function ( event ) {
  8769. THREE.Cache.add( url, this );
  8770. if ( onLoad ) onLoad( this );
  8771. scope.manager.itemEnd( url );
  8772. }, false );
  8773. if ( onProgress !== undefined ) {
  8774. image.addEventListener( 'progress', function ( event ) {
  8775. onProgress( event );
  8776. }, false );
  8777. }
  8778. image.addEventListener( 'error', function ( event ) {
  8779. if ( onError ) onError( event );
  8780. scope.manager.itemError( url );
  8781. }, false );
  8782. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  8783. scope.manager.itemStart( url );
  8784. image.src = url;
  8785. return image;
  8786. },
  8787. setCrossOrigin: function ( value ) {
  8788. this.crossOrigin = value;
  8789. }
  8790. };
  8791. // File:src/loaders/JSONLoader.js
  8792. /**
  8793. * @author mrdoob / http://mrdoob.com/
  8794. * @author alteredq / http://alteredqualia.com/
  8795. */
  8796. THREE.JSONLoader = function ( manager ) {
  8797. if ( typeof manager === 'boolean' ) {
  8798. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  8799. manager = undefined;
  8800. }
  8801. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8802. this.withCredentials = false;
  8803. };
  8804. THREE.JSONLoader.prototype = {
  8805. constructor: THREE.JSONLoader,
  8806. // Deprecated
  8807. get statusDomElement () {
  8808. if ( this._statusDomElement === undefined ) {
  8809. this._statusDomElement = document.createElement( 'div' );
  8810. }
  8811. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  8812. return this._statusDomElement;
  8813. },
  8814. load: function( url, onLoad, onProgress, onError ) {
  8815. var scope = this;
  8816. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  8817. var loader = new THREE.XHRLoader( this.manager );
  8818. loader.setCrossOrigin( this.crossOrigin );
  8819. loader.setWithCredentials( this.withCredentials );
  8820. loader.load( url, function ( text ) {
  8821. var json = JSON.parse( text );
  8822. var metadata = json.metadata;
  8823. if ( metadata !== undefined ) {
  8824. if ( metadata.type === 'object' ) {
  8825. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  8826. return;
  8827. }
  8828. if ( metadata.type === 'scene' ) {
  8829. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  8830. return;
  8831. }
  8832. }
  8833. var object = scope.parse( json, texturePath );
  8834. onLoad( object.geometry, object.materials );
  8835. } );
  8836. },
  8837. setCrossOrigin: function ( value ) {
  8838. this.crossOrigin = value;
  8839. },
  8840. setTexturePath: function ( value ) {
  8841. this.texturePath = value;
  8842. },
  8843. parse: function ( json, texturePath ) {
  8844. var geometry = new THREE.Geometry(),
  8845. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  8846. parseModel( scale );
  8847. parseSkin();
  8848. parseMorphing( scale );
  8849. parseAnimations();
  8850. geometry.computeFaceNormals();
  8851. geometry.computeBoundingSphere();
  8852. function parseModel( scale ) {
  8853. function isBitSet( value, position ) {
  8854. return value & ( 1 << position );
  8855. }
  8856. var i, j, fi,
  8857. offset, zLength,
  8858. colorIndex, normalIndex, uvIndex, materialIndex,
  8859. type,
  8860. isQuad,
  8861. hasMaterial,
  8862. hasFaceVertexUv,
  8863. hasFaceNormal, hasFaceVertexNormal,
  8864. hasFaceColor, hasFaceVertexColor,
  8865. vertex, face, faceA, faceB, hex, normal,
  8866. uvLayer, uv, u, v,
  8867. faces = json.faces,
  8868. vertices = json.vertices,
  8869. normals = json.normals,
  8870. colors = json.colors,
  8871. nUvLayers = 0;
  8872. if ( json.uvs !== undefined ) {
  8873. // disregard empty arrays
  8874. for ( i = 0; i < json.uvs.length; i ++ ) {
  8875. if ( json.uvs[ i ].length ) nUvLayers ++;
  8876. }
  8877. for ( i = 0; i < nUvLayers; i ++ ) {
  8878. geometry.faceVertexUvs[ i ] = [];
  8879. }
  8880. }
  8881. offset = 0;
  8882. zLength = vertices.length;
  8883. while ( offset < zLength ) {
  8884. vertex = new THREE.Vector3();
  8885. vertex.x = vertices[ offset ++ ] * scale;
  8886. vertex.y = vertices[ offset ++ ] * scale;
  8887. vertex.z = vertices[ offset ++ ] * scale;
  8888. geometry.vertices.push( vertex );
  8889. }
  8890. offset = 0;
  8891. zLength = faces.length;
  8892. while ( offset < zLength ) {
  8893. type = faces[ offset ++ ];
  8894. isQuad = isBitSet( type, 0 );
  8895. hasMaterial = isBitSet( type, 1 );
  8896. hasFaceVertexUv = isBitSet( type, 3 );
  8897. hasFaceNormal = isBitSet( type, 4 );
  8898. hasFaceVertexNormal = isBitSet( type, 5 );
  8899. hasFaceColor = isBitSet( type, 6 );
  8900. hasFaceVertexColor = isBitSet( type, 7 );
  8901. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  8902. if ( isQuad ) {
  8903. faceA = new THREE.Face3();
  8904. faceA.a = faces[ offset ];
  8905. faceA.b = faces[ offset + 1 ];
  8906. faceA.c = faces[ offset + 3 ];
  8907. faceB = new THREE.Face3();
  8908. faceB.a = faces[ offset + 1 ];
  8909. faceB.b = faces[ offset + 2 ];
  8910. faceB.c = faces[ offset + 3 ];
  8911. offset += 4;
  8912. if ( hasMaterial ) {
  8913. materialIndex = faces[ offset ++ ];
  8914. faceA.materialIndex = materialIndex;
  8915. faceB.materialIndex = materialIndex;
  8916. }
  8917. // to get face <=> uv index correspondence
  8918. fi = geometry.faces.length;
  8919. if ( hasFaceVertexUv ) {
  8920. for ( i = 0; i < nUvLayers; i ++ ) {
  8921. uvLayer = json.uvs[ i ];
  8922. geometry.faceVertexUvs[ i ][ fi ] = [];
  8923. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  8924. for ( j = 0; j < 4; j ++ ) {
  8925. uvIndex = faces[ offset ++ ];
  8926. u = uvLayer[ uvIndex * 2 ];
  8927. v = uvLayer[ uvIndex * 2 + 1 ];
  8928. uv = new THREE.Vector2( u, v );
  8929. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  8930. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  8931. }
  8932. }
  8933. }
  8934. if ( hasFaceNormal ) {
  8935. normalIndex = faces[ offset ++ ] * 3;
  8936. faceA.normal.set(
  8937. normals[ normalIndex ++ ],
  8938. normals[ normalIndex ++ ],
  8939. normals[ normalIndex ]
  8940. );
  8941. faceB.normal.copy( faceA.normal );
  8942. }
  8943. if ( hasFaceVertexNormal ) {
  8944. for ( i = 0; i < 4; i ++ ) {
  8945. normalIndex = faces[ offset ++ ] * 3;
  8946. normal = new THREE.Vector3(
  8947. normals[ normalIndex ++ ],
  8948. normals[ normalIndex ++ ],
  8949. normals[ normalIndex ]
  8950. );
  8951. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  8952. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  8953. }
  8954. }
  8955. if ( hasFaceColor ) {
  8956. colorIndex = faces[ offset ++ ];
  8957. hex = colors[ colorIndex ];
  8958. faceA.color.setHex( hex );
  8959. faceB.color.setHex( hex );
  8960. }
  8961. if ( hasFaceVertexColor ) {
  8962. for ( i = 0; i < 4; i ++ ) {
  8963. colorIndex = faces[ offset ++ ];
  8964. hex = colors[ colorIndex ];
  8965. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  8966. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  8967. }
  8968. }
  8969. geometry.faces.push( faceA );
  8970. geometry.faces.push( faceB );
  8971. } else {
  8972. face = new THREE.Face3();
  8973. face.a = faces[ offset ++ ];
  8974. face.b = faces[ offset ++ ];
  8975. face.c = faces[ offset ++ ];
  8976. if ( hasMaterial ) {
  8977. materialIndex = faces[ offset ++ ];
  8978. face.materialIndex = materialIndex;
  8979. }
  8980. // to get face <=> uv index correspondence
  8981. fi = geometry.faces.length;
  8982. if ( hasFaceVertexUv ) {
  8983. for ( i = 0; i < nUvLayers; i ++ ) {
  8984. uvLayer = json.uvs[ i ];
  8985. geometry.faceVertexUvs[ i ][ fi ] = [];
  8986. for ( j = 0; j < 3; j ++ ) {
  8987. uvIndex = faces[ offset ++ ];
  8988. u = uvLayer[ uvIndex * 2 ];
  8989. v = uvLayer[ uvIndex * 2 + 1 ];
  8990. uv = new THREE.Vector2( u, v );
  8991. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  8992. }
  8993. }
  8994. }
  8995. if ( hasFaceNormal ) {
  8996. normalIndex = faces[ offset ++ ] * 3;
  8997. face.normal.set(
  8998. normals[ normalIndex ++ ],
  8999. normals[ normalIndex ++ ],
  9000. normals[ normalIndex ]
  9001. );
  9002. }
  9003. if ( hasFaceVertexNormal ) {
  9004. for ( i = 0; i < 3; i ++ ) {
  9005. normalIndex = faces[ offset ++ ] * 3;
  9006. normal = new THREE.Vector3(
  9007. normals[ normalIndex ++ ],
  9008. normals[ normalIndex ++ ],
  9009. normals[ normalIndex ]
  9010. );
  9011. face.vertexNormals.push( normal );
  9012. }
  9013. }
  9014. if ( hasFaceColor ) {
  9015. colorIndex = faces[ offset ++ ];
  9016. face.color.setHex( colors[ colorIndex ] );
  9017. }
  9018. if ( hasFaceVertexColor ) {
  9019. for ( i = 0; i < 3; i ++ ) {
  9020. colorIndex = faces[ offset ++ ];
  9021. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  9022. }
  9023. }
  9024. geometry.faces.push( face );
  9025. }
  9026. }
  9027. };
  9028. function parseSkin() {
  9029. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  9030. if ( json.skinWeights ) {
  9031. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  9032. var x = json.skinWeights[ i ];
  9033. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  9034. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  9035. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  9036. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  9037. }
  9038. }
  9039. if ( json.skinIndices ) {
  9040. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  9041. var a = json.skinIndices[ i ];
  9042. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  9043. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  9044. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  9045. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  9046. }
  9047. }
  9048. geometry.bones = json.bones;
  9049. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  9050. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  9051. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  9052. }
  9053. };
  9054. function parseMorphing( scale ) {
  9055. if ( json.morphTargets !== undefined ) {
  9056. var i, l, v, vl, dstVertices, srcVertices;
  9057. for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  9058. geometry.morphTargets[ i ] = {};
  9059. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  9060. geometry.morphTargets[ i ].vertices = [];
  9061. dstVertices = geometry.morphTargets[ i ].vertices;
  9062. srcVertices = json.morphTargets[ i ].vertices;
  9063. for ( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  9064. var vertex = new THREE.Vector3();
  9065. vertex.x = srcVertices[ v ] * scale;
  9066. vertex.y = srcVertices[ v + 1 ] * scale;
  9067. vertex.z = srcVertices[ v + 2 ] * scale;
  9068. dstVertices.push( vertex );
  9069. }
  9070. }
  9071. }
  9072. if ( json.morphColors !== undefined ) {
  9073. var i, l, c, cl, dstColors, srcColors, color;
  9074. for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
  9075. geometry.morphColors[ i ] = {};
  9076. geometry.morphColors[ i ].name = json.morphColors[ i ].name;
  9077. geometry.morphColors[ i ].colors = [];
  9078. dstColors = geometry.morphColors[ i ].colors;
  9079. srcColors = json.morphColors[ i ].colors;
  9080. for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
  9081. color = new THREE.Color( 0xffaa00 );
  9082. color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
  9083. dstColors.push( color );
  9084. }
  9085. }
  9086. }
  9087. }
  9088. function parseAnimations() {
  9089. var outputAnimations = [];
  9090. // parse old style Bone/Hierarchy animations
  9091. var animations = [];
  9092. if( json.animation !== undefined ) {
  9093. animations.push( json.animation );
  9094. }
  9095. if( json.animations !== undefined ) {
  9096. if( json.animations.length ) {
  9097. animations = animations.concat( json.animations );
  9098. }
  9099. else {
  9100. animations.push( json.animations );
  9101. }
  9102. }
  9103. for( var i = 0; i < animations.length; i ++ ) {
  9104. var clip = THREE.AnimationClip.parseAnimation( animations[i], geometry.bones );
  9105. if( clip ) outputAnimations.push( clip );
  9106. }
  9107. // parse implicit morph animations
  9108. if( geometry.morphTargets ) {
  9109. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  9110. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  9111. outputAnimations = outputAnimations.concat( morphAnimationClips );
  9112. }
  9113. if( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  9114. };
  9115. if ( json.materials === undefined || json.materials.length === 0 ) {
  9116. return { geometry: geometry };
  9117. } else {
  9118. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  9119. return { geometry: geometry, materials: materials };
  9120. }
  9121. }
  9122. };
  9123. // File:src/loaders/LoadingManager.js
  9124. /**
  9125. * @author mrdoob / http://mrdoob.com/
  9126. */
  9127. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  9128. var scope = this;
  9129. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  9130. this.onStart = undefined;
  9131. this.onLoad = onLoad;
  9132. this.onProgress = onProgress;
  9133. this.onError = onError;
  9134. this.itemStart = function ( url ) {
  9135. itemsTotal ++;
  9136. if ( isLoading === false ) {
  9137. if ( scope.onStart !== undefined ) {
  9138. scope.onStart( url, itemsLoaded, itemsTotal );
  9139. }
  9140. }
  9141. isLoading = true;
  9142. };
  9143. this.itemEnd = function ( url ) {
  9144. itemsLoaded ++;
  9145. if ( scope.onProgress !== undefined ) {
  9146. scope.onProgress( url, itemsLoaded, itemsTotal );
  9147. }
  9148. if ( itemsLoaded === itemsTotal ) {
  9149. isLoading = false;
  9150. if ( scope.onLoad !== undefined ) {
  9151. scope.onLoad();
  9152. }
  9153. }
  9154. };
  9155. this.itemError = function ( url ) {
  9156. if ( scope.onError !== undefined ) {
  9157. scope.onError( url );
  9158. }
  9159. };
  9160. };
  9161. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  9162. // File:src/loaders/BufferGeometryLoader.js
  9163. /**
  9164. * @author mrdoob / http://mrdoob.com/
  9165. */
  9166. THREE.BufferGeometryLoader = function ( manager ) {
  9167. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9168. };
  9169. THREE.BufferGeometryLoader.prototype = {
  9170. constructor: THREE.BufferGeometryLoader,
  9171. load: function ( url, onLoad, onProgress, onError ) {
  9172. var scope = this;
  9173. var loader = new THREE.XHRLoader( scope.manager );
  9174. loader.setCrossOrigin( this.crossOrigin );
  9175. loader.load( url, function ( text ) {
  9176. onLoad( scope.parse( JSON.parse( text ) ) );
  9177. }, onProgress, onError );
  9178. },
  9179. setCrossOrigin: function ( value ) {
  9180. this.crossOrigin = value;
  9181. },
  9182. parse: function ( json ) {
  9183. var geometry = new THREE.BufferGeometry();
  9184. var index = json.data.index;
  9185. if ( index !== undefined ) {
  9186. var typedArray = new self[ index.type ]( index.array );
  9187. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  9188. }
  9189. var attributes = json.data.attributes;
  9190. for ( var key in attributes ) {
  9191. var attribute = attributes[ key ];
  9192. var typedArray = new self[ attribute.type ]( attribute.array );
  9193. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  9194. }
  9195. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  9196. if ( groups !== undefined ) {
  9197. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  9198. var group = groups[ i ];
  9199. geometry.addGroup( group.start, group.count );
  9200. }
  9201. }
  9202. var boundingSphere = json.data.boundingSphere;
  9203. if ( boundingSphere !== undefined ) {
  9204. var center = new THREE.Vector3();
  9205. if ( boundingSphere.center !== undefined ) {
  9206. center.fromArray( boundingSphere.center );
  9207. }
  9208. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  9209. }
  9210. return geometry;
  9211. }
  9212. };
  9213. // File:src/loaders/MaterialLoader.js
  9214. /**
  9215. * @author mrdoob / http://mrdoob.com/
  9216. */
  9217. THREE.MaterialLoader = function ( manager ) {
  9218. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9219. this.textures = {};
  9220. };
  9221. THREE.MaterialLoader.prototype = {
  9222. constructor: THREE.MaterialLoader,
  9223. load: function ( url, onLoad, onProgress, onError ) {
  9224. var scope = this;
  9225. var loader = new THREE.XHRLoader( scope.manager );
  9226. loader.setCrossOrigin( this.crossOrigin );
  9227. loader.load( url, function ( text ) {
  9228. onLoad( scope.parse( JSON.parse( text ) ) );
  9229. }, onProgress, onError );
  9230. },
  9231. setCrossOrigin: function ( value ) {
  9232. this.crossOrigin = value;
  9233. },
  9234. setTextures: function ( value ) {
  9235. this.textures = value;
  9236. },
  9237. getTexture: function ( name ) {
  9238. var textures = this.textures;
  9239. if ( textures[ name ] === undefined ) {
  9240. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  9241. }
  9242. return textures[ name ];
  9243. },
  9244. parse: function ( json ) {
  9245. var material = new THREE[ json.type ];
  9246. material.uuid = json.uuid;
  9247. if ( json.name !== undefined ) material.name = json.name;
  9248. if ( json.color !== undefined ) material.color.setHex( json.color );
  9249. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  9250. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  9251. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  9252. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  9253. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  9254. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  9255. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  9256. if ( json.shading !== undefined ) material.shading = json.shading;
  9257. if ( json.blending !== undefined ) material.blending = json.blending;
  9258. if ( json.side !== undefined ) material.side = json.side;
  9259. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  9260. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  9261. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  9262. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  9263. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  9264. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  9265. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  9266. // for PointsMaterial
  9267. if ( json.size !== undefined ) material.size = json.size;
  9268. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  9269. // maps
  9270. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  9271. if ( json.alphaMap !== undefined ) {
  9272. material.alphaMap = this.getTexture( json.alphaMap );
  9273. material.transparent = true;
  9274. }
  9275. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  9276. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  9277. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  9278. if ( json.normalScale ) material.normalScale = new THREE.Vector2( json.normalScale, json.normalScale );
  9279. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  9280. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  9281. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  9282. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  9283. if ( json.envMap !== undefined ) {
  9284. material.envMap = this.getTexture( json.envMap );
  9285. material.combine = THREE.MultiplyOperation;
  9286. }
  9287. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  9288. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  9289. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  9290. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  9291. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  9292. // MeshFaceMaterial
  9293. if ( json.materials !== undefined ) {
  9294. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  9295. material.materials.push( this.parse( json.materials[ i ] ) );
  9296. }
  9297. }
  9298. return material;
  9299. }
  9300. };
  9301. // File:src/loaders/ObjectLoader.js
  9302. /**
  9303. * @author mrdoob / http://mrdoob.com/
  9304. */
  9305. THREE.ObjectLoader = function ( manager ) {
  9306. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9307. this.texturePath = '';
  9308. };
  9309. THREE.ObjectLoader.prototype = {
  9310. constructor: THREE.ObjectLoader,
  9311. load: function ( url, onLoad, onProgress, onError ) {
  9312. if ( this.texturePath === '' ) {
  9313. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  9314. }
  9315. var scope = this;
  9316. var loader = new THREE.XHRLoader( scope.manager );
  9317. loader.setCrossOrigin( this.crossOrigin );
  9318. loader.load( url, function ( text ) {
  9319. scope.parse( JSON.parse( text ), onLoad );
  9320. }, onProgress, onError );
  9321. },
  9322. setTexturePath: function ( value ) {
  9323. this.texturePath = value;
  9324. },
  9325. setCrossOrigin: function ( value ) {
  9326. this.crossOrigin = value;
  9327. },
  9328. parse: function ( json, onLoad ) {
  9329. var geometries = this.parseGeometries( json.geometries );
  9330. var images = this.parseImages( json.images, function () {
  9331. if ( onLoad !== undefined ) onLoad( object );
  9332. } );
  9333. var textures = this.parseTextures( json.textures, images );
  9334. var materials = this.parseMaterials( json.materials, textures );
  9335. var object = this.parseObject( json.object, geometries, materials );
  9336. if( json.animations ) {
  9337. object.animations = this.parseAnimations( json.animations );
  9338. }
  9339. if ( json.images === undefined || json.images.length === 0 ) {
  9340. if ( onLoad !== undefined ) onLoad( object );
  9341. }
  9342. return object;
  9343. },
  9344. parseGeometries: function ( json ) {
  9345. var geometries = {};
  9346. if ( json !== undefined ) {
  9347. var geometryLoader = new THREE.JSONLoader();
  9348. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  9349. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9350. var geometry;
  9351. var data = json[ i ];
  9352. switch ( data.type ) {
  9353. case 'PlaneGeometry':
  9354. case 'PlaneBufferGeometry':
  9355. geometry = new THREE[ data.type ](
  9356. data.width,
  9357. data.height,
  9358. data.widthSegments,
  9359. data.heightSegments
  9360. );
  9361. break;
  9362. case 'BoxGeometry':
  9363. case 'CubeGeometry': // backwards compatible
  9364. geometry = new THREE.BoxGeometry(
  9365. data.width,
  9366. data.height,
  9367. data.depth,
  9368. data.widthSegments,
  9369. data.heightSegments,
  9370. data.depthSegments
  9371. );
  9372. break;
  9373. case 'CircleBufferGeometry':
  9374. geometry = new THREE.CircleBufferGeometry(
  9375. data.radius,
  9376. data.segments,
  9377. data.thetaStart,
  9378. data.thetaLength
  9379. );
  9380. break;
  9381. case 'CircleGeometry':
  9382. geometry = new THREE.CircleGeometry(
  9383. data.radius,
  9384. data.segments,
  9385. data.thetaStart,
  9386. data.thetaLength
  9387. );
  9388. break;
  9389. case 'CylinderGeometry':
  9390. geometry = new THREE.CylinderGeometry(
  9391. data.radiusTop,
  9392. data.radiusBottom,
  9393. data.height,
  9394. data.radialSegments,
  9395. data.heightSegments,
  9396. data.openEnded,
  9397. data.thetaStart,
  9398. data.thetaLength
  9399. );
  9400. break;
  9401. case 'SphereGeometry':
  9402. geometry = new THREE.SphereGeometry(
  9403. data.radius,
  9404. data.widthSegments,
  9405. data.heightSegments,
  9406. data.phiStart,
  9407. data.phiLength,
  9408. data.thetaStart,
  9409. data.thetaLength
  9410. );
  9411. break;
  9412. case 'SphereBufferGeometry':
  9413. geometry = new THREE.SphereBufferGeometry(
  9414. data.radius,
  9415. data.widthSegments,
  9416. data.heightSegments,
  9417. data.phiStart,
  9418. data.phiLength,
  9419. data.thetaStart,
  9420. data.thetaLength
  9421. );
  9422. break;
  9423. case 'DodecahedronGeometry':
  9424. geometry = new THREE.DodecahedronGeometry(
  9425. data.radius,
  9426. data.detail
  9427. );
  9428. break;
  9429. case 'IcosahedronGeometry':
  9430. geometry = new THREE.IcosahedronGeometry(
  9431. data.radius,
  9432. data.detail
  9433. );
  9434. break;
  9435. case 'OctahedronGeometry':
  9436. geometry = new THREE.OctahedronGeometry(
  9437. data.radius,
  9438. data.detail
  9439. );
  9440. break;
  9441. case 'TetrahedronGeometry':
  9442. geometry = new THREE.TetrahedronGeometry(
  9443. data.radius,
  9444. data.detail
  9445. );
  9446. break;
  9447. case 'RingGeometry':
  9448. geometry = new THREE.RingGeometry(
  9449. data.innerRadius,
  9450. data.outerRadius,
  9451. data.thetaSegments,
  9452. data.phiSegments,
  9453. data.thetaStart,
  9454. data.thetaLength
  9455. );
  9456. break;
  9457. case 'TorusGeometry':
  9458. geometry = new THREE.TorusGeometry(
  9459. data.radius,
  9460. data.tube,
  9461. data.radialSegments,
  9462. data.tubularSegments,
  9463. data.arc
  9464. );
  9465. break;
  9466. case 'TorusKnotGeometry':
  9467. geometry = new THREE.TorusKnotGeometry(
  9468. data.radius,
  9469. data.tube,
  9470. data.radialSegments,
  9471. data.tubularSegments,
  9472. data.p,
  9473. data.q,
  9474. data.heightScale
  9475. );
  9476. break;
  9477. case 'TextGeometry':
  9478. geometry = new THREE.TextGeometry(
  9479. data.text,
  9480. data.data
  9481. );
  9482. break;
  9483. case 'BufferGeometry':
  9484. geometry = bufferGeometryLoader.parse( data );
  9485. break;
  9486. case 'Geometry':
  9487. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  9488. break;
  9489. default:
  9490. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  9491. continue;
  9492. }
  9493. geometry.uuid = data.uuid;
  9494. if ( data.name !== undefined ) geometry.name = data.name;
  9495. geometries[ data.uuid ] = geometry;
  9496. }
  9497. }
  9498. return geometries;
  9499. },
  9500. parseMaterials: function ( json, textures ) {
  9501. var materials = {};
  9502. if ( json !== undefined ) {
  9503. var loader = new THREE.MaterialLoader();
  9504. loader.setTextures( textures );
  9505. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9506. var material = loader.parse( json[ i ] );
  9507. materials[ material.uuid ] = material;
  9508. }
  9509. }
  9510. return materials;
  9511. },
  9512. parseAnimations: function ( json ) {
  9513. var animations = [];
  9514. for( var i = 0; i < json.length; i ++ ) {
  9515. var clip = THREE.AnimationClip.parse( json[i] );
  9516. animations.push( clip );
  9517. }
  9518. return animations;
  9519. },
  9520. parseImages: function ( json, onLoad ) {
  9521. var scope = this;
  9522. var images = {};
  9523. function loadImage( url ) {
  9524. scope.manager.itemStart( url );
  9525. return loader.load( url, function () {
  9526. scope.manager.itemEnd( url );
  9527. } );
  9528. }
  9529. if ( json !== undefined && json.length > 0 ) {
  9530. var manager = new THREE.LoadingManager( onLoad );
  9531. var loader = new THREE.ImageLoader( manager );
  9532. loader.setCrossOrigin( this.crossOrigin );
  9533. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9534. var image = json[ i ];
  9535. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  9536. images[ image.uuid ] = loadImage( path );
  9537. }
  9538. }
  9539. return images;
  9540. },
  9541. parseTextures: function ( json, images ) {
  9542. function parseConstant( value ) {
  9543. if ( typeof( value ) === 'number' ) return value;
  9544. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  9545. return THREE[ value ];
  9546. }
  9547. var textures = {};
  9548. if ( json !== undefined ) {
  9549. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9550. var data = json[ i ];
  9551. if ( data.image === undefined ) {
  9552. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  9553. }
  9554. if ( images[ data.image ] === undefined ) {
  9555. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  9556. }
  9557. var texture = new THREE.Texture( images[ data.image ] );
  9558. texture.needsUpdate = true;
  9559. texture.uuid = data.uuid;
  9560. if ( data.name !== undefined ) texture.name = data.name;
  9561. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  9562. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  9563. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  9564. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  9565. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  9566. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  9567. if ( Array.isArray( data.wrap ) ) {
  9568. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  9569. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  9570. }
  9571. textures[ data.uuid ] = texture;
  9572. }
  9573. }
  9574. return textures;
  9575. },
  9576. parseObject: function () {
  9577. var matrix = new THREE.Matrix4();
  9578. return function ( data, geometries, materials ) {
  9579. var object;
  9580. var getGeometry = function ( name ) {
  9581. if ( geometries[ name ] === undefined ) {
  9582. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  9583. }
  9584. return geometries[ name ];
  9585. };
  9586. var getMaterial = function ( name ) {
  9587. if ( materials[ name ] === undefined ) {
  9588. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  9589. }
  9590. return materials[ name ];
  9591. };
  9592. switch ( data.type ) {
  9593. case 'Scene':
  9594. object = new THREE.Scene();
  9595. break;
  9596. case 'PerspectiveCamera':
  9597. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  9598. break;
  9599. case 'OrthographicCamera':
  9600. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  9601. break;
  9602. case 'AmbientLight':
  9603. object = new THREE.AmbientLight( data.color );
  9604. break;
  9605. case 'DirectionalLight':
  9606. object = new THREE.DirectionalLight( data.color, data.intensity );
  9607. break;
  9608. case 'PointLight':
  9609. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  9610. break;
  9611. case 'SpotLight':
  9612. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  9613. break;
  9614. case 'HemisphereLight':
  9615. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  9616. break;
  9617. case 'Mesh':
  9618. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  9619. break;
  9620. case 'LOD':
  9621. object = new THREE.LOD();
  9622. break;
  9623. case 'Line':
  9624. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  9625. break;
  9626. case 'PointCloud':
  9627. case 'Points':
  9628. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  9629. break;
  9630. case 'Sprite':
  9631. object = new THREE.Sprite( getMaterial( data.material ) );
  9632. break;
  9633. case 'Group':
  9634. object = new THREE.Group();
  9635. break;
  9636. default:
  9637. object = new THREE.Object3D();
  9638. }
  9639. object.uuid = data.uuid;
  9640. if ( data.name !== undefined ) object.name = data.name;
  9641. if ( data.matrix !== undefined ) {
  9642. matrix.fromArray( data.matrix );
  9643. matrix.decompose( object.position, object.quaternion, object.scale );
  9644. } else {
  9645. if ( data.position !== undefined ) object.position.fromArray( data.position );
  9646. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  9647. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  9648. }
  9649. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  9650. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  9651. if ( data.visible !== undefined ) object.visible = data.visible;
  9652. if ( data.userData !== undefined ) object.userData = data.userData;
  9653. if ( data.children !== undefined ) {
  9654. for ( var child in data.children ) {
  9655. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  9656. }
  9657. }
  9658. if ( data.type === 'LOD' ) {
  9659. var levels = data.levels;
  9660. for ( var l = 0; l < levels.length; l ++ ) {
  9661. var level = levels[ l ];
  9662. var child = object.getObjectByProperty( 'uuid', level.object );
  9663. if ( child !== undefined ) {
  9664. object.addLevel( child, level.distance );
  9665. }
  9666. }
  9667. }
  9668. return object;
  9669. }
  9670. }()
  9671. };
  9672. // File:src/loaders/TextureLoader.js
  9673. /**
  9674. * @author mrdoob / http://mrdoob.com/
  9675. */
  9676. THREE.TextureLoader = function ( manager ) {
  9677. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9678. };
  9679. THREE.TextureLoader.prototype = {
  9680. constructor: THREE.TextureLoader,
  9681. load: function ( url, onLoad, onProgress, onError ) {
  9682. var scope = this;
  9683. var loader = new THREE.ImageLoader( scope.manager );
  9684. loader.setCrossOrigin( this.crossOrigin );
  9685. loader.load( url, function ( image ) {
  9686. var texture = new THREE.Texture( image );
  9687. texture.needsUpdate = true;
  9688. if ( onLoad !== undefined ) {
  9689. onLoad( texture );
  9690. }
  9691. }, onProgress, onError );
  9692. },
  9693. setCrossOrigin: function ( value ) {
  9694. this.crossOrigin = value;
  9695. }
  9696. };
  9697. // File:src/loaders/BinaryTextureLoader.js
  9698. /**
  9699. * @author Nikos M. / https://github.com/foo123/
  9700. *
  9701. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  9702. */
  9703. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  9704. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9705. // override in sub classes
  9706. this._parser = null;
  9707. };
  9708. THREE.BinaryTextureLoader.prototype = {
  9709. constructor: THREE.BinaryTextureLoader,
  9710. load: function ( url, onLoad, onProgress, onError ) {
  9711. var scope = this;
  9712. var texture = new THREE.DataTexture();
  9713. var loader = new THREE.XHRLoader( this.manager );
  9714. loader.setCrossOrigin( this.crossOrigin );
  9715. loader.setResponseType( 'arraybuffer' );
  9716. loader.load( url, function ( buffer ) {
  9717. var texData = scope._parser( buffer );
  9718. if ( ! texData ) return;
  9719. if ( undefined !== texData.image ) {
  9720. texture.image = texData.image;
  9721. } else if ( undefined !== texData.data ) {
  9722. texture.image.width = texData.width;
  9723. texture.image.height = texData.height;
  9724. texture.image.data = texData.data;
  9725. }
  9726. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  9727. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  9728. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  9729. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  9730. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  9731. if ( undefined !== texData.format ) {
  9732. texture.format = texData.format;
  9733. }
  9734. if ( undefined !== texData.type ) {
  9735. texture.type = texData.type;
  9736. }
  9737. if ( undefined !== texData.mipmaps ) {
  9738. texture.mipmaps = texData.mipmaps;
  9739. }
  9740. if ( 1 === texData.mipmapCount ) {
  9741. texture.minFilter = THREE.LinearFilter;
  9742. }
  9743. texture.needsUpdate = true;
  9744. if ( onLoad ) onLoad( texture, texData );
  9745. }, onProgress, onError );
  9746. return texture;
  9747. },
  9748. setCrossOrigin: function ( value ) {
  9749. this.crossOrigin = value;
  9750. }
  9751. };
  9752. // File:src/loaders/CompressedTextureLoader.js
  9753. /**
  9754. * @author mrdoob / http://mrdoob.com/
  9755. *
  9756. * Abstract Base class to block based textures loader (dds, pvr, ...)
  9757. */
  9758. THREE.CompressedTextureLoader = function ( manager ) {
  9759. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9760. // override in sub classes
  9761. this._parser = null;
  9762. };
  9763. THREE.CompressedTextureLoader.prototype = {
  9764. constructor: THREE.CompressedTextureLoader,
  9765. load: function ( url, onLoad, onProgress, onError ) {
  9766. var scope = this;
  9767. var images = [];
  9768. var texture = new THREE.CompressedTexture();
  9769. texture.image = images;
  9770. var loader = new THREE.XHRLoader( this.manager );
  9771. loader.setCrossOrigin( this.crossOrigin );
  9772. loader.setResponseType( 'arraybuffer' );
  9773. if ( Array.isArray( url ) ) {
  9774. var loaded = 0;
  9775. var loadTexture = function ( i ) {
  9776. loader.load( url[ i ], function ( buffer ) {
  9777. var texDatas = scope._parser( buffer, true );
  9778. images[ i ] = {
  9779. width: texDatas.width,
  9780. height: texDatas.height,
  9781. format: texDatas.format,
  9782. mipmaps: texDatas.mipmaps
  9783. };
  9784. loaded += 1;
  9785. if ( loaded === 6 ) {
  9786. if ( texDatas.mipmapCount === 1 )
  9787. texture.minFilter = THREE.LinearFilter;
  9788. texture.format = texDatas.format;
  9789. texture.needsUpdate = true;
  9790. if ( onLoad ) onLoad( texture );
  9791. }
  9792. }, onProgress, onError );
  9793. };
  9794. for ( var i = 0, il = url.length; i < il; ++ i ) {
  9795. loadTexture( i );
  9796. }
  9797. } else {
  9798. // compressed cubemap texture stored in a single DDS file
  9799. loader.load( url, function ( buffer ) {
  9800. var texDatas = scope._parser( buffer, true );
  9801. if ( texDatas.isCubemap ) {
  9802. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  9803. for ( var f = 0; f < faces; f ++ ) {
  9804. images[ f ] = { mipmaps : [] };
  9805. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  9806. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  9807. images[ f ].format = texDatas.format;
  9808. images[ f ].width = texDatas.width;
  9809. images[ f ].height = texDatas.height;
  9810. }
  9811. }
  9812. } else {
  9813. texture.image.width = texDatas.width;
  9814. texture.image.height = texDatas.height;
  9815. texture.mipmaps = texDatas.mipmaps;
  9816. }
  9817. if ( texDatas.mipmapCount === 1 ) {
  9818. texture.minFilter = THREE.LinearFilter;
  9819. }
  9820. texture.format = texDatas.format;
  9821. texture.needsUpdate = true;
  9822. if ( onLoad ) onLoad( texture );
  9823. }, onProgress, onError );
  9824. }
  9825. return texture;
  9826. },
  9827. setCrossOrigin: function ( value ) {
  9828. this.crossOrigin = value;
  9829. }
  9830. };
  9831. // File:src/materials/Material.js
  9832. /**
  9833. * @author mrdoob / http://mrdoob.com/
  9834. * @author alteredq / http://alteredqualia.com/
  9835. */
  9836. THREE.Material = function () {
  9837. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  9838. this.uuid = THREE.Math.generateUUID();
  9839. this.name = '';
  9840. this.type = 'Material';
  9841. this.side = THREE.FrontSide;
  9842. this.opacity = 1;
  9843. this.transparent = false;
  9844. this.blending = THREE.NormalBlending;
  9845. this.blendSrc = THREE.SrcAlphaFactor;
  9846. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  9847. this.blendEquation = THREE.AddEquation;
  9848. this.blendSrcAlpha = null;
  9849. this.blendDstAlpha = null;
  9850. this.blendEquationAlpha = null;
  9851. this.depthFunc = THREE.LessEqualDepth;
  9852. this.depthTest = true;
  9853. this.depthWrite = true;
  9854. this.colorWrite = true;
  9855. this.precision = null; // override the renderer's default precision for this material
  9856. this.polygonOffset = false;
  9857. this.polygonOffsetFactor = 0;
  9858. this.polygonOffsetUnits = 0;
  9859. this.alphaTest = 0;
  9860. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  9861. this.visible = true;
  9862. this._needsUpdate = true;
  9863. };
  9864. THREE.Material.prototype = {
  9865. constructor: THREE.Material,
  9866. get needsUpdate () {
  9867. return this._needsUpdate;
  9868. },
  9869. set needsUpdate ( value ) {
  9870. if ( value === true ) this.update();
  9871. this._needsUpdate = value;
  9872. },
  9873. setValues: function ( values ) {
  9874. if ( values === undefined ) return;
  9875. for ( var key in values ) {
  9876. var newValue = values[ key ];
  9877. if ( newValue === undefined ) {
  9878. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  9879. continue;
  9880. }
  9881. var currentValue = this[ key ];
  9882. if ( currentValue === undefined ) {
  9883. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  9884. continue;
  9885. }
  9886. if ( currentValue instanceof THREE.Color ) {
  9887. currentValue.set( newValue );
  9888. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  9889. currentValue.copy( newValue );
  9890. } else if ( key === 'overdraw' ) {
  9891. // ensure overdraw is backwards-compatible with legacy boolean type
  9892. this[ key ] = Number( newValue );
  9893. } else {
  9894. this[ key ] = newValue;
  9895. }
  9896. }
  9897. },
  9898. toJSON: function ( meta ) {
  9899. var data = {
  9900. metadata: {
  9901. version: 4.4,
  9902. type: 'Material',
  9903. generator: 'Material.toJSON'
  9904. }
  9905. };
  9906. // standard Material serialization
  9907. data.uuid = this.uuid;
  9908. data.type = this.type;
  9909. if ( this.name !== '' ) data.name = this.name;
  9910. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  9911. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  9912. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  9913. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  9914. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  9915. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  9916. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  9917. if ( this.bumpMap instanceof THREE.Texture ) {
  9918. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  9919. data.bumpScale = this.bumpScale;
  9920. }
  9921. if ( this.normalMap instanceof THREE.Texture ) {
  9922. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  9923. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  9924. }
  9925. if ( this.displacementMap instanceof THREE.Texture ) {
  9926. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  9927. data.displacementScale = this.displacementScale;
  9928. data.displacementBias = this.displacementBias;
  9929. }
  9930. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  9931. if ( this.envMap instanceof THREE.Texture ) {
  9932. data.envMap = this.envMap.toJSON( meta ).uuid;
  9933. data.reflectivity = this.reflectivity; // Scale behind envMap
  9934. }
  9935. if ( this.size !== undefined ) data.size = this.size;
  9936. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  9937. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  9938. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  9939. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  9940. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  9941. if ( this.opacity < 1 ) data.opacity = this.opacity;
  9942. if ( this.transparent === true ) data.transparent = this.transparent;
  9943. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  9944. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  9945. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  9946. return data;
  9947. },
  9948. clone: function () {
  9949. return new this.constructor().copy( this );
  9950. },
  9951. copy: function ( source ) {
  9952. this.name = source.name;
  9953. this.side = source.side;
  9954. this.opacity = source.opacity;
  9955. this.transparent = source.transparent;
  9956. this.blending = source.blending;
  9957. this.blendSrc = source.blendSrc;
  9958. this.blendDst = source.blendDst;
  9959. this.blendEquation = source.blendEquation;
  9960. this.blendSrcAlpha = source.blendSrcAlpha;
  9961. this.blendDstAlpha = source.blendDstAlpha;
  9962. this.blendEquationAlpha = source.blendEquationAlpha;
  9963. this.depthFunc = source.depthFunc;
  9964. this.depthTest = source.depthTest;
  9965. this.depthWrite = source.depthWrite;
  9966. this.precision = source.precision;
  9967. this.polygonOffset = source.polygonOffset;
  9968. this.polygonOffsetFactor = source.polygonOffsetFactor;
  9969. this.polygonOffsetUnits = source.polygonOffsetUnits;
  9970. this.alphaTest = source.alphaTest;
  9971. this.overdraw = source.overdraw;
  9972. this.visible = source.visible;
  9973. return this;
  9974. },
  9975. update: function () {
  9976. this.dispatchEvent( { type: 'update' } );
  9977. },
  9978. dispose: function () {
  9979. this.dispatchEvent( { type: 'dispose' } );
  9980. },
  9981. // Deprecated
  9982. get wrapAround () {
  9983. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  9984. },
  9985. set wrapAround ( boolean ) {
  9986. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  9987. },
  9988. get wrapRGB () {
  9989. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  9990. return new THREE.Color();
  9991. }
  9992. };
  9993. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  9994. THREE.MaterialIdCount = 0;
  9995. // File:src/materials/LineBasicMaterial.js
  9996. /**
  9997. * @author mrdoob / http://mrdoob.com/
  9998. * @author alteredq / http://alteredqualia.com/
  9999. *
  10000. * parameters = {
  10001. * color: <hex>,
  10002. * opacity: <float>,
  10003. *
  10004. * blending: THREE.NormalBlending,
  10005. * depthTest: <bool>,
  10006. * depthWrite: <bool>,
  10007. *
  10008. * linewidth: <float>,
  10009. * linecap: "round",
  10010. * linejoin: "round",
  10011. *
  10012. * vertexColors: <bool>
  10013. *
  10014. * fog: <bool>
  10015. * }
  10016. */
  10017. THREE.LineBasicMaterial = function ( parameters ) {
  10018. THREE.Material.call( this );
  10019. this.type = 'LineBasicMaterial';
  10020. this.color = new THREE.Color( 0xffffff );
  10021. this.linewidth = 1;
  10022. this.linecap = 'round';
  10023. this.linejoin = 'round';
  10024. this.vertexColors = THREE.NoColors;
  10025. this.fog = true;
  10026. this.setValues( parameters );
  10027. };
  10028. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  10029. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  10030. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  10031. THREE.Material.prototype.copy.call( this, source );
  10032. this.color.copy( source.color );
  10033. this.linewidth = source.linewidth;
  10034. this.linecap = source.linecap;
  10035. this.linejoin = source.linejoin;
  10036. this.vertexColors = source.vertexColors;
  10037. this.fog = source.fog;
  10038. return this;
  10039. };
  10040. // File:src/materials/LineDashedMaterial.js
  10041. /**
  10042. * @author alteredq / http://alteredqualia.com/
  10043. *
  10044. * parameters = {
  10045. * color: <hex>,
  10046. * opacity: <float>,
  10047. *
  10048. * blending: THREE.NormalBlending,
  10049. * depthTest: <bool>,
  10050. * depthWrite: <bool>,
  10051. *
  10052. * linewidth: <float>,
  10053. *
  10054. * scale: <float>,
  10055. * dashSize: <float>,
  10056. * gapSize: <float>,
  10057. *
  10058. * vertexColors: <bool>
  10059. *
  10060. * fog: <bool>
  10061. * }
  10062. */
  10063. THREE.LineDashedMaterial = function ( parameters ) {
  10064. THREE.Material.call( this );
  10065. this.type = 'LineDashedMaterial';
  10066. this.color = new THREE.Color( 0xffffff );
  10067. this.linewidth = 1;
  10068. this.scale = 1;
  10069. this.dashSize = 3;
  10070. this.gapSize = 1;
  10071. this.vertexColors = false;
  10072. this.fog = true;
  10073. this.setValues( parameters );
  10074. };
  10075. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  10076. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  10077. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  10078. THREE.Material.prototype.copy.call( this, source );
  10079. this.color.copy( source.color );
  10080. this.linewidth = source.linewidth;
  10081. this.scale = source.scale;
  10082. this.dashSize = source.dashSize;
  10083. this.gapSize = source.gapSize;
  10084. this.vertexColors = source.vertexColors;
  10085. this.fog = source.fog;
  10086. return this;
  10087. };
  10088. // File:src/materials/MeshBasicMaterial.js
  10089. /**
  10090. * @author mrdoob / http://mrdoob.com/
  10091. * @author alteredq / http://alteredqualia.com/
  10092. *
  10093. * parameters = {
  10094. * color: <hex>,
  10095. * opacity: <float>,
  10096. * map: new THREE.Texture( <Image> ),
  10097. *
  10098. * aoMap: new THREE.Texture( <Image> ),
  10099. * aoMapIntensity: <float>
  10100. *
  10101. * specularMap: new THREE.Texture( <Image> ),
  10102. *
  10103. * alphaMap: new THREE.Texture( <Image> ),
  10104. *
  10105. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10106. * combine: THREE.Multiply,
  10107. * reflectivity: <float>,
  10108. * refractionRatio: <float>,
  10109. *
  10110. * shading: THREE.SmoothShading,
  10111. * blending: THREE.NormalBlending,
  10112. * depthTest: <bool>,
  10113. * depthWrite: <bool>,
  10114. *
  10115. * wireframe: <boolean>,
  10116. * wireframeLinewidth: <float>,
  10117. *
  10118. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10119. *
  10120. * skinning: <bool>,
  10121. * morphTargets: <bool>,
  10122. *
  10123. * fog: <bool>
  10124. * }
  10125. */
  10126. THREE.MeshBasicMaterial = function ( parameters ) {
  10127. THREE.Material.call( this );
  10128. this.type = 'MeshBasicMaterial';
  10129. this.color = new THREE.Color( 0xffffff ); // emissive
  10130. this.map = null;
  10131. this.aoMap = null;
  10132. this.aoMapIntensity = 1.0;
  10133. this.specularMap = null;
  10134. this.alphaMap = null;
  10135. this.envMap = null;
  10136. this.combine = THREE.MultiplyOperation;
  10137. this.reflectivity = 1;
  10138. this.refractionRatio = 0.98;
  10139. this.fog = true;
  10140. this.shading = THREE.SmoothShading;
  10141. this.wireframe = false;
  10142. this.wireframeLinewidth = 1;
  10143. this.wireframeLinecap = 'round';
  10144. this.wireframeLinejoin = 'round';
  10145. this.vertexColors = THREE.NoColors;
  10146. this.skinning = false;
  10147. this.morphTargets = false;
  10148. this.setValues( parameters );
  10149. };
  10150. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  10151. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  10152. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  10153. THREE.Material.prototype.copy.call( this, source );
  10154. this.color.copy( source.color );
  10155. this.map = source.map;
  10156. this.aoMap = source.aoMap;
  10157. this.aoMapIntensity = source.aoMapIntensity;
  10158. this.specularMap = source.specularMap;
  10159. this.alphaMap = source.alphaMap;
  10160. this.envMap = source.envMap;
  10161. this.combine = source.combine;
  10162. this.reflectivity = source.reflectivity;
  10163. this.refractionRatio = source.refractionRatio;
  10164. this.fog = source.fog;
  10165. this.shading = source.shading;
  10166. this.wireframe = source.wireframe;
  10167. this.wireframeLinewidth = source.wireframeLinewidth;
  10168. this.wireframeLinecap = source.wireframeLinecap;
  10169. this.wireframeLinejoin = source.wireframeLinejoin;
  10170. this.vertexColors = source.vertexColors;
  10171. this.skinning = source.skinning;
  10172. this.morphTargets = source.morphTargets;
  10173. return this;
  10174. };
  10175. // File:src/materials/MeshLambertMaterial.js
  10176. /**
  10177. * @author mrdoob / http://mrdoob.com/
  10178. * @author alteredq / http://alteredqualia.com/
  10179. *
  10180. * parameters = {
  10181. * color: <hex>,
  10182. * emissive: <hex>,
  10183. * opacity: <float>,
  10184. *
  10185. * map: new THREE.Texture( <Image> ),
  10186. *
  10187. * specularMap: new THREE.Texture( <Image> ),
  10188. *
  10189. * alphaMap: new THREE.Texture( <Image> ),
  10190. *
  10191. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10192. * combine: THREE.Multiply,
  10193. * reflectivity: <float>,
  10194. * refractionRatio: <float>,
  10195. *
  10196. * blending: THREE.NormalBlending,
  10197. * depthTest: <bool>,
  10198. * depthWrite: <bool>,
  10199. *
  10200. * wireframe: <boolean>,
  10201. * wireframeLinewidth: <float>,
  10202. *
  10203. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10204. *
  10205. * skinning: <bool>,
  10206. * morphTargets: <bool>,
  10207. * morphNormals: <bool>,
  10208. *
  10209. * fog: <bool>
  10210. * }
  10211. */
  10212. THREE.MeshLambertMaterial = function ( parameters ) {
  10213. THREE.Material.call( this );
  10214. this.type = 'MeshLambertMaterial';
  10215. this.color = new THREE.Color( 0xffffff ); // diffuse
  10216. this.emissive = new THREE.Color( 0x000000 );
  10217. this.map = null;
  10218. this.specularMap = null;
  10219. this.alphaMap = null;
  10220. this.envMap = null;
  10221. this.combine = THREE.MultiplyOperation;
  10222. this.reflectivity = 1;
  10223. this.refractionRatio = 0.98;
  10224. this.fog = true;
  10225. this.wireframe = false;
  10226. this.wireframeLinewidth = 1;
  10227. this.wireframeLinecap = 'round';
  10228. this.wireframeLinejoin = 'round';
  10229. this.vertexColors = THREE.NoColors;
  10230. this.skinning = false;
  10231. this.morphTargets = false;
  10232. this.morphNormals = false;
  10233. this.setValues( parameters );
  10234. };
  10235. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  10236. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  10237. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  10238. THREE.Material.prototype.copy.call( this, source );
  10239. this.color.copy( source.color );
  10240. this.emissive.copy( source.emissive );
  10241. this.map = source.map;
  10242. this.specularMap = source.specularMap;
  10243. this.alphaMap = source.alphaMap;
  10244. this.envMap = source.envMap;
  10245. this.combine = source.combine;
  10246. this.reflectivity = source.reflectivity;
  10247. this.refractionRatio = source.refractionRatio;
  10248. this.fog = source.fog;
  10249. this.wireframe = source.wireframe;
  10250. this.wireframeLinewidth = source.wireframeLinewidth;
  10251. this.wireframeLinecap = source.wireframeLinecap;
  10252. this.wireframeLinejoin = source.wireframeLinejoin;
  10253. this.vertexColors = source.vertexColors;
  10254. this.skinning = source.skinning;
  10255. this.morphTargets = source.morphTargets;
  10256. this.morphNormals = source.morphNormals;
  10257. return this;
  10258. };
  10259. // File:src/materials/MeshPhongMaterial.js
  10260. /**
  10261. * @author mrdoob / http://mrdoob.com/
  10262. * @author alteredq / http://alteredqualia.com/
  10263. *
  10264. * parameters = {
  10265. * color: <hex>,
  10266. * emissive: <hex>,
  10267. * specular: <hex>,
  10268. * shininess: <float>,
  10269. * opacity: <float>,
  10270. *
  10271. * map: new THREE.Texture( <Image> ),
  10272. *
  10273. * lightMap: new THREE.Texture( <Image> ),
  10274. * lightMapIntensity: <float>
  10275. *
  10276. * aoMap: new THREE.Texture( <Image> ),
  10277. * aoMapIntensity: <float>
  10278. *
  10279. * emissiveMap: new THREE.Texture( <Image> ),
  10280. *
  10281. * bumpMap: new THREE.Texture( <Image> ),
  10282. * bumpScale: <float>,
  10283. *
  10284. * normalMap: new THREE.Texture( <Image> ),
  10285. * normalScale: <Vector2>,
  10286. *
  10287. * displacementMap: new THREE.Texture( <Image> ),
  10288. * displacementScale: <float>,
  10289. * displacementBias: <float>,
  10290. *
  10291. * specularMap: new THREE.Texture( <Image> ),
  10292. *
  10293. * alphaMap: new THREE.Texture( <Image> ),
  10294. *
  10295. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10296. * combine: THREE.Multiply,
  10297. * reflectivity: <float>,
  10298. * refractionRatio: <float>,
  10299. *
  10300. * shading: THREE.SmoothShading,
  10301. * blending: THREE.NormalBlending,
  10302. * depthTest: <bool>,
  10303. * depthWrite: <bool>,
  10304. *
  10305. * wireframe: <boolean>,
  10306. * wireframeLinewidth: <float>,
  10307. *
  10308. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10309. *
  10310. * skinning: <bool>,
  10311. * morphTargets: <bool>,
  10312. * morphNormals: <bool>,
  10313. *
  10314. * fog: <bool>
  10315. * }
  10316. */
  10317. THREE.MeshPhongMaterial = function ( parameters ) {
  10318. THREE.Material.call( this );
  10319. this.type = 'MeshPhongMaterial';
  10320. this.color = new THREE.Color( 0xffffff ); // diffuse
  10321. this.emissive = new THREE.Color( 0x000000 );
  10322. this.specular = new THREE.Color( 0x111111 );
  10323. this.shininess = 30;
  10324. this.metal = false;
  10325. this.map = null;
  10326. this.lightMap = null;
  10327. this.lightMapIntensity = 1.0;
  10328. this.aoMap = null;
  10329. this.aoMapIntensity = 1.0;
  10330. this.emissiveMap = null;
  10331. this.bumpMap = null;
  10332. this.bumpScale = 1;
  10333. this.normalMap = null;
  10334. this.normalScale = new THREE.Vector2( 1, 1 );
  10335. this.displacementMap = null;
  10336. this.displacementScale = 1;
  10337. this.displacementBias = 0;
  10338. this.specularMap = null;
  10339. this.alphaMap = null;
  10340. this.envMap = null;
  10341. this.combine = THREE.MultiplyOperation;
  10342. this.reflectivity = 1;
  10343. this.refractionRatio = 0.98;
  10344. this.fog = true;
  10345. this.shading = THREE.SmoothShading;
  10346. this.wireframe = false;
  10347. this.wireframeLinewidth = 1;
  10348. this.wireframeLinecap = 'round';
  10349. this.wireframeLinejoin = 'round';
  10350. this.vertexColors = THREE.NoColors;
  10351. this.skinning = false;
  10352. this.morphTargets = false;
  10353. this.morphNormals = false;
  10354. this.setValues( parameters );
  10355. };
  10356. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  10357. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  10358. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  10359. THREE.Material.prototype.copy.call( this, source );
  10360. this.color.copy( source.color );
  10361. this.emissive.copy( source.emissive );
  10362. this.specular.copy( source.specular );
  10363. this.shininess = source.shininess;
  10364. this.metal = source.metal;
  10365. this.map = source.map;
  10366. this.lightMap = source.lightMap;
  10367. this.lightMapIntensity = source.lightMapIntensity;
  10368. this.aoMap = source.aoMap;
  10369. this.aoMapIntensity = source.aoMapIntensity;
  10370. this.emissiveMap = source.emissiveMap;
  10371. this.bumpMap = source.bumpMap;
  10372. this.bumpScale = source.bumpScale;
  10373. this.normalMap = source.normalMap;
  10374. this.normalScale.copy( source.normalScale );
  10375. this.displacementMap = source.displacementMap;
  10376. this.displacementScale = source.displacementScale;
  10377. this.displacementBias = source.displacementBias;
  10378. this.specularMap = source.specularMap;
  10379. this.alphaMap = source.alphaMap;
  10380. this.envMap = source.envMap;
  10381. this.combine = source.combine;
  10382. this.reflectivity = source.reflectivity;
  10383. this.refractionRatio = source.refractionRatio;
  10384. this.fog = source.fog;
  10385. this.shading = source.shading;
  10386. this.wireframe = source.wireframe;
  10387. this.wireframeLinewidth = source.wireframeLinewidth;
  10388. this.wireframeLinecap = source.wireframeLinecap;
  10389. this.wireframeLinejoin = source.wireframeLinejoin;
  10390. this.vertexColors = source.vertexColors;
  10391. this.skinning = source.skinning;
  10392. this.morphTargets = source.morphTargets;
  10393. this.morphNormals = source.morphNormals;
  10394. return this;
  10395. };
  10396. // File:src/materials/MeshDepthMaterial.js
  10397. /**
  10398. * @author mrdoob / http://mrdoob.com/
  10399. * @author alteredq / http://alteredqualia.com/
  10400. *
  10401. * parameters = {
  10402. * opacity: <float>,
  10403. *
  10404. * blending: THREE.NormalBlending,
  10405. * depthTest: <bool>,
  10406. * depthWrite: <bool>,
  10407. *
  10408. * wireframe: <boolean>,
  10409. * wireframeLinewidth: <float>
  10410. * }
  10411. */
  10412. THREE.MeshDepthMaterial = function ( parameters ) {
  10413. THREE.Material.call( this );
  10414. this.type = 'MeshDepthMaterial';
  10415. this.morphTargets = false;
  10416. this.wireframe = false;
  10417. this.wireframeLinewidth = 1;
  10418. this.setValues( parameters );
  10419. };
  10420. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  10421. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  10422. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  10423. THREE.Material.prototype.copy.call( this, source );
  10424. this.wireframe = source.wireframe;
  10425. this.wireframeLinewidth = source.wireframeLinewidth;
  10426. return this;
  10427. };
  10428. // File:src/materials/MeshNormalMaterial.js
  10429. /**
  10430. * @author mrdoob / http://mrdoob.com/
  10431. *
  10432. * parameters = {
  10433. * opacity: <float>,
  10434. *
  10435. * shading: THREE.FlatShading,
  10436. * blending: THREE.NormalBlending,
  10437. * depthTest: <bool>,
  10438. * depthWrite: <bool>,
  10439. *
  10440. * wireframe: <boolean>,
  10441. * wireframeLinewidth: <float>
  10442. * }
  10443. */
  10444. THREE.MeshNormalMaterial = function ( parameters ) {
  10445. THREE.Material.call( this, parameters );
  10446. this.type = 'MeshNormalMaterial';
  10447. this.wireframe = false;
  10448. this.wireframeLinewidth = 1;
  10449. this.morphTargets = false;
  10450. this.setValues( parameters );
  10451. };
  10452. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  10453. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  10454. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  10455. THREE.Material.prototype.copy.call( this, source );
  10456. this.wireframe = source.wireframe;
  10457. this.wireframeLinewidth = source.wireframeLinewidth;
  10458. return this;
  10459. };
  10460. // File:src/materials/MultiMaterial.js
  10461. /**
  10462. * @author mrdoob / http://mrdoob.com/
  10463. */
  10464. THREE.MultiMaterial = function ( materials ) {
  10465. this.uuid = THREE.Math.generateUUID();
  10466. this.type = 'MultiMaterial';
  10467. this.materials = materials instanceof Array ? materials : [];
  10468. this.visible = true;
  10469. };
  10470. THREE.MultiMaterial.prototype = {
  10471. constructor: THREE.MultiMaterial,
  10472. toJSON: function () {
  10473. var output = {
  10474. metadata: {
  10475. version: 4.2,
  10476. type: 'material',
  10477. generator: 'MaterialExporter'
  10478. },
  10479. uuid: this.uuid,
  10480. type: this.type,
  10481. materials: []
  10482. };
  10483. for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
  10484. output.materials.push( this.materials[ i ].toJSON() );
  10485. }
  10486. output.visible = this.visible;
  10487. return output;
  10488. },
  10489. clone: function () {
  10490. var material = new this.constructor();
  10491. for ( var i = 0; i < this.materials.length; i ++ ) {
  10492. material.materials.push( this.materials[ i ].clone() );
  10493. }
  10494. material.visible = this.visible;
  10495. return material;
  10496. }
  10497. };
  10498. // backwards compatibility
  10499. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  10500. // File:src/materials/PointsMaterial.js
  10501. /**
  10502. * @author mrdoob / http://mrdoob.com/
  10503. * @author alteredq / http://alteredqualia.com/
  10504. *
  10505. * parameters = {
  10506. * color: <hex>,
  10507. * opacity: <float>,
  10508. * map: new THREE.Texture( <Image> ),
  10509. *
  10510. * size: <float>,
  10511. * sizeAttenuation: <bool>,
  10512. *
  10513. * blending: THREE.NormalBlending,
  10514. * depthTest: <bool>,
  10515. * depthWrite: <bool>,
  10516. *
  10517. * vertexColors: <bool>,
  10518. *
  10519. * fog: <bool>
  10520. * }
  10521. */
  10522. THREE.PointsMaterial = function ( parameters ) {
  10523. THREE.Material.call( this );
  10524. this.type = 'PointsMaterial';
  10525. this.color = new THREE.Color( 0xffffff );
  10526. this.map = null;
  10527. this.size = 1;
  10528. this.sizeAttenuation = true;
  10529. this.vertexColors = THREE.NoColors;
  10530. this.fog = true;
  10531. this.setValues( parameters );
  10532. };
  10533. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  10534. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  10535. THREE.PointsMaterial.prototype.copy = function ( source ) {
  10536. THREE.Material.prototype.copy.call( this, source );
  10537. this.color.copy( source.color );
  10538. this.map = source.map;
  10539. this.size = source.size;
  10540. this.sizeAttenuation = source.sizeAttenuation;
  10541. this.vertexColors = source.vertexColors;
  10542. this.fog = source.fog;
  10543. return this;
  10544. };
  10545. // backwards compatibility
  10546. THREE.PointCloudMaterial = function ( parameters ) {
  10547. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  10548. return new THREE.PointsMaterial( parameters );
  10549. };
  10550. THREE.ParticleBasicMaterial = function ( parameters ) {
  10551. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  10552. return new THREE.PointsMaterial( parameters );
  10553. };
  10554. THREE.ParticleSystemMaterial = function ( parameters ) {
  10555. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  10556. return new THREE.PointsMaterial( parameters );
  10557. };
  10558. // File:src/materials/ShaderMaterial.js
  10559. /**
  10560. * @author alteredq / http://alteredqualia.com/
  10561. *
  10562. * parameters = {
  10563. * defines: { "label" : "value" },
  10564. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  10565. *
  10566. * fragmentShader: <string>,
  10567. * vertexShader: <string>,
  10568. *
  10569. * shading: THREE.SmoothShading,
  10570. * blending: THREE.NormalBlending,
  10571. * depthTest: <bool>,
  10572. * depthWrite: <bool>,
  10573. *
  10574. * wireframe: <boolean>,
  10575. * wireframeLinewidth: <float>,
  10576. *
  10577. * lights: <bool>,
  10578. *
  10579. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10580. *
  10581. * skinning: <bool>,
  10582. * morphTargets: <bool>,
  10583. * morphNormals: <bool>,
  10584. *
  10585. * fog: <bool>
  10586. * }
  10587. */
  10588. THREE.ShaderMaterial = function ( parameters ) {
  10589. THREE.Material.call( this );
  10590. this.type = 'ShaderMaterial';
  10591. this.defines = {};
  10592. this.uniforms = {};
  10593. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  10594. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  10595. this.shading = THREE.SmoothShading;
  10596. this.linewidth = 1;
  10597. this.wireframe = false;
  10598. this.wireframeLinewidth = 1;
  10599. this.fog = false; // set to use scene fog
  10600. this.lights = false; // set to use scene lights
  10601. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  10602. this.skinning = false; // set to use skinning attribute streams
  10603. this.morphTargets = false; // set to use morph targets
  10604. this.morphNormals = false; // set to use morph normals
  10605. this.derivatives = false; // set to use derivatives
  10606. // When rendered geometry doesn't include these attributes but the material does,
  10607. // use these default values in WebGL. This avoids errors when buffer data is missing.
  10608. this.defaultAttributeValues = {
  10609. 'color': [ 1, 1, 1 ],
  10610. 'uv': [ 0, 0 ],
  10611. 'uv2': [ 0, 0 ]
  10612. };
  10613. this.index0AttributeName = undefined;
  10614. if ( parameters !== undefined ) {
  10615. if ( parameters.attributes !== undefined ) {
  10616. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  10617. }
  10618. this.setValues( parameters );
  10619. }
  10620. };
  10621. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  10622. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  10623. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  10624. THREE.Material.prototype.copy.call( this, source );
  10625. this.fragmentShader = source.fragmentShader;
  10626. this.vertexShader = source.vertexShader;
  10627. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  10628. this.attributes = source.attributes;
  10629. this.defines = source.defines;
  10630. this.shading = source.shading;
  10631. this.wireframe = source.wireframe;
  10632. this.wireframeLinewidth = source.wireframeLinewidth;
  10633. this.fog = source.fog;
  10634. this.lights = source.lights;
  10635. this.vertexColors = source.vertexColors;
  10636. this.skinning = source.skinning;
  10637. this.morphTargets = source.morphTargets;
  10638. this.morphNormals = source.morphNormals;
  10639. this.derivatives = source.derivatives;
  10640. return this;
  10641. };
  10642. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  10643. var data = THREE.Material.prototype.toJSON.call( this, meta );
  10644. data.uniforms = this.uniforms;
  10645. data.attributes = this.attributes;
  10646. data.vertexShader = this.vertexShader;
  10647. data.fragmentShader = this.fragmentShader;
  10648. return data;
  10649. };
  10650. // File:src/materials/RawShaderMaterial.js
  10651. /**
  10652. * @author mrdoob / http://mrdoob.com/
  10653. */
  10654. THREE.RawShaderMaterial = function ( parameters ) {
  10655. THREE.ShaderMaterial.call( this, parameters );
  10656. this.type = 'RawShaderMaterial';
  10657. };
  10658. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  10659. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  10660. // File:src/materials/SpriteMaterial.js
  10661. /**
  10662. * @author alteredq / http://alteredqualia.com/
  10663. *
  10664. * parameters = {
  10665. * color: <hex>,
  10666. * opacity: <float>,
  10667. * map: new THREE.Texture( <Image> ),
  10668. *
  10669. * blending: THREE.NormalBlending,
  10670. * depthTest: <bool>,
  10671. * depthWrite: <bool>,
  10672. *
  10673. * uvOffset: new THREE.Vector2(),
  10674. * uvScale: new THREE.Vector2(),
  10675. *
  10676. * fog: <bool>
  10677. * }
  10678. */
  10679. THREE.SpriteMaterial = function ( parameters ) {
  10680. THREE.Material.call( this );
  10681. this.type = 'SpriteMaterial';
  10682. this.color = new THREE.Color( 0xffffff );
  10683. this.map = null;
  10684. this.rotation = 0;
  10685. this.fog = false;
  10686. // set parameters
  10687. this.setValues( parameters );
  10688. };
  10689. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  10690. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  10691. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  10692. THREE.Material.prototype.copy.call( this, source );
  10693. this.color.copy( source.color );
  10694. this.map = source.map;
  10695. this.rotation = source.rotation;
  10696. this.fog = source.fog;
  10697. return this;
  10698. };
  10699. // File:src/textures/Texture.js
  10700. /**
  10701. * @author mrdoob / http://mrdoob.com/
  10702. * @author alteredq / http://alteredqualia.com/
  10703. * @author szimek / https://github.com/szimek/
  10704. */
  10705. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10706. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  10707. this.uuid = THREE.Math.generateUUID();
  10708. this.name = '';
  10709. this.sourceFile = '';
  10710. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  10711. this.mipmaps = [];
  10712. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  10713. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  10714. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  10715. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  10716. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  10717. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  10718. this.format = format !== undefined ? format : THREE.RGBAFormat;
  10719. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  10720. this.offset = new THREE.Vector2( 0, 0 );
  10721. this.repeat = new THREE.Vector2( 1, 1 );
  10722. this.generateMipmaps = true;
  10723. this.premultiplyAlpha = false;
  10724. this.flipY = true;
  10725. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  10726. this.version = 0;
  10727. this.onUpdate = null;
  10728. };
  10729. THREE.Texture.DEFAULT_IMAGE = undefined;
  10730. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  10731. THREE.Texture.prototype = {
  10732. constructor: THREE.Texture,
  10733. set needsUpdate ( value ) {
  10734. if ( value === true ) this.version ++;
  10735. },
  10736. clone: function () {
  10737. return new this.constructor().copy( this );
  10738. },
  10739. copy: function ( source ) {
  10740. this.image = source.image;
  10741. this.mipmaps = source.mipmaps.slice( 0 );
  10742. this.mapping = source.mapping;
  10743. this.wrapS = source.wrapS;
  10744. this.wrapT = source.wrapT;
  10745. this.magFilter = source.magFilter;
  10746. this.minFilter = source.minFilter;
  10747. this.anisotropy = source.anisotropy;
  10748. this.format = source.format;
  10749. this.type = source.type;
  10750. this.offset.copy( source.offset );
  10751. this.repeat.copy( source.repeat );
  10752. this.generateMipmaps = source.generateMipmaps;
  10753. this.premultiplyAlpha = source.premultiplyAlpha;
  10754. this.flipY = source.flipY;
  10755. this.unpackAlignment = source.unpackAlignment;
  10756. return this;
  10757. },
  10758. toJSON: function ( meta ) {
  10759. if ( meta.textures[ this.uuid ] !== undefined ) {
  10760. return meta.textures[ this.uuid ];
  10761. }
  10762. function getDataURL( image ) {
  10763. var canvas;
  10764. if ( image.toDataURL !== undefined ) {
  10765. canvas = image;
  10766. } else {
  10767. canvas = document.createElement( 'canvas' );
  10768. canvas.width = image.width;
  10769. canvas.height = image.height;
  10770. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  10771. }
  10772. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  10773. return canvas.toDataURL( 'image/jpeg', 0.6 );
  10774. } else {
  10775. return canvas.toDataURL( 'image/png' );
  10776. }
  10777. }
  10778. var output = {
  10779. metadata: {
  10780. version: 4.4,
  10781. type: 'Texture',
  10782. generator: 'Texture.toJSON'
  10783. },
  10784. uuid: this.uuid,
  10785. name: this.name,
  10786. mapping: this.mapping,
  10787. repeat: [ this.repeat.x, this.repeat.y ],
  10788. offset: [ this.offset.x, this.offset.y ],
  10789. wrap: [ this.wrapS, this.wrapT ],
  10790. minFilter: this.minFilter,
  10791. magFilter: this.magFilter,
  10792. anisotropy: this.anisotropy
  10793. };
  10794. if ( this.image !== undefined ) {
  10795. // TODO: Move to THREE.Image
  10796. var image = this.image;
  10797. if ( image.uuid === undefined ) {
  10798. image.uuid = THREE.Math.generateUUID(); // UGH
  10799. }
  10800. if ( meta.images[ image.uuid ] === undefined ) {
  10801. meta.images[ image.uuid ] = {
  10802. uuid: image.uuid,
  10803. url: getDataURL( image )
  10804. };
  10805. }
  10806. output.image = image.uuid;
  10807. }
  10808. meta.textures[ this.uuid ] = output;
  10809. return output;
  10810. },
  10811. dispose: function () {
  10812. this.dispatchEvent( { type: 'dispose' } );
  10813. },
  10814. transformUv: function ( uv ) {
  10815. if ( this.mapping !== THREE.UVMapping ) return;
  10816. uv.multiply( this.repeat );
  10817. uv.add( this.offset );
  10818. if ( uv.x < 0 || uv.x > 1 ) {
  10819. switch ( this.wrapS ) {
  10820. case THREE.RepeatWrapping:
  10821. uv.x = uv.x - Math.floor( uv.x );
  10822. break;
  10823. case THREE.ClampToEdgeWrapping:
  10824. uv.x = uv.x < 0 ? 0 : 1;
  10825. break;
  10826. case THREE.MirroredRepeatWrapping:
  10827. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  10828. uv.x = Math.ceil( uv.x ) - uv.x;
  10829. } else {
  10830. uv.x = uv.x - Math.floor( uv.x );
  10831. }
  10832. break;
  10833. }
  10834. }
  10835. if ( uv.y < 0 || uv.y > 1 ) {
  10836. switch ( this.wrapT ) {
  10837. case THREE.RepeatWrapping:
  10838. uv.y = uv.y - Math.floor( uv.y );
  10839. break;
  10840. case THREE.ClampToEdgeWrapping:
  10841. uv.y = uv.y < 0 ? 0 : 1;
  10842. break;
  10843. case THREE.MirroredRepeatWrapping:
  10844. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  10845. uv.y = Math.ceil( uv.y ) - uv.y;
  10846. } else {
  10847. uv.y = uv.y - Math.floor( uv.y );
  10848. }
  10849. break;
  10850. }
  10851. }
  10852. if ( this.flipY ) {
  10853. uv.y = 1 - uv.y;
  10854. }
  10855. }
  10856. };
  10857. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  10858. THREE.TextureIdCount = 0;
  10859. // File:src/textures/CanvasTexture.js
  10860. /**
  10861. * @author mrdoob / http://mrdoob.com/
  10862. */
  10863. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10864. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10865. this.needsUpdate = true;
  10866. };
  10867. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  10868. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  10869. // File:src/textures/CubeTexture.js
  10870. /**
  10871. * @author mrdoob / http://mrdoob.com/
  10872. */
  10873. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10874. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  10875. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10876. this.images = images;
  10877. this.flipY = false;
  10878. };
  10879. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  10880. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  10881. THREE.CubeTexture.prototype.copy = function ( source ) {
  10882. THREE.Texture.prototype.copy.call( this, source );
  10883. this.images = source.images;
  10884. return this;
  10885. };
  10886. // File:src/textures/CompressedTexture.js
  10887. /**
  10888. * @author alteredq / http://alteredqualia.com/
  10889. */
  10890. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  10891. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10892. this.image = { width: width, height: height };
  10893. this.mipmaps = mipmaps;
  10894. // no flipping for cube textures
  10895. // (also flipping doesn't work for compressed textures )
  10896. this.flipY = false;
  10897. // can't generate mipmaps for compressed textures
  10898. // mips must be embedded in DDS files
  10899. this.generateMipmaps = false;
  10900. };
  10901. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  10902. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  10903. // File:src/textures/DataTexture.js
  10904. /**
  10905. * @author alteredq / http://alteredqualia.com/
  10906. */
  10907. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  10908. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10909. this.image = { data: data, width: width, height: height };
  10910. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  10911. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  10912. this.flipY = false;
  10913. this.generateMipmaps = false;
  10914. };
  10915. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  10916. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  10917. // File:src/textures/VideoTexture.js
  10918. /**
  10919. * @author mrdoob / http://mrdoob.com/
  10920. */
  10921. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10922. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10923. this.generateMipmaps = false;
  10924. var scope = this;
  10925. var update = function () {
  10926. requestAnimationFrame( update );
  10927. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  10928. scope.needsUpdate = true;
  10929. }
  10930. };
  10931. update();
  10932. };
  10933. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  10934. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  10935. // File:src/objects/Group.js
  10936. /**
  10937. * @author mrdoob / http://mrdoob.com/
  10938. */
  10939. THREE.Group = function () {
  10940. THREE.Object3D.call( this );
  10941. this.type = 'Group';
  10942. };
  10943. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  10944. THREE.Group.prototype.constructor = THREE.Group;
  10945. // File:src/objects/Points.js
  10946. /**
  10947. * @author alteredq / http://alteredqualia.com/
  10948. */
  10949. THREE.Points = function ( geometry, material ) {
  10950. THREE.Object3D.call( this );
  10951. this.type = 'Points';
  10952. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  10953. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  10954. };
  10955. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  10956. THREE.Points.prototype.constructor = THREE.Points;
  10957. THREE.Points.prototype.raycast = ( function () {
  10958. var inverseMatrix = new THREE.Matrix4();
  10959. var ray = new THREE.Ray();
  10960. return function raycast( raycaster, intersects ) {
  10961. var object = this;
  10962. var geometry = object.geometry;
  10963. var threshold = raycaster.params.Points.threshold;
  10964. inverseMatrix.getInverse( this.matrixWorld );
  10965. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  10966. if ( geometry.boundingBox !== null ) {
  10967. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  10968. return;
  10969. }
  10970. }
  10971. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10972. var localThresholdSq = localThreshold * localThreshold;
  10973. var position = new THREE.Vector3();
  10974. function testPoint( point, index ) {
  10975. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  10976. if ( rayPointDistanceSq < localThresholdSq ) {
  10977. var intersectPoint = ray.closestPointToPoint( point );
  10978. intersectPoint.applyMatrix4( object.matrixWorld );
  10979. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  10980. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10981. intersects.push( {
  10982. distance: distance,
  10983. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  10984. point: intersectPoint.clone(),
  10985. index: index,
  10986. face: null,
  10987. object: object
  10988. } );
  10989. }
  10990. }
  10991. if ( geometry instanceof THREE.BufferGeometry ) {
  10992. var index = geometry.index;
  10993. var attributes = geometry.attributes;
  10994. var positions = attributes.position.array;
  10995. if ( index !== null ) {
  10996. var indices = index.array;
  10997. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  10998. var a = indices[ i ];
  10999. position.fromArray( positions, a * 3 );
  11000. testPoint( position, a );
  11001. }
  11002. } else {
  11003. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  11004. position.fromArray( positions, i * 3 );
  11005. testPoint( position, i );
  11006. }
  11007. }
  11008. } else {
  11009. var vertices = geometry.vertices;
  11010. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  11011. testPoint( vertices[ i ], i );
  11012. }
  11013. }
  11014. };
  11015. }() );
  11016. THREE.Points.prototype.clone = function () {
  11017. return new this.constructor( this.geometry, this.material ).copy( this );
  11018. };
  11019. THREE.Points.prototype.toJSON = function ( meta ) {
  11020. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11021. // only serialize if not in meta geometries cache
  11022. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  11023. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  11024. }
  11025. // only serialize if not in meta materials cache
  11026. if ( meta.materials[ this.material.uuid ] === undefined ) {
  11027. meta.materials[ this.material.uuid ] = this.material.toJSON();
  11028. }
  11029. data.object.geometry = this.geometry.uuid;
  11030. data.object.material = this.material.uuid;
  11031. return data;
  11032. };
  11033. // Backwards compatibility
  11034. THREE.PointCloud = function ( geometry, material ) {
  11035. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  11036. return new THREE.Points( geometry, material );
  11037. };
  11038. THREE.ParticleSystem = function ( geometry, material ) {
  11039. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  11040. return new THREE.Points( geometry, material );
  11041. };
  11042. // File:src/objects/Line.js
  11043. /**
  11044. * @author mrdoob / http://mrdoob.com/
  11045. */
  11046. THREE.Line = function ( geometry, material, mode ) {
  11047. if ( mode === 1 ) {
  11048. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  11049. return new THREE.LineSegments( geometry, material );
  11050. }
  11051. THREE.Object3D.call( this );
  11052. this.type = 'Line';
  11053. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  11054. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  11055. };
  11056. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  11057. THREE.Line.prototype.constructor = THREE.Line;
  11058. THREE.Line.prototype.raycast = ( function () {
  11059. var inverseMatrix = new THREE.Matrix4();
  11060. var ray = new THREE.Ray();
  11061. var sphere = new THREE.Sphere();
  11062. return function raycast( raycaster, intersects ) {
  11063. var precision = raycaster.linePrecision;
  11064. var precisionSq = precision * precision;
  11065. var geometry = this.geometry;
  11066. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  11067. // Checking boundingSphere distance to ray
  11068. sphere.copy( geometry.boundingSphere );
  11069. sphere.applyMatrix4( this.matrixWorld );
  11070. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  11071. return;
  11072. }
  11073. inverseMatrix.getInverse( this.matrixWorld );
  11074. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  11075. var vStart = new THREE.Vector3();
  11076. var vEnd = new THREE.Vector3();
  11077. var interSegment = new THREE.Vector3();
  11078. var interRay = new THREE.Vector3();
  11079. var step = this instanceof THREE.LineSegments ? 2 : 1;
  11080. if ( geometry instanceof THREE.BufferGeometry ) {
  11081. var index = geometry.index;
  11082. var attributes = geometry.attributes;
  11083. if ( index !== null ) {
  11084. var indices = index.array;
  11085. var positions = attributes.position.array;
  11086. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  11087. var a = indices[ i ];
  11088. var b = indices[ i + 1 ];
  11089. vStart.fromArray( positions, a * 3 );
  11090. vEnd.fromArray( positions, b * 3 );
  11091. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  11092. if ( distSq > precisionSq ) continue;
  11093. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11094. var distance = raycaster.ray.origin.distanceTo( interRay );
  11095. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11096. intersects.push( {
  11097. distance: distance,
  11098. // What do we want? intersection point on the ray or on the segment??
  11099. // point: raycaster.ray.at( distance ),
  11100. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11101. index: i,
  11102. face: null,
  11103. faceIndex: null,
  11104. object: this
  11105. } );
  11106. }
  11107. } else {
  11108. var positions = attributes.position.array;
  11109. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  11110. vStart.fromArray( positions, 3 * i );
  11111. vEnd.fromArray( positions, 3 * i + 3 );
  11112. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  11113. if ( distSq > precisionSq ) continue;
  11114. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11115. var distance = raycaster.ray.origin.distanceTo( interRay );
  11116. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11117. intersects.push( {
  11118. distance: distance,
  11119. // What do we want? intersection point on the ray or on the segment??
  11120. // point: raycaster.ray.at( distance ),
  11121. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11122. index: i,
  11123. face: null,
  11124. faceIndex: null,
  11125. object: this
  11126. } );
  11127. }
  11128. }
  11129. } else if ( geometry instanceof THREE.Geometry ) {
  11130. var vertices = geometry.vertices;
  11131. var nbVertices = vertices.length;
  11132. for ( var i = 0; i < nbVertices - 1; i += step ) {
  11133. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  11134. if ( distSq > precisionSq ) continue;
  11135. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11136. var distance = raycaster.ray.origin.distanceTo( interRay );
  11137. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11138. intersects.push( {
  11139. distance: distance,
  11140. // What do we want? intersection point on the ray or on the segment??
  11141. // point: raycaster.ray.at( distance ),
  11142. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11143. index: i,
  11144. face: null,
  11145. faceIndex: null,
  11146. object: this
  11147. } );
  11148. }
  11149. }
  11150. };
  11151. }() );
  11152. THREE.Line.prototype.clone = function () {
  11153. return new this.constructor( this.geometry, this.material ).copy( this );
  11154. };
  11155. THREE.Line.prototype.toJSON = function ( meta ) {
  11156. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11157. // only serialize if not in meta geometries cache
  11158. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  11159. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  11160. }
  11161. // only serialize if not in meta materials cache
  11162. if ( meta.materials[ this.material.uuid ] === undefined ) {
  11163. meta.materials[ this.material.uuid ] = this.material.toJSON();
  11164. }
  11165. data.object.geometry = this.geometry.uuid;
  11166. data.object.material = this.material.uuid;
  11167. return data;
  11168. };
  11169. // DEPRECATED
  11170. THREE.LineStrip = 0;
  11171. THREE.LinePieces = 1;
  11172. // File:src/objects/LineSegments.js
  11173. /**
  11174. * @author mrdoob / http://mrdoob.com/
  11175. */
  11176. THREE.LineSegments = function ( geometry, material ) {
  11177. THREE.Line.call( this, geometry, material );
  11178. this.type = 'LineSegments';
  11179. };
  11180. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  11181. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  11182. // File:src/objects/Mesh.js
  11183. /**
  11184. * @author mrdoob / http://mrdoob.com/
  11185. * @author alteredq / http://alteredqualia.com/
  11186. * @author mikael emtinger / http://gomo.se/
  11187. * @author jonobr1 / http://jonobr1.com/
  11188. */
  11189. THREE.Mesh = function ( geometry, material ) {
  11190. THREE.Object3D.call( this );
  11191. this.type = 'Mesh';
  11192. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  11193. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  11194. this.updateMorphTargets();
  11195. };
  11196. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  11197. THREE.Mesh.prototype.constructor = THREE.Mesh;
  11198. THREE.Mesh.prototype.updateMorphTargets = function () {
  11199. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  11200. this.morphTargetBase = - 1;
  11201. this.morphTargetInfluences = [];
  11202. this.morphTargetDictionary = {};
  11203. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  11204. this.morphTargetInfluences.push( 0 );
  11205. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  11206. }
  11207. }
  11208. };
  11209. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  11210. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  11211. return this.morphTargetDictionary[ name ];
  11212. }
  11213. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  11214. return 0;
  11215. };
  11216. THREE.Mesh.prototype.raycast = ( function () {
  11217. var inverseMatrix = new THREE.Matrix4();
  11218. var ray = new THREE.Ray();
  11219. var sphere = new THREE.Sphere();
  11220. var vA = new THREE.Vector3();
  11221. var vB = new THREE.Vector3();
  11222. var vC = new THREE.Vector3();
  11223. var tempA = new THREE.Vector3();
  11224. var tempB = new THREE.Vector3();
  11225. var tempC = new THREE.Vector3();
  11226. var uvA = new THREE.Vector2();
  11227. var uvB = new THREE.Vector2();
  11228. var uvC = new THREE.Vector2();
  11229. var barycoord = new THREE.Vector3();
  11230. var intersectionPoint = new THREE.Vector3();
  11231. var intersectionPointWorld = new THREE.Vector3();
  11232. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  11233. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  11234. uv1.multiplyScalar( barycoord.x );
  11235. uv2.multiplyScalar( barycoord.y );
  11236. uv3.multiplyScalar( barycoord.z );
  11237. uv1.add( uv2 ).add( uv3 );
  11238. return uv1.clone();
  11239. }
  11240. return function raycast( raycaster, intersects ) {
  11241. var geometry = this.geometry;
  11242. var material = this.material;
  11243. if ( material === undefined ) return;
  11244. // Checking boundingSphere distance to ray
  11245. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  11246. sphere.copy( geometry.boundingSphere );
  11247. sphere.applyMatrix4( this.matrixWorld );
  11248. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  11249. return;
  11250. }
  11251. // Check boundingBox before continuing
  11252. inverseMatrix.getInverse( this.matrixWorld );
  11253. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  11254. if ( geometry.boundingBox !== null ) {
  11255. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  11256. return;
  11257. }
  11258. }
  11259. var a, b, c;
  11260. if ( geometry instanceof THREE.BufferGeometry ) {
  11261. var index = geometry.index;
  11262. var attributes = geometry.attributes;
  11263. if ( index !== null ) {
  11264. var indices = index.array;
  11265. var positions = attributes.position.array;
  11266. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  11267. a = indices[ i ];
  11268. b = indices[ i + 1 ];
  11269. c = indices[ i + 2 ];
  11270. vA.fromArray( positions, a * 3 );
  11271. vB.fromArray( positions, b * 3 );
  11272. vC.fromArray( positions, c * 3 );
  11273. if ( material.side === THREE.BackSide ) {
  11274. if ( ray.intersectTriangle( vC, vB, vA, true, intersectionPoint ) === null ) continue;
  11275. } else {
  11276. if ( ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide, intersectionPoint ) === null ) continue;
  11277. }
  11278. intersectionPointWorld.copy( intersectionPoint );
  11279. intersectionPointWorld.applyMatrix4( this.matrixWorld );
  11280. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  11281. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11282. var uv;
  11283. if ( attributes.uv !== undefined ) {
  11284. var uvs = attributes.uv.array;
  11285. uvA.fromArray( uvs, a * 2 );
  11286. uvB.fromArray( uvs, b * 2 );
  11287. uvC.fromArray( uvs, c * 2 );
  11288. uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  11289. }
  11290. intersects.push( {
  11291. distance: distance,
  11292. point: intersectionPointWorld.clone(),
  11293. uv: uv,
  11294. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  11295. faceIndex: Math.floor( i / 3 ), // triangle number in indices buffer semantics
  11296. object: this
  11297. } );
  11298. }
  11299. } else {
  11300. var positions = attributes.position.array;
  11301. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  11302. vA.fromArray( positions, i );
  11303. vB.fromArray( positions, i + 3 );
  11304. vC.fromArray( positions, i + 6 );
  11305. if ( material.side === THREE.BackSide ) {
  11306. if ( ray.intersectTriangle( vC, vB, vA, true, intersectionPoint ) === null ) continue;
  11307. } else {
  11308. if ( ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide, intersectionPoint ) === null ) continue;
  11309. }
  11310. intersectionPointWorld.copy( intersectionPoint );
  11311. intersectionPointWorld.applyMatrix4( this.matrixWorld );
  11312. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  11313. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11314. var uv;
  11315. if ( attributes.uv !== undefined ) {
  11316. var uvs = attributes.uv.array;
  11317. uvA.fromArray( uvs, i );
  11318. uvB.fromArray( uvs, i + 2 );
  11319. uvC.fromArray( uvs, i + 4 );
  11320. uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  11321. }
  11322. a = i / 3;
  11323. b = a + 1;
  11324. c = a + 2;
  11325. intersects.push( {
  11326. distance: distance,
  11327. point: intersectionPointWorld.clone(),
  11328. uv: uv,
  11329. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  11330. index: a, // triangle number in positions buffer semantics
  11331. object: this
  11332. } );
  11333. }
  11334. }
  11335. } else if ( geometry instanceof THREE.Geometry ) {
  11336. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  11337. var materials = isFaceMaterial === true ? material.materials : null;
  11338. var vertices = geometry.vertices;
  11339. var faces = geometry.faces;
  11340. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  11341. var face = faces[ f ];
  11342. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  11343. if ( faceMaterial === undefined ) continue;
  11344. a = vertices[ face.a ];
  11345. b = vertices[ face.b ];
  11346. c = vertices[ face.c ];
  11347. if ( faceMaterial.morphTargets === true ) {
  11348. var morphTargets = geometry.morphTargets;
  11349. var morphInfluences = this.morphTargetInfluences;
  11350. vA.set( 0, 0, 0 );
  11351. vB.set( 0, 0, 0 );
  11352. vC.set( 0, 0, 0 );
  11353. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  11354. var influence = morphInfluences[ t ];
  11355. if ( influence === 0 ) continue;
  11356. var targets = morphTargets[ t ].vertices;
  11357. vA.addScaledVector( tempA.subVectors( targets[ face.a ], a ), influence );
  11358. vB.addScaledVector( tempB.subVectors( targets[ face.b ], b ), influence );
  11359. vC.addScaledVector( tempC.subVectors( targets[ face.c ], c ), influence );
  11360. }
  11361. vA.add( a );
  11362. vB.add( b );
  11363. vC.add( c );
  11364. a = vA;
  11365. b = vB;
  11366. c = vC;
  11367. }
  11368. if ( faceMaterial.side === THREE.BackSide ) {
  11369. if ( ray.intersectTriangle( c, b, a, true, intersectionPoint ) === null ) continue;
  11370. } else {
  11371. if ( ray.intersectTriangle( a, b, c, faceMaterial.side !== THREE.DoubleSide, intersectionPoint ) === null ) continue;
  11372. }
  11373. intersectionPointWorld.copy( intersectionPoint );
  11374. intersectionPointWorld.applyMatrix4( this.matrixWorld );
  11375. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  11376. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11377. var uv;
  11378. if ( geometry.faceVertexUvs[ 0 ].length > 0 ) {
  11379. var uvs = geometry.faceVertexUvs[ 0 ][ f ];
  11380. uvA.copy( uvs[ 0 ] );
  11381. uvB.copy( uvs[ 1 ] );
  11382. uvC.copy( uvs[ 2 ] );
  11383. uv = uvIntersection( intersectionPoint, a, b, c, uvA, uvB, uvC );
  11384. }
  11385. intersects.push( {
  11386. distance: distance,
  11387. point: intersectionPointWorld.clone(),
  11388. uv: uv,
  11389. face: face,
  11390. faceIndex: f,
  11391. object: this
  11392. } );
  11393. }
  11394. }
  11395. };
  11396. }() );
  11397. THREE.Mesh.prototype.clone = function () {
  11398. return new this.constructor( this.geometry, this.material ).copy( this );
  11399. };
  11400. THREE.Mesh.prototype.toJSON = function ( meta ) {
  11401. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11402. // only serialize if not in meta geometries cache
  11403. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  11404. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  11405. }
  11406. // only serialize if not in meta materials cache
  11407. if ( meta.materials[ this.material.uuid ] === undefined ) {
  11408. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  11409. }
  11410. data.object.geometry = this.geometry.uuid;
  11411. data.object.material = this.material.uuid;
  11412. return data;
  11413. };
  11414. // File:src/objects/Bone.js
  11415. /**
  11416. * @author mikael emtinger / http://gomo.se/
  11417. * @author alteredq / http://alteredqualia.com/
  11418. * @author ikerr / http://verold.com
  11419. */
  11420. THREE.Bone = function ( skin ) {
  11421. THREE.Object3D.call( this );
  11422. this.type = 'Bone';
  11423. this.skin = skin;
  11424. };
  11425. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  11426. THREE.Bone.prototype.constructor = THREE.Bone;
  11427. THREE.Bone.prototype.copy = function ( source ) {
  11428. THREE.Object3D.prototype.copy.call( this, source );
  11429. this.skin = source.skin;
  11430. return this;
  11431. };
  11432. // File:src/objects/Skeleton.js
  11433. /**
  11434. * @author mikael emtinger / http://gomo.se/
  11435. * @author alteredq / http://alteredqualia.com/
  11436. * @author michael guerrero / http://realitymeltdown.com
  11437. * @author ikerr / http://verold.com
  11438. */
  11439. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  11440. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  11441. this.identityMatrix = new THREE.Matrix4();
  11442. // copy the bone array
  11443. bones = bones || [];
  11444. this.bones = bones.slice( 0 );
  11445. // create a bone texture or an array of floats
  11446. if ( this.useVertexTexture ) {
  11447. // layout (1 matrix = 4 pixels)
  11448. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  11449. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  11450. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  11451. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  11452. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  11453. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  11454. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  11455. size = Math.max( size, 4 );
  11456. this.boneTextureWidth = size;
  11457. this.boneTextureHeight = size;
  11458. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  11459. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  11460. } else {
  11461. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  11462. }
  11463. // use the supplied bone inverses or calculate the inverses
  11464. if ( boneInverses === undefined ) {
  11465. this.calculateInverses();
  11466. } else {
  11467. if ( this.bones.length === boneInverses.length ) {
  11468. this.boneInverses = boneInverses.slice( 0 );
  11469. } else {
  11470. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  11471. this.boneInverses = [];
  11472. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11473. this.boneInverses.push( new THREE.Matrix4() );
  11474. }
  11475. }
  11476. }
  11477. };
  11478. THREE.Skeleton.prototype.calculateInverses = function () {
  11479. this.boneInverses = [];
  11480. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11481. var inverse = new THREE.Matrix4();
  11482. if ( this.bones[ b ] ) {
  11483. inverse.getInverse( this.bones[ b ].matrixWorld );
  11484. }
  11485. this.boneInverses.push( inverse );
  11486. }
  11487. };
  11488. THREE.Skeleton.prototype.pose = function () {
  11489. var bone;
  11490. // recover the bind-time world matrices
  11491. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11492. bone = this.bones[ b ];
  11493. if ( bone ) {
  11494. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  11495. }
  11496. }
  11497. // compute the local matrices, positions, rotations and scales
  11498. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11499. bone = this.bones[ b ];
  11500. if ( bone ) {
  11501. if ( bone.parent ) {
  11502. bone.matrix.getInverse( bone.parent.matrixWorld );
  11503. bone.matrix.multiply( bone.matrixWorld );
  11504. } else {
  11505. bone.matrix.copy( bone.matrixWorld );
  11506. }
  11507. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  11508. }
  11509. }
  11510. };
  11511. THREE.Skeleton.prototype.update = ( function () {
  11512. var offsetMatrix = new THREE.Matrix4();
  11513. return function update() {
  11514. // flatten bone matrices to array
  11515. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11516. // compute the offset between the current and the original transform
  11517. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  11518. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  11519. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  11520. }
  11521. if ( this.useVertexTexture ) {
  11522. this.boneTexture.needsUpdate = true;
  11523. }
  11524. };
  11525. } )();
  11526. THREE.Skeleton.prototype.clone = function () {
  11527. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  11528. };
  11529. // File:src/objects/SkinnedMesh.js
  11530. /**
  11531. * @author mikael emtinger / http://gomo.se/
  11532. * @author alteredq / http://alteredqualia.com/
  11533. * @author ikerr / http://verold.com
  11534. */
  11535. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  11536. THREE.Mesh.call( this, geometry, material );
  11537. this.type = 'SkinnedMesh';
  11538. this.bindMode = "attached";
  11539. this.bindMatrix = new THREE.Matrix4();
  11540. this.bindMatrixInverse = new THREE.Matrix4();
  11541. // init bones
  11542. // TODO: remove bone creation as there is no reason (other than
  11543. // convenience) for THREE.SkinnedMesh to do this.
  11544. var bones = [];
  11545. if ( this.geometry && this.geometry.bones !== undefined ) {
  11546. var bone, gbone;
  11547. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  11548. gbone = this.geometry.bones[ b ];
  11549. bone = new THREE.Bone( this );
  11550. bones.push( bone );
  11551. bone.name = gbone.name;
  11552. bone.position.fromArray( gbone.pos );
  11553. bone.quaternion.fromArray( gbone.rotq );
  11554. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  11555. }
  11556. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  11557. gbone = this.geometry.bones[ b ];
  11558. if ( gbone.parent !== - 1 ) {
  11559. bones[ gbone.parent ].add( bones[ b ] );
  11560. } else {
  11561. this.add( bones[ b ] );
  11562. }
  11563. }
  11564. }
  11565. this.normalizeSkinWeights();
  11566. this.updateMatrixWorld( true );
  11567. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  11568. };
  11569. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  11570. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  11571. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  11572. this.skeleton = skeleton;
  11573. if ( bindMatrix === undefined ) {
  11574. this.updateMatrixWorld( true );
  11575. this.skeleton.calculateInverses();
  11576. bindMatrix = this.matrixWorld;
  11577. }
  11578. this.bindMatrix.copy( bindMatrix );
  11579. this.bindMatrixInverse.getInverse( bindMatrix );
  11580. };
  11581. THREE.SkinnedMesh.prototype.pose = function () {
  11582. this.skeleton.pose();
  11583. };
  11584. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  11585. if ( this.geometry instanceof THREE.Geometry ) {
  11586. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  11587. var sw = this.geometry.skinWeights[ i ];
  11588. var scale = 1.0 / sw.lengthManhattan();
  11589. if ( scale !== Infinity ) {
  11590. sw.multiplyScalar( scale );
  11591. } else {
  11592. sw.set( 1 ); // this will be normalized by the shader anyway
  11593. }
  11594. }
  11595. } else {
  11596. // skinning weights assumed to be normalized for THREE.BufferGeometry
  11597. }
  11598. };
  11599. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  11600. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  11601. if ( this.bindMode === "attached" ) {
  11602. this.bindMatrixInverse.getInverse( this.matrixWorld );
  11603. } else if ( this.bindMode === "detached" ) {
  11604. this.bindMatrixInverse.getInverse( this.bindMatrix );
  11605. } else {
  11606. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  11607. }
  11608. };
  11609. THREE.SkinnedMesh.prototype.clone = function() {
  11610. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  11611. };
  11612. // File:src/objects/LOD.js
  11613. /**
  11614. * @author mikael emtinger / http://gomo.se/
  11615. * @author alteredq / http://alteredqualia.com/
  11616. * @author mrdoob / http://mrdoob.com/
  11617. */
  11618. THREE.LOD = function () {
  11619. THREE.Object3D.call( this );
  11620. this.type = 'LOD';
  11621. Object.defineProperties( this, {
  11622. levels: {
  11623. enumerable: true,
  11624. value: []
  11625. },
  11626. objects: {
  11627. get: function () {
  11628. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  11629. return this.levels;
  11630. }
  11631. }
  11632. } );
  11633. };
  11634. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  11635. THREE.LOD.prototype.constructor = THREE.LOD;
  11636. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  11637. if ( distance === undefined ) distance = 0;
  11638. distance = Math.abs( distance );
  11639. var levels = this.levels;
  11640. for ( var l = 0; l < levels.length; l ++ ) {
  11641. if ( distance < levels[ l ].distance ) {
  11642. break;
  11643. }
  11644. }
  11645. levels.splice( l, 0, { distance: distance, object: object } );
  11646. this.add( object );
  11647. };
  11648. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  11649. var levels = this.levels;
  11650. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  11651. if ( distance < levels[ i ].distance ) {
  11652. break;
  11653. }
  11654. }
  11655. return levels[ i - 1 ].object;
  11656. };
  11657. THREE.LOD.prototype.raycast = ( function () {
  11658. var matrixPosition = new THREE.Vector3();
  11659. return function raycast( raycaster, intersects ) {
  11660. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  11661. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  11662. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  11663. };
  11664. }() );
  11665. THREE.LOD.prototype.update = function () {
  11666. var v1 = new THREE.Vector3();
  11667. var v2 = new THREE.Vector3();
  11668. return function update( camera ) {
  11669. var levels = this.levels;
  11670. if ( levels.length > 1 ) {
  11671. v1.setFromMatrixPosition( camera.matrixWorld );
  11672. v2.setFromMatrixPosition( this.matrixWorld );
  11673. var distance = v1.distanceTo( v2 );
  11674. levels[ 0 ].object.visible = true;
  11675. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  11676. if ( distance >= levels[ i ].distance ) {
  11677. levels[ i - 1 ].object.visible = false;
  11678. levels[ i ].object.visible = true;
  11679. } else {
  11680. break;
  11681. }
  11682. }
  11683. for ( ; i < l; i ++ ) {
  11684. levels[ i ].object.visible = false;
  11685. }
  11686. }
  11687. };
  11688. }();
  11689. THREE.LOD.prototype.copy = function ( source ) {
  11690. THREE.Object3D.prototype.copy.call( this, source, false );
  11691. var levels = source.levels;
  11692. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  11693. var level = levels[ i ];
  11694. this.addLevel( level.object.clone(), level.distance );
  11695. }
  11696. return this;
  11697. };
  11698. THREE.LOD.prototype.toJSON = function ( meta ) {
  11699. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11700. data.object.levels = [];
  11701. var levels = this.levels;
  11702. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  11703. var level = levels[ i ];
  11704. data.object.levels.push( {
  11705. object: level.object.uuid,
  11706. distance: level.distance
  11707. } );
  11708. }
  11709. return data;
  11710. };
  11711. // File:src/objects/Sprite.js
  11712. /**
  11713. * @author mikael emtinger / http://gomo.se/
  11714. * @author alteredq / http://alteredqualia.com/
  11715. */
  11716. THREE.Sprite = ( function () {
  11717. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  11718. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  11719. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  11720. var geometry = new THREE.BufferGeometry();
  11721. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  11722. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  11723. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  11724. return function Sprite( material ) {
  11725. THREE.Object3D.call( this );
  11726. this.type = 'Sprite';
  11727. this.geometry = geometry;
  11728. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  11729. };
  11730. } )();
  11731. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  11732. THREE.Sprite.prototype.constructor = THREE.Sprite;
  11733. THREE.Sprite.prototype.raycast = ( function () {
  11734. var matrixPosition = new THREE.Vector3();
  11735. return function raycast( raycaster, intersects ) {
  11736. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  11737. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  11738. var guessSizeSq = this.scale.x * this.scale.y;
  11739. if ( distanceSq > guessSizeSq ) {
  11740. return;
  11741. }
  11742. intersects.push( {
  11743. distance: Math.sqrt( distanceSq ),
  11744. point: this.position,
  11745. face: null,
  11746. object: this
  11747. } );
  11748. };
  11749. }() );
  11750. THREE.Sprite.prototype.clone = function () {
  11751. return new this.constructor( this.material ).copy( this );
  11752. };
  11753. THREE.Sprite.prototype.toJSON = function ( meta ) {
  11754. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11755. // only serialize if not in meta materials cache
  11756. if ( meta.materials[ this.material.uuid ] === undefined ) {
  11757. meta.materials[ this.material.uuid ] = this.material.toJSON();
  11758. }
  11759. data.object.material = this.material.uuid;
  11760. return data;
  11761. };
  11762. // Backwards compatibility
  11763. THREE.Particle = THREE.Sprite;
  11764. // File:src/objects/LensFlare.js
  11765. /**
  11766. * @author mikael emtinger / http://gomo.se/
  11767. * @author alteredq / http://alteredqualia.com/
  11768. */
  11769. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  11770. THREE.Object3D.call( this );
  11771. this.lensFlares = [];
  11772. this.positionScreen = new THREE.Vector3();
  11773. this.customUpdateCallback = undefined;
  11774. if ( texture !== undefined ) {
  11775. this.add( texture, size, distance, blending, color );
  11776. }
  11777. };
  11778. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  11779. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  11780. /*
  11781. * Add: adds another flare
  11782. */
  11783. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  11784. if ( size === undefined ) size = - 1;
  11785. if ( distance === undefined ) distance = 0;
  11786. if ( opacity === undefined ) opacity = 1;
  11787. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  11788. if ( blending === undefined ) blending = THREE.NormalBlending;
  11789. distance = Math.min( distance, Math.max( 0, distance ) );
  11790. this.lensFlares.push( {
  11791. texture: texture, // THREE.Texture
  11792. size: size, // size in pixels (-1 = use texture.width)
  11793. distance: distance, // distance (0-1) from light source (0=at light source)
  11794. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  11795. scale: 1, // scale
  11796. rotation: 0, // rotation
  11797. opacity: opacity, // opacity
  11798. color: color, // color
  11799. blending: blending // blending
  11800. } );
  11801. };
  11802. /*
  11803. * Update lens flares update positions on all flares based on the screen position
  11804. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  11805. */
  11806. THREE.LensFlare.prototype.updateLensFlares = function () {
  11807. var f, fl = this.lensFlares.length;
  11808. var flare;
  11809. var vecX = - this.positionScreen.x * 2;
  11810. var vecY = - this.positionScreen.y * 2;
  11811. for ( f = 0; f < fl; f ++ ) {
  11812. flare = this.lensFlares[ f ];
  11813. flare.x = this.positionScreen.x + vecX * flare.distance;
  11814. flare.y = this.positionScreen.y + vecY * flare.distance;
  11815. flare.wantedRotation = flare.x * Math.PI * 0.25;
  11816. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  11817. }
  11818. };
  11819. THREE.LensFlare.prototype.copy = function ( source ) {
  11820. THREE.Object3D.prototype.copy.call( this, source );
  11821. this.positionScreen.copy( source.positionScreen );
  11822. this.customUpdateCallback = source.customUpdateCallback;
  11823. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  11824. this.lensFlares.push( source.lensFlares[ i ] );
  11825. }
  11826. return this;
  11827. };
  11828. // File:src/scenes/Scene.js
  11829. /**
  11830. * @author mrdoob / http://mrdoob.com/
  11831. */
  11832. THREE.Scene = function () {
  11833. THREE.Object3D.call( this );
  11834. this.type = 'Scene';
  11835. this.fog = null;
  11836. this.overrideMaterial = null;
  11837. this.autoUpdate = true; // checked by the renderer
  11838. };
  11839. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  11840. THREE.Scene.prototype.constructor = THREE.Scene;
  11841. THREE.Scene.prototype.copy = function ( source ) {
  11842. THREE.Object3D.prototype.copy.call( this, source );
  11843. if ( source.fog !== null ) this.fog = source.fog.clone();
  11844. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  11845. this.autoUpdate = source.autoUpdate;
  11846. this.matrixAutoUpdate = source.matrixAutoUpdate;
  11847. return this;
  11848. };
  11849. // File:src/scenes/Fog.js
  11850. /**
  11851. * @author mrdoob / http://mrdoob.com/
  11852. * @author alteredq / http://alteredqualia.com/
  11853. */
  11854. THREE.Fog = function ( color, near, far ) {
  11855. this.name = '';
  11856. this.color = new THREE.Color( color );
  11857. this.near = ( near !== undefined ) ? near : 1;
  11858. this.far = ( far !== undefined ) ? far : 1000;
  11859. };
  11860. THREE.Fog.prototype.clone = function () {
  11861. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  11862. };
  11863. // File:src/scenes/FogExp2.js
  11864. /**
  11865. * @author mrdoob / http://mrdoob.com/
  11866. * @author alteredq / http://alteredqualia.com/
  11867. */
  11868. THREE.FogExp2 = function ( color, density ) {
  11869. this.name = '';
  11870. this.color = new THREE.Color( color );
  11871. this.density = ( density !== undefined ) ? density : 0.00025;
  11872. };
  11873. THREE.FogExp2.prototype.clone = function () {
  11874. return new THREE.FogExp2( this.color.getHex(), this.density );
  11875. };
  11876. // File:src/renderers/shaders/ShaderChunk.js
  11877. THREE.ShaderChunk = {};
  11878. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  11879. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  11880. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  11881. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  11882. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  11883. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  11884. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  11885. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  11886. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  11887. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  11888. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  11889. THREE.ShaderChunk[ 'begin_vertex'] = "\nvec3 transformed = vec3( position );\n";
  11890. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  11891. THREE.ShaderChunk[ 'beginnormal_vertex'] = "\nvec3 objectNormal = vec3( normal );\n";
  11892. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  11893. 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";
  11894. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  11895. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  11896. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  11897. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  11898. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  11899. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  11900. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  11901. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = color.xyz;\n\n#endif";
  11902. // File:src/renderers/shaders/ShaderChunk/common.glsl
  11903. 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 // Original approximation by Christophe Schlick '94\n //;float fresnel = pow( 1.0 - dotLH, 5.0 );\n\n // Optimized variant (presented by Epic at SIGGRAPH '13)\n float fresnel = exp2( ( -5.55437 * dotLH - 6.98316 ) * dotLH );\n\n return ( 1.0 - specularColor ) * fresnel + 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";
  11904. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  11905. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef FLIP_SIDED\n\n objectNormal = -objectNormal;\n\n#endif\n\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  11906. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  11907. THREE.ShaderChunk[ 'displacementmap_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n\n#endif\n";
  11908. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  11909. THREE.ShaderChunk[ 'displacementmap_pars_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n\n#endif\n";
  11910. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  11911. 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";
  11912. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  11913. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n";
  11914. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  11915. 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";
  11916. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  11917. 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";
  11918. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  11919. 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";
  11920. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  11921. 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";
  11922. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  11923. 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";
  11924. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  11925. 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";
  11926. // File:src/renderers/shaders/ShaderChunk/hemilight_fragment.glsl
  11927. THREE.ShaderChunk[ 'hemilight_fragment'] = "#if MAX_HEMI_LIGHTS > 0\n\n for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = hemisphereLightDirection[ i ];\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 totalAmbientLight += lightColor;\n\n }\n\n#endif\n\n";
  11928. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  11929. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  11930. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  11931. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  11932. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  11933. 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";
  11934. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  11935. 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 vec3 lVector = pointLightPosition[ i ] - 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 vec3 lVector = lightPosition - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], lightDir );\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 = directionalLightDirection[ i ];\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 = hemisphereLightDirection[ i ];\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";
  11936. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  11937. THREE.ShaderChunk[ 'lights_phong_fragment'] = "vec3 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 vec3 lVector = lightPosition + 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 vec3 lVector = lightPosition + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], lightDir );\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 = directionalLightDirection[ i ];\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#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";
  11938. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  11939. 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_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";
  11940. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  11941. THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n\n#endif\n";
  11942. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  11943. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif\n";
  11944. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  11945. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  11946. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  11947. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  11948. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  11949. 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";
  11950. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  11951. 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";
  11952. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  11953. 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";
  11954. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  11955. 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";
  11956. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  11957. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  11958. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  11959. 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";
  11960. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  11961. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  11962. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  11963. THREE.ShaderChunk[ 'morphnormal_vertex'] = "#ifdef USE_MORPHNORMALS\n\n objectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n objectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n objectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n objectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n\n#endif\n";
  11964. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  11965. 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";
  11966. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  11967. THREE.ShaderChunk[ 'morphtarget_vertex'] = "#ifdef USE_MORPHTARGETS\n\n transformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n transformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n transformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n transformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\n #ifndef USE_MORPHNORMALS\n\n transformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n transformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n transformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n transformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\n #endif\n\n#endif\n";
  11968. // File:src/renderers/shaders/ShaderChunk/normal_phong_fragment.glsl
  11969. THREE.ShaderChunk[ 'normal_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\n";
  11970. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  11971. 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";
  11972. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  11973. THREE.ShaderChunk[ 'project_vertex'] = "#ifdef USE_SKINNING\n\n vec4 mvPosition = modelViewMatrix * skinned;\n\n#else\n\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n\n#endif\n\ngl_Position = projectionMatrix * mvPosition;\n";
  11974. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  11975. 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 // to save on uniform space, we use the sign of @shadowDarkness[ i ] to determine\n // whether or not this light is a point light ( shadowDarkness[ i ] < 0 == point light)\n bool isPointLight = shadowDarkness[ i ] < 0.0;\n\n // get the real shadow darkness\n float realShadowDarkness = abs( shadowDarkness[ i ] );\n\n // for point lights, the uniform @vShadowCoord is re-purposed to hold\n // the distance from the light to the world-space position of the fragment.\n vec3 lightToPosition = vShadowCoord[ i ].xyz;\n\n float texelSizeX = 1.0 / shadowMapSize[ i ].x;\n float texelSizeY = 1.0 / shadowMapSize[ i ].y;\n\n vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\n float shadow = 0.0;\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 || isPointLight ) { \n\n #if defined( SHADOWMAP_TYPE_PCF )\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n if( isPointLight ) {\n\n float cubeTexelSize = 1.0 / ( shadowMapSize[ i ].x * 0.25 );\n vec3 baseDirection3D = normalize( lightToPosition );\n vec2 baseDirection2D = cubeToUV( baseDirection3D, texelSizeY );\n\n initGridSamplingDisk();\n\n float diskRadius = 1.25;\n float numSamples = 1.0;\n shadow = 0.0;\n\n vec3 baseDirection = normalize( lightToPosition );\n float curDistance = length( lightToPosition );\n\n float dist = unpack1K( texture2D( shadowMap[ i ], baseDirection2D ) ) + 0.1;\n if ( curDistance >= dist )\n shadow += 1.0;\n \n // evaluate each sampling direction\n for( int s = 0; s < 20; s++ ) {\n \n vec3 offset = gridSamplingDisk[ s ] * diskRadius * cubeTexelSize;\n vec3 adjustedBaseDirection3D = baseDirection3D + offset;\n vec2 adjustedBaseDirection2D = cubeToUV( adjustedBaseDirection3D, texelSizeY );\n dist = unpack1K( texture2D( shadowMap[ i ], adjustedBaseDirection2D ) ) + shadowBias[ i ];\n if ( curDistance >= dist )\n shadow += 1.0;\n numSamples += 1.0;\n\n }\n\n shadow /= numSamples;\n\n } else {\n\n #endif\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n \n /*\n // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL\n // must enroll loop manually\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 vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\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 float fDepth = unpackDepth( rgbaDepth );\n if ( fDepth < shadowCoord.z )\n shadow += 1.0;\n }\n shadow /= 9.0;\n */\n\n shadowCoord.z += shadowBias[ i ];\n\n const float shadowDelta = 1.0 / 9.0;\n\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\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 #if defined(POINT_LIGHT_SHADOWS)\n\n }\n\n #endif\n\n shadowColor = shadowColor * vec3( ( 1.0 - realShadowDarkness * shadow ) );\n\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n if( isPointLight ) {\n\n float cubeTexelSize = 1.0 / ( shadowMapSize[ i ].x * 0.25 );\n vec3 baseDirection3D = normalize( lightToPosition );\n vec2 baseDirection2D = cubeToUV( baseDirection3D, texelSizeY );\n\n initGridSamplingDisk();\n\n float diskRadius = 2.25;\n float numSamples = 1.0;\n shadow = 0.0;\n\n vec3 baseDirection = normalize( lightToPosition );\n float curDistance = length( lightToPosition );\n\n float dist = unpack1K( texture2D( shadowMap[ i ], baseDirection2D ) ) + 0.1;\n if ( curDistance >= dist )\n shadow += 1.0;\n\n // evaluate each sampling direction\n for( int s = 0; s < 20; s++ ) {\n\n vec3 offset = gridSamplingDisk[ s ] * diskRadius * cubeTexelSize;\n vec3 adjustedBaseDirection3D = baseDirection3D + offset;\n vec2 adjustedBaseDirection2D = cubeToUV( adjustedBaseDirection3D, texelSizeY );\n dist = unpack1K( texture2D( shadowMap[ i ], adjustedBaseDirection2D ) ) + shadowBias[ i ];\n if ( curDistance >= dist )\n shadow += 1.0;\n numSamples += 1.0;\n\n }\n\n shadow /= numSamples;\n\n } else {\n\n #endif\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n shadowCoord.z += shadowBias[ i ];\n\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\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 #if defined(POINT_LIGHT_SHADOWS)\n \n }\n\n #endif\n\n shadowColor = shadowColor * vec3( ( 1.0 - realShadowDarkness * shadow ) );\n\n #else\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n if( isPointLight ) {\n\n vec3 baseDirection3D = normalize( lightToPosition );\n vec2 baseDirection2D = cubeToUV( baseDirection3D, texelSizeY );\n vec4 data = texture2D( shadowMap[ i ], baseDirection2D );\n float dist = unpack1K( data ) + shadowBias[ i ];\n if ( length( lightToPosition ) >= dist)\n shadowColor = shadowColor * vec3( 1.0 - realShadowDarkness );\n\n } else {\n\n #endif\n shadowCoord.z += shadowBias[ i ];\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 - realShadowDarkness );\n\n // spot with multiple shadows has the same color as single shadow spot\n\n // shadowColor = min( shadowColor, vec3( realShadowDarkness ) );\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n }\n\n #endif\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";
  11976. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  11977. 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 #if defined(POINT_LIGHT_SHADOWS)\n\n float unpack1K ( vec4 color ) {\n\n const vec4 bitSh = vec4( 1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0 );\n return dot( color, bitSh ) * 1000.0;\n\n }\n\n // cubeToUV() maps a 3D direction vector suitable for cube texture mapping to a 2D\n // vector suitable for 2D texture mapping. This code uses the following layout for the\n // 2D texture:\n //\n // xzXZ\n // y Y\n //\n // Y - Positive y direction\n // y - Negative y direction\n // X - Positive x direction\n // x - Negative x direction\n // Z - Positive z direction\n // z - Negative z direction\n //\n // Source and test bed:\n // https://gist.github.com/tschw/da10c43c467ce8afd0c4\n\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n\n // Number of texels to avoid at the edge of each square\n\n vec3 absV = abs( v );\n\n // Intersect unit cube\n\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n\n // Apply scale to avoid seams\n\n // two texels less per square (one texel will do for NEAREST)\n v *= scaleToCube * ( 1.0 - 4.0 * texelSizeY );\n\n // Unwrap\n\n // space: -1 ... 1 range for each square\n //\n // #X## dim := ( 4 , 2 )\n // # # center := ( 1 , 1 )\n\n vec2 planar = v.xy;\n\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n\n if ( absV.z >= almostOne ) {\n\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n\n } else if ( absV.x >= almostOne ) {\n\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n\n } else if ( absV.y >= almostOne ) {\n\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n\n }\n\n // Transform to UV space\n\n // scale := 0.5 / dim\n // translate := ( center + 0.5 ) / dim\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\n }\n\n vec3 gridSamplingDisk[ 20 ];\n bool gridSamplingInitialized = false;\n\n void initGridSamplingDisk() {\n\n if( gridSamplingInitialized ) {\n\n return;\n\n }\n\n gridSamplingDisk[0] = vec3(1, 1, 1);\n gridSamplingDisk[1] = vec3(1, -1, 1);\n gridSamplingDisk[2] = vec3(-1, -1, 1);\n gridSamplingDisk[3] = vec3(-1, 1, 1);\n gridSamplingDisk[4] = vec3(1, 1, -1);\n gridSamplingDisk[5] = vec3(1, -1, -1);\n gridSamplingDisk[6] = vec3(-1, -1, -1);\n gridSamplingDisk[7] = vec3(-1, 1, -1);\n gridSamplingDisk[8] = vec3(1, 1, 0);\n gridSamplingDisk[9] = vec3(1, -1, 0);\n gridSamplingDisk[10] = vec3(-1, -1, 0);\n gridSamplingDisk[11] = vec3(-1, 1, 0);\n gridSamplingDisk[12] = vec3(1, 0, 1);\n gridSamplingDisk[13] = vec3(-1, 0, 1);\n gridSamplingDisk[14] = vec3(1, 0, -1);\n gridSamplingDisk[15] = vec3(-1, 0, -1);\n gridSamplingDisk[16] = vec3(0, 1, 1);\n gridSamplingDisk[17] = vec3(0, -1, 1);\n gridSamplingDisk[18] = vec3(0, -1, -1);\n gridSamplingDisk[19] = vec3(0, 1, -1);\n\n gridSamplingInitialized = true;\n\n }\n\n #endif\n\n#endif\n";
  11978. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  11979. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n#endif";
  11980. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  11981. THREE.ShaderChunk[ 'shadowmap_vertex'] = "#ifdef USE_SHADOWMAP\n\n for( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n // if shadowDarkness[ i ] < 0.0, that means we have a point light with a cube\n // shadow map\n if( shadowDarkness[ i ] < 0.0 ) {\n\n // calculate vector from light to vertex in view space\n\n vec3 fromLight = mvPosition.xyz - pointLightPosition[ i ];\n\n // Transform 'fromLight' into world space by multiplying it on the left\n // side of 'viewMatrix'. This is equivalent to multiplying it on the right\n // side of the transpose of 'viewMatrix'. Since 'viewMatrix' is orthogonal, \n // its transpose is the same as its inverse.\n\n fromLight = fromLight * mat3( viewMatrix );\n\n // We repurpose vShadowCoord to hold the distance in world space from the\n // light to the vertex. This value will be interpolated correctly in the fragment shader.\n\n vShadowCoord[ i ] = vec4( fromLight, 1.0 );\n\n } else {\n\n vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n\n }\n\n #else\n\n vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n\n #endif\n\n }\n\n#endif";
  11982. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  11983. 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";
  11984. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  11985. 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";
  11986. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  11987. THREE.ShaderChunk[ 'skinning_vertex'] = "#ifdef USE_SKINNING\n\n vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\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";
  11988. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  11989. 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 objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\n#endif\n";
  11990. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  11991. 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";
  11992. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  11993. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  11994. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  11995. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  11996. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  11997. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  11998. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  11999. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  12000. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  12001. 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";
  12002. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  12003. 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";
  12004. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  12005. 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";
  12006. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  12007. 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 #else\n\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n\n #endif\n\n#endif\n";
  12008. // File:src/renderers/shaders/UniformsUtils.js
  12009. /**
  12010. * Uniform Utilities
  12011. */
  12012. THREE.UniformsUtils = {
  12013. merge: function ( uniforms ) {
  12014. var merged = {};
  12015. for ( var u = 0; u < uniforms.length; u ++ ) {
  12016. var tmp = this.clone( uniforms[ u ] );
  12017. for ( var p in tmp ) {
  12018. merged[ p ] = tmp[ p ];
  12019. }
  12020. }
  12021. return merged;
  12022. },
  12023. clone: function ( uniforms_src ) {
  12024. var uniforms_dst = {};
  12025. for ( var u in uniforms_src ) {
  12026. uniforms_dst[ u ] = {};
  12027. for ( var p in uniforms_src[ u ] ) {
  12028. var parameter_src = uniforms_src[ u ][ p ];
  12029. if ( parameter_src instanceof THREE.Color ||
  12030. parameter_src instanceof THREE.Vector2 ||
  12031. parameter_src instanceof THREE.Vector3 ||
  12032. parameter_src instanceof THREE.Vector4 ||
  12033. parameter_src instanceof THREE.Matrix3 ||
  12034. parameter_src instanceof THREE.Matrix4 ||
  12035. parameter_src instanceof THREE.Texture ) {
  12036. uniforms_dst[ u ][ p ] = parameter_src.clone();
  12037. } else if ( Array.isArray( parameter_src ) ) {
  12038. uniforms_dst[ u ][ p ] = parameter_src.slice();
  12039. } else {
  12040. uniforms_dst[ u ][ p ] = parameter_src;
  12041. }
  12042. }
  12043. }
  12044. return uniforms_dst;
  12045. }
  12046. };
  12047. // File:src/renderers/shaders/UniformsLib.js
  12048. /**
  12049. * Uniforms library for shared webgl shaders
  12050. */
  12051. THREE.UniformsLib = {
  12052. common: {
  12053. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  12054. "opacity" : { type: "f", value: 1.0 },
  12055. "map" : { type: "t", value: null },
  12056. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  12057. "specularMap" : { type: "t", value: null },
  12058. "alphaMap" : { type: "t", value: null },
  12059. "envMap" : { type: "t", value: null },
  12060. "flipEnvMap" : { type: "f", value: - 1 },
  12061. "reflectivity" : { type: "f", value: 1.0 },
  12062. "refractionRatio" : { type: "f", value: 0.98 }
  12063. },
  12064. aomap: {
  12065. "aoMap" : { type: "t", value: null },
  12066. "aoMapIntensity" : { type: "f", value: 1 },
  12067. },
  12068. lightmap: {
  12069. "lightMap" : { type: "t", value: null },
  12070. "lightMapIntensity" : { type: "f", value: 1 },
  12071. },
  12072. emissivemap: {
  12073. "emissiveMap" : { type: "t", value: null },
  12074. },
  12075. bumpmap: {
  12076. "bumpMap" : { type: "t", value: null },
  12077. "bumpScale" : { type: "f", value: 1 }
  12078. },
  12079. normalmap: {
  12080. "normalMap" : { type: "t", value: null },
  12081. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  12082. },
  12083. displacementmap: {
  12084. "displacementMap" : { type: "t", value: null },
  12085. "displacementScale" : { type: "f", value: 1 },
  12086. "displacementBias" : { type: "f", value: 0 }
  12087. },
  12088. fog : {
  12089. "fogDensity" : { type: "f", value: 0.00025 },
  12090. "fogNear" : { type: "f", value: 1 },
  12091. "fogFar" : { type: "f", value: 2000 },
  12092. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  12093. },
  12094. lights: {
  12095. "ambientLightColor" : { type: "fv", value: [] },
  12096. "directionalLightDirection" : { type: "fv", value: [] },
  12097. "directionalLightColor" : { type: "fv", value: [] },
  12098. "hemisphereLightDirection" : { type: "fv", value: [] },
  12099. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  12100. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  12101. "pointLightColor" : { type: "fv", value: [] },
  12102. "pointLightPosition" : { type: "fv", value: [] },
  12103. "pointLightDistance" : { type: "fv1", value: [] },
  12104. "pointLightDecay" : { type: "fv1", value: [] },
  12105. "spotLightColor" : { type: "fv", value: [] },
  12106. "spotLightPosition" : { type: "fv", value: [] },
  12107. "spotLightDirection" : { type: "fv", value: [] },
  12108. "spotLightDistance" : { type: "fv1", value: [] },
  12109. "spotLightAngleCos" : { type: "fv1", value: [] },
  12110. "spotLightExponent" : { type: "fv1", value: [] },
  12111. "spotLightDecay" : { type: "fv1", value: [] }
  12112. },
  12113. points: {
  12114. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  12115. "opacity" : { type: "f", value: 1.0 },
  12116. "size" : { type: "f", value: 1.0 },
  12117. "scale" : { type: "f", value: 1.0 },
  12118. "map" : { type: "t", value: null },
  12119. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  12120. "fogDensity" : { type: "f", value: 0.00025 },
  12121. "fogNear" : { type: "f", value: 1 },
  12122. "fogFar" : { type: "f", value: 2000 },
  12123. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  12124. },
  12125. shadowmap: {
  12126. "shadowMap": { type: "tv", value: [] },
  12127. "shadowMapSize": { type: "v2v", value: [] },
  12128. "shadowBias" : { type: "fv1", value: [] },
  12129. "shadowDarkness": { type: "fv1", value: [] },
  12130. "shadowMatrix" : { type: "m4v", value: [] }
  12131. }
  12132. };
  12133. // File:src/renderers/shaders/ShaderLib.js
  12134. /**
  12135. * Webgl Shader Library for three.js
  12136. *
  12137. * @author alteredq / http://alteredqualia.com/
  12138. * @author mrdoob / http://mrdoob.com/
  12139. * @author mikael emtinger / http://gomo.se/
  12140. */
  12141. THREE.ShaderLib = {
  12142. 'basic': {
  12143. uniforms: THREE.UniformsUtils.merge( [
  12144. THREE.UniformsLib[ "common" ],
  12145. THREE.UniformsLib[ "aomap" ],
  12146. THREE.UniformsLib[ "fog" ],
  12147. THREE.UniformsLib[ "shadowmap" ]
  12148. ] ),
  12149. vertexShader: [
  12150. THREE.ShaderChunk[ "common" ],
  12151. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12152. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12153. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12154. THREE.ShaderChunk[ "color_pars_vertex" ],
  12155. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12156. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12157. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12158. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12159. "void main() {",
  12160. THREE.ShaderChunk[ "uv_vertex" ],
  12161. THREE.ShaderChunk[ "uv2_vertex" ],
  12162. THREE.ShaderChunk[ "color_vertex" ],
  12163. THREE.ShaderChunk[ "skinbase_vertex" ],
  12164. " #ifdef USE_ENVMAP",
  12165. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12166. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12167. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12168. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12169. " #endif",
  12170. THREE.ShaderChunk[ "begin_vertex" ],
  12171. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12172. THREE.ShaderChunk[ "skinning_vertex" ],
  12173. THREE.ShaderChunk[ "project_vertex" ],
  12174. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12175. THREE.ShaderChunk[ "worldpos_vertex" ],
  12176. THREE.ShaderChunk[ "envmap_vertex" ],
  12177. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12178. "}"
  12179. ].join( "\n" ),
  12180. fragmentShader: [
  12181. "uniform vec3 diffuse;",
  12182. "uniform float opacity;",
  12183. THREE.ShaderChunk[ "common" ],
  12184. THREE.ShaderChunk[ "color_pars_fragment" ],
  12185. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12186. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12187. THREE.ShaderChunk[ "map_pars_fragment" ],
  12188. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12189. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  12190. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12191. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12192. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12193. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12194. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12195. "void main() {",
  12196. " vec3 outgoingLight = vec3( 0.0 );",
  12197. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12198. " vec3 totalAmbientLight = vec3( 1.0 );", // hardwired
  12199. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12200. THREE.ShaderChunk[ "map_fragment" ],
  12201. THREE.ShaderChunk[ "color_fragment" ],
  12202. THREE.ShaderChunk[ "alphamap_fragment" ],
  12203. THREE.ShaderChunk[ "alphatest_fragment" ],
  12204. THREE.ShaderChunk[ "specularmap_fragment" ],
  12205. THREE.ShaderChunk[ "aomap_fragment" ],
  12206. " outgoingLight = diffuseColor.rgb * totalAmbientLight;", // simple shader
  12207. THREE.ShaderChunk[ "envmap_fragment" ],
  12208. THREE.ShaderChunk[ "shadowmap_fragment" ], // TODO: Shadows on an otherwise unlit surface doesn't make sense.
  12209. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12210. THREE.ShaderChunk[ "fog_fragment" ],
  12211. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12212. "}"
  12213. ].join( "\n" )
  12214. },
  12215. 'lambert': {
  12216. uniforms: THREE.UniformsUtils.merge( [
  12217. THREE.UniformsLib[ "common" ],
  12218. THREE.UniformsLib[ "fog" ],
  12219. THREE.UniformsLib[ "lights" ],
  12220. THREE.UniformsLib[ "shadowmap" ],
  12221. {
  12222. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  12223. }
  12224. ] ),
  12225. vertexShader: [
  12226. "#define LAMBERT",
  12227. "varying vec3 vLightFront;",
  12228. "#ifdef DOUBLE_SIDED",
  12229. " varying vec3 vLightBack;",
  12230. "#endif",
  12231. THREE.ShaderChunk[ "common" ],
  12232. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12233. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12234. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12235. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  12236. THREE.ShaderChunk[ "color_pars_vertex" ],
  12237. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12238. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12239. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12240. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12241. "void main() {",
  12242. THREE.ShaderChunk[ "uv_vertex" ],
  12243. THREE.ShaderChunk[ "uv2_vertex" ],
  12244. THREE.ShaderChunk[ "color_vertex" ],
  12245. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12246. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12247. THREE.ShaderChunk[ "skinbase_vertex" ],
  12248. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12249. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12250. THREE.ShaderChunk[ "begin_vertex" ],
  12251. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12252. THREE.ShaderChunk[ "skinning_vertex" ],
  12253. THREE.ShaderChunk[ "project_vertex" ],
  12254. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12255. THREE.ShaderChunk[ "worldpos_vertex" ],
  12256. THREE.ShaderChunk[ "envmap_vertex" ],
  12257. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  12258. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12259. "}"
  12260. ].join( "\n" ),
  12261. fragmentShader: [
  12262. "uniform vec3 diffuse;",
  12263. "uniform vec3 emissive;",
  12264. "uniform float opacity;",
  12265. "varying vec3 vLightFront;",
  12266. "#ifdef DOUBLE_SIDED",
  12267. " varying vec3 vLightBack;",
  12268. "#endif",
  12269. THREE.ShaderChunk[ "common" ],
  12270. THREE.ShaderChunk[ "color_pars_fragment" ],
  12271. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12272. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12273. THREE.ShaderChunk[ "map_pars_fragment" ],
  12274. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12275. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12276. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12277. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12278. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12279. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12280. "void main() {",
  12281. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  12282. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12283. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12284. THREE.ShaderChunk[ "map_fragment" ],
  12285. THREE.ShaderChunk[ "color_fragment" ],
  12286. THREE.ShaderChunk[ "alphamap_fragment" ],
  12287. THREE.ShaderChunk[ "alphatest_fragment" ],
  12288. THREE.ShaderChunk[ "specularmap_fragment" ],
  12289. " #ifdef DOUBLE_SIDED",
  12290. " if ( gl_FrontFacing )",
  12291. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  12292. " else",
  12293. " outgoingLight += diffuseColor.rgb * vLightBack + emissive;",
  12294. " #else",
  12295. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  12296. " #endif",
  12297. THREE.ShaderChunk[ "envmap_fragment" ],
  12298. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12299. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12300. THREE.ShaderChunk[ "fog_fragment" ],
  12301. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12302. "}"
  12303. ].join( "\n" )
  12304. },
  12305. 'phong': {
  12306. uniforms: THREE.UniformsUtils.merge( [
  12307. THREE.UniformsLib[ "common" ],
  12308. THREE.UniformsLib[ "aomap" ],
  12309. THREE.UniformsLib[ "lightmap" ],
  12310. THREE.UniformsLib[ "emissivemap" ],
  12311. THREE.UniformsLib[ "bumpmap" ],
  12312. THREE.UniformsLib[ "normalmap" ],
  12313. THREE.UniformsLib[ "displacementmap" ],
  12314. THREE.UniformsLib[ "fog" ],
  12315. THREE.UniformsLib[ "lights" ],
  12316. THREE.UniformsLib[ "shadowmap" ],
  12317. {
  12318. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  12319. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  12320. "shininess": { type: "f", value: 30 }
  12321. }
  12322. ] ),
  12323. vertexShader: [
  12324. "#define PHONG",
  12325. "varying vec3 vViewPosition;",
  12326. "#ifndef FLAT_SHADED",
  12327. " varying vec3 vNormal;",
  12328. "#endif",
  12329. THREE.ShaderChunk[ "common" ],
  12330. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12331. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12332. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  12333. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12334. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  12335. THREE.ShaderChunk[ "color_pars_vertex" ],
  12336. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12337. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12338. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12339. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12340. "void main() {",
  12341. THREE.ShaderChunk[ "uv_vertex" ],
  12342. THREE.ShaderChunk[ "uv2_vertex" ],
  12343. THREE.ShaderChunk[ "color_vertex" ],
  12344. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12345. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12346. THREE.ShaderChunk[ "skinbase_vertex" ],
  12347. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12348. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12349. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  12350. " vNormal = normalize( transformedNormal );",
  12351. "#endif",
  12352. THREE.ShaderChunk[ "begin_vertex" ],
  12353. THREE.ShaderChunk[ "displacementmap_vertex" ],
  12354. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12355. THREE.ShaderChunk[ "skinning_vertex" ],
  12356. THREE.ShaderChunk[ "project_vertex" ],
  12357. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12358. " vViewPosition = - mvPosition.xyz;",
  12359. THREE.ShaderChunk[ "worldpos_vertex" ],
  12360. THREE.ShaderChunk[ "envmap_vertex" ],
  12361. THREE.ShaderChunk[ "lights_phong_vertex" ],
  12362. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12363. "}"
  12364. ].join( "\n" ),
  12365. fragmentShader: [
  12366. "#define PHONG",
  12367. "uniform vec3 diffuse;",
  12368. "uniform vec3 emissive;",
  12369. "uniform vec3 specular;",
  12370. "uniform float shininess;",
  12371. "uniform float opacity;",
  12372. THREE.ShaderChunk[ "common" ],
  12373. THREE.ShaderChunk[ "color_pars_fragment" ],
  12374. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12375. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12376. THREE.ShaderChunk[ "map_pars_fragment" ],
  12377. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12378. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  12379. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  12380. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  12381. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12382. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12383. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  12384. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12385. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  12386. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  12387. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12388. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12389. "void main() {",
  12390. " vec3 outgoingLight = vec3( 0.0 );",
  12391. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12392. " vec3 totalAmbientLight = ambientLightColor;",
  12393. " vec3 totalEmissiveLight = emissive;",
  12394. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12395. THREE.ShaderChunk[ "map_fragment" ],
  12396. THREE.ShaderChunk[ "color_fragment" ],
  12397. THREE.ShaderChunk[ "alphamap_fragment" ],
  12398. THREE.ShaderChunk[ "alphatest_fragment" ],
  12399. THREE.ShaderChunk[ "specularmap_fragment" ],
  12400. THREE.ShaderChunk[ "normal_phong_fragment" ],
  12401. THREE.ShaderChunk[ "lightmap_fragment" ],
  12402. THREE.ShaderChunk[ "hemilight_fragment" ],
  12403. THREE.ShaderChunk[ "aomap_fragment" ],
  12404. THREE.ShaderChunk[ "emissivemap_fragment" ],
  12405. THREE.ShaderChunk[ "lights_phong_fragment" ],
  12406. THREE.ShaderChunk[ "envmap_fragment" ],
  12407. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12408. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12409. THREE.ShaderChunk[ "fog_fragment" ],
  12410. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12411. "}"
  12412. ].join( "\n" )
  12413. },
  12414. 'points': {
  12415. uniforms: THREE.UniformsUtils.merge( [
  12416. THREE.UniformsLib[ "points" ],
  12417. THREE.UniformsLib[ "shadowmap" ]
  12418. ] ),
  12419. vertexShader: [
  12420. "uniform float size;",
  12421. "uniform float scale;",
  12422. THREE.ShaderChunk[ "common" ],
  12423. THREE.ShaderChunk[ "color_pars_vertex" ],
  12424. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12425. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12426. "void main() {",
  12427. THREE.ShaderChunk[ "color_vertex" ],
  12428. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  12429. " #ifdef USE_SIZEATTENUATION",
  12430. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  12431. " #else",
  12432. " gl_PointSize = size;",
  12433. " #endif",
  12434. " gl_Position = projectionMatrix * mvPosition;",
  12435. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12436. THREE.ShaderChunk[ "worldpos_vertex" ],
  12437. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12438. "}"
  12439. ].join( "\n" ),
  12440. fragmentShader: [
  12441. "uniform vec3 psColor;",
  12442. "uniform float opacity;",
  12443. THREE.ShaderChunk[ "common" ],
  12444. THREE.ShaderChunk[ "color_pars_fragment" ],
  12445. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  12446. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12447. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12448. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12449. "void main() {",
  12450. " vec3 outgoingLight = vec3( 0.0 );",
  12451. " vec4 diffuseColor = vec4( psColor, opacity );",
  12452. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12453. THREE.ShaderChunk[ "map_particle_fragment" ],
  12454. THREE.ShaderChunk[ "color_fragment" ],
  12455. THREE.ShaderChunk[ "alphatest_fragment" ],
  12456. " outgoingLight = diffuseColor.rgb;", // simple shader
  12457. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12458. THREE.ShaderChunk[ "fog_fragment" ],
  12459. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12460. "}"
  12461. ].join( "\n" )
  12462. },
  12463. 'dashed': {
  12464. uniforms: THREE.UniformsUtils.merge( [
  12465. THREE.UniformsLib[ "common" ],
  12466. THREE.UniformsLib[ "fog" ],
  12467. {
  12468. "scale" : { type: "f", value: 1 },
  12469. "dashSize" : { type: "f", value: 1 },
  12470. "totalSize": { type: "f", value: 2 }
  12471. }
  12472. ] ),
  12473. vertexShader: [
  12474. "uniform float scale;",
  12475. "attribute float lineDistance;",
  12476. "varying float vLineDistance;",
  12477. THREE.ShaderChunk[ "common" ],
  12478. THREE.ShaderChunk[ "color_pars_vertex" ],
  12479. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12480. "void main() {",
  12481. THREE.ShaderChunk[ "color_vertex" ],
  12482. " vLineDistance = scale * lineDistance;",
  12483. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  12484. " gl_Position = projectionMatrix * mvPosition;",
  12485. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12486. "}"
  12487. ].join( "\n" ),
  12488. fragmentShader: [
  12489. "uniform vec3 diffuse;",
  12490. "uniform float opacity;",
  12491. "uniform float dashSize;",
  12492. "uniform float totalSize;",
  12493. "varying float vLineDistance;",
  12494. THREE.ShaderChunk[ "common" ],
  12495. THREE.ShaderChunk[ "color_pars_fragment" ],
  12496. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12497. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12498. "void main() {",
  12499. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  12500. " discard;",
  12501. " }",
  12502. " vec3 outgoingLight = vec3( 0.0 );",
  12503. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12504. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12505. THREE.ShaderChunk[ "color_fragment" ],
  12506. " outgoingLight = diffuseColor.rgb;", // simple shader
  12507. THREE.ShaderChunk[ "fog_fragment" ],
  12508. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12509. "}"
  12510. ].join( "\n" )
  12511. },
  12512. 'depth': {
  12513. uniforms: {
  12514. "mNear": { type: "f", value: 1.0 },
  12515. "mFar" : { type: "f", value: 2000.0 },
  12516. "opacity" : { type: "f", value: 1.0 }
  12517. },
  12518. vertexShader: [
  12519. THREE.ShaderChunk[ "common" ],
  12520. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12521. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12522. "void main() {",
  12523. THREE.ShaderChunk[ "begin_vertex" ],
  12524. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12525. THREE.ShaderChunk[ "project_vertex" ],
  12526. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12527. "}"
  12528. ].join( "\n" ),
  12529. fragmentShader: [
  12530. "uniform float mNear;",
  12531. "uniform float mFar;",
  12532. "uniform float opacity;",
  12533. THREE.ShaderChunk[ "common" ],
  12534. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12535. "void main() {",
  12536. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12537. " #ifdef USE_LOGDEPTHBUF_EXT",
  12538. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  12539. " #else",
  12540. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  12541. " #endif",
  12542. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  12543. " gl_FragColor = vec4( vec3( color ), opacity );",
  12544. "}"
  12545. ].join( "\n" )
  12546. },
  12547. 'normal': {
  12548. uniforms: {
  12549. "opacity" : { type: "f", value: 1.0 }
  12550. },
  12551. vertexShader: [
  12552. "varying vec3 vNormal;",
  12553. THREE.ShaderChunk[ "common" ],
  12554. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12555. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12556. "void main() {",
  12557. " vNormal = normalize( normalMatrix * normal );",
  12558. THREE.ShaderChunk[ "begin_vertex" ],
  12559. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12560. THREE.ShaderChunk[ "project_vertex" ],
  12561. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12562. "}"
  12563. ].join( "\n" ),
  12564. fragmentShader: [
  12565. "uniform float opacity;",
  12566. "varying vec3 vNormal;",
  12567. THREE.ShaderChunk[ "common" ],
  12568. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12569. "void main() {",
  12570. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  12571. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12572. "}"
  12573. ].join( "\n" )
  12574. },
  12575. /* -------------------------------------------------------------------------
  12576. // Cube map shader
  12577. ------------------------------------------------------------------------- */
  12578. 'cube': {
  12579. uniforms: { "tCube": { type: "t", value: null },
  12580. "tFlip": { type: "f", value: - 1 } },
  12581. vertexShader: [
  12582. "varying vec3 vWorldPosition;",
  12583. THREE.ShaderChunk[ "common" ],
  12584. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12585. "void main() {",
  12586. " vWorldPosition = transformDirection( position, modelMatrix );",
  12587. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  12588. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12589. "}"
  12590. ].join( "\n" ),
  12591. fragmentShader: [
  12592. "uniform samplerCube tCube;",
  12593. "uniform float tFlip;",
  12594. "varying vec3 vWorldPosition;",
  12595. THREE.ShaderChunk[ "common" ],
  12596. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12597. "void main() {",
  12598. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  12599. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12600. "}"
  12601. ].join( "\n" )
  12602. },
  12603. /* -------------------------------------------------------------------------
  12604. // Cube map shader
  12605. ------------------------------------------------------------------------- */
  12606. 'equirect': {
  12607. uniforms: { "tEquirect": { type: "t", value: null },
  12608. "tFlip": { type: "f", value: - 1 } },
  12609. vertexShader: [
  12610. "varying vec3 vWorldPosition;",
  12611. THREE.ShaderChunk[ "common" ],
  12612. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12613. "void main() {",
  12614. " vWorldPosition = transformDirection( position, modelMatrix );",
  12615. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  12616. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12617. "}"
  12618. ].join( "\n" ),
  12619. fragmentShader: [
  12620. "uniform sampler2D tEquirect;",
  12621. "uniform float tFlip;",
  12622. "varying vec3 vWorldPosition;",
  12623. THREE.ShaderChunk[ "common" ],
  12624. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12625. "void main() {",
  12626. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  12627. "vec3 direction = normalize( vWorldPosition );",
  12628. "vec2 sampleUV;",
  12629. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  12630. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  12631. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  12632. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12633. "}"
  12634. ].join( "\n" )
  12635. },
  12636. /* Depth encoding into RGBA texture
  12637. *
  12638. * based on SpiderGL shadow map example
  12639. * http://spidergl.org/example.php?id=6
  12640. *
  12641. * originally from
  12642. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  12643. *
  12644. * see also
  12645. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  12646. */
  12647. 'depthRGBA': {
  12648. uniforms: {},
  12649. vertexShader: [
  12650. THREE.ShaderChunk[ "common" ],
  12651. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12652. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12653. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12654. "void main() {",
  12655. THREE.ShaderChunk[ "skinbase_vertex" ],
  12656. THREE.ShaderChunk[ "begin_vertex" ],
  12657. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12658. THREE.ShaderChunk[ "skinning_vertex" ],
  12659. THREE.ShaderChunk[ "project_vertex" ],
  12660. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12661. "}"
  12662. ].join( "\n" ),
  12663. fragmentShader: [
  12664. THREE.ShaderChunk[ "common" ],
  12665. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12666. "vec4 pack_depth( const in float depth ) {",
  12667. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  12668. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  12669. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  12670. " res -= res.xxyz * bit_mask;",
  12671. " return res;",
  12672. "}",
  12673. "void main() {",
  12674. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12675. " #ifdef USE_LOGDEPTHBUF_EXT",
  12676. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  12677. " #else",
  12678. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  12679. " #endif",
  12680. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  12681. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  12682. //"gl_FragData[ 0 ] = pack_depth( z );",
  12683. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  12684. "}"
  12685. ].join( "\n" )
  12686. },
  12687. 'distanceRGBA': {
  12688. uniforms: {
  12689. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  12690. },
  12691. vertexShader: [
  12692. "varying vec4 vWorldPosition;",
  12693. THREE.ShaderChunk[ "common" ],
  12694. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12695. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12696. "void main() {",
  12697. THREE.ShaderChunk[ "skinbase_vertex" ],
  12698. THREE.ShaderChunk[ "begin_vertex" ],
  12699. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12700. THREE.ShaderChunk[ "skinning_vertex" ],
  12701. THREE.ShaderChunk[ "project_vertex" ],
  12702. THREE.ShaderChunk[ "worldpos_vertex" ],
  12703. "vWorldPosition = worldPosition;",
  12704. "}"
  12705. ].join( "\n" ),
  12706. fragmentShader: [
  12707. "uniform vec3 lightPos;",
  12708. "varying vec4 vWorldPosition;",
  12709. THREE.ShaderChunk[ "common" ],
  12710. "vec4 pack1K ( float depth ) {",
  12711. " depth /= 1000.0;",
  12712. " const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  12713. " const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  12714. " vec4 res = fract( depth * bitSh );",
  12715. " res -= res.xxyz * bitMsk;",
  12716. " return res; ",
  12717. "}",
  12718. "float unpack1K ( vec4 color ) {",
  12719. " const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  12720. " return dot( color, bitSh ) * 1000.0;",
  12721. "}",
  12722. "void main () {",
  12723. " gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",
  12724. "}"
  12725. ].join( "\n" )
  12726. }
  12727. };
  12728. // File:src/renderers/WebGLRenderer.js
  12729. /**
  12730. * @author supereggbert / http://www.paulbrunt.co.uk/
  12731. * @author mrdoob / http://mrdoob.com/
  12732. * @author alteredq / http://alteredqualia.com/
  12733. * @author szimek / https://github.com/szimek/
  12734. */
  12735. THREE.WebGLRenderer = function ( parameters ) {
  12736. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  12737. parameters = parameters || {};
  12738. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  12739. _context = parameters.context !== undefined ? parameters.context : null,
  12740. _width = _canvas.width,
  12741. _height = _canvas.height,
  12742. pixelRatio = 1,
  12743. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  12744. _depth = parameters.depth !== undefined ? parameters.depth : true,
  12745. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  12746. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  12747. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  12748. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  12749. _clearColor = new THREE.Color( 0x000000 ),
  12750. _clearAlpha = 0;
  12751. var lights = [];
  12752. var opaqueObjects = [];
  12753. var opaqueObjectsLastIndex = -1;
  12754. var transparentObjects = [];
  12755. var transparentObjectsLastIndex = -1;
  12756. var morphInfluences = new Float32Array( 8 );
  12757. var sprites = [];
  12758. var lensFlares = [];
  12759. // public properties
  12760. this.domElement = _canvas;
  12761. this.context = null;
  12762. // clearing
  12763. this.autoClear = true;
  12764. this.autoClearColor = true;
  12765. this.autoClearDepth = true;
  12766. this.autoClearStencil = true;
  12767. // scene graph
  12768. this.sortObjects = true;
  12769. // physically based shading
  12770. this.gammaFactor = 2.0; // for backwards compatibility
  12771. this.gammaInput = false;
  12772. this.gammaOutput = false;
  12773. // morphs
  12774. this.maxMorphTargets = 8;
  12775. this.maxMorphNormals = 4;
  12776. // flags
  12777. this.autoScaleCubemaps = true;
  12778. // internal properties
  12779. var _this = this,
  12780. // internal state cache
  12781. _currentProgram = null,
  12782. _currentFramebuffer = null,
  12783. _currentMaterialId = - 1,
  12784. _currentGeometryProgram = '',
  12785. _currentCamera = null,
  12786. _usedTextureUnits = 0,
  12787. _viewportX = 0,
  12788. _viewportY = 0,
  12789. _viewportWidth = _canvas.width,
  12790. _viewportHeight = _canvas.height,
  12791. _currentWidth = 0,
  12792. _currentHeight = 0,
  12793. // frustum
  12794. _frustum = new THREE.Frustum(),
  12795. // camera matrices cache
  12796. _projScreenMatrix = new THREE.Matrix4(),
  12797. _vector3 = new THREE.Vector3(),
  12798. // light arrays cache
  12799. _direction = new THREE.Vector3(),
  12800. _lightsNeedUpdate = true,
  12801. _lights = {
  12802. ambient: [ 0, 0, 0 ],
  12803. directional: { length: 0, colors: [], positions: [] },
  12804. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  12805. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  12806. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  12807. },
  12808. // info
  12809. _infoMemory = {
  12810. geometries: 0,
  12811. textures: 0
  12812. },
  12813. _infoRender = {
  12814. calls: 0,
  12815. vertices: 0,
  12816. faces: 0,
  12817. points: 0
  12818. };
  12819. this.info = {
  12820. render: _infoRender,
  12821. memory: _infoMemory,
  12822. programs: null
  12823. };
  12824. // initialize
  12825. var _gl;
  12826. try {
  12827. var attributes = {
  12828. alpha: _alpha,
  12829. depth: _depth,
  12830. stencil: _stencil,
  12831. antialias: _antialias,
  12832. premultipliedAlpha: _premultipliedAlpha,
  12833. preserveDrawingBuffer: _preserveDrawingBuffer
  12834. };
  12835. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  12836. if ( _gl === null ) {
  12837. if ( _canvas.getContext( 'webgl' ) !== null ) {
  12838. throw 'Error creating WebGL context with your selected attributes.';
  12839. } else {
  12840. throw 'Error creating WebGL context.';
  12841. }
  12842. }
  12843. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  12844. } catch ( error ) {
  12845. console.error( 'THREE.WebGLRenderer: ' + error );
  12846. }
  12847. var extensions = new THREE.WebGLExtensions( _gl );
  12848. extensions.get( 'OES_texture_float' );
  12849. extensions.get( 'OES_texture_float_linear' );
  12850. extensions.get( 'OES_texture_half_float' );
  12851. extensions.get( 'OES_texture_half_float_linear' );
  12852. extensions.get( 'OES_standard_derivatives' );
  12853. extensions.get( 'ANGLE_instanced_arrays' );
  12854. if ( extensions.get( 'OES_element_index_uint' ) ) {
  12855. THREE.BufferGeometry.MaxIndex = 4294967296;
  12856. }
  12857. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  12858. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  12859. var properties = new THREE.WebGLProperties();
  12860. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  12861. var programCache = new THREE.WebGLPrograms( this, capabilities );
  12862. this.info.programs = programCache.programs;
  12863. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  12864. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  12865. //
  12866. function glClearColor( r, g, b, a ) {
  12867. if ( _premultipliedAlpha === true ) {
  12868. r *= a; g *= a; b *= a;
  12869. }
  12870. _gl.clearColor( r, g, b, a );
  12871. }
  12872. function setDefaultGLState() {
  12873. state.init();
  12874. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  12875. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12876. }
  12877. function resetGLState() {
  12878. _currentProgram = null;
  12879. _currentCamera = null;
  12880. _currentGeometryProgram = '';
  12881. _currentMaterialId = - 1;
  12882. _lightsNeedUpdate = true;
  12883. state.reset();
  12884. }
  12885. setDefaultGLState();
  12886. this.context = _gl;
  12887. this.capabilities = capabilities;
  12888. this.extensions = extensions;
  12889. this.state = state;
  12890. // shadow map
  12891. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  12892. this.shadowMap = shadowMap;
  12893. // Plugins
  12894. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  12895. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  12896. // API
  12897. this.getContext = function () {
  12898. return _gl;
  12899. };
  12900. this.getContextAttributes = function () {
  12901. return _gl.getContextAttributes();
  12902. };
  12903. this.forceContextLoss = function () {
  12904. extensions.get( 'WEBGL_lose_context' ).loseContext();
  12905. };
  12906. this.getMaxAnisotropy = ( function () {
  12907. var value;
  12908. return function getMaxAnisotropy() {
  12909. if ( value !== undefined ) return value;
  12910. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12911. if ( extension !== null ) {
  12912. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  12913. } else {
  12914. value = 0;
  12915. }
  12916. return value;
  12917. }
  12918. } )();
  12919. this.getPrecision = function () {
  12920. return capabilities.precision;
  12921. };
  12922. this.getPixelRatio = function () {
  12923. return pixelRatio;
  12924. };
  12925. this.setPixelRatio = function ( value ) {
  12926. if ( value !== undefined ) pixelRatio = value;
  12927. };
  12928. this.getSize = function () {
  12929. return {
  12930. width: _width,
  12931. height: _height
  12932. };
  12933. };
  12934. this.setSize = function ( width, height, updateStyle ) {
  12935. _width = width;
  12936. _height = height;
  12937. _canvas.width = width * pixelRatio;
  12938. _canvas.height = height * pixelRatio;
  12939. if ( updateStyle !== false ) {
  12940. _canvas.style.width = width + 'px';
  12941. _canvas.style.height = height + 'px';
  12942. }
  12943. this.setViewport( 0, 0, width, height );
  12944. };
  12945. this.setViewport = function ( x, y, width, height ) {
  12946. _viewportX = x * pixelRatio;
  12947. _viewportY = y * pixelRatio;
  12948. _viewportWidth = width * pixelRatio;
  12949. _viewportHeight = height * pixelRatio;
  12950. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  12951. };
  12952. this.getViewport = function ( dimensions ) {
  12953. dimensions.x = _viewportX;
  12954. dimensions.y = _viewportY;
  12955. dimensions.z = _viewportWidth;
  12956. dimensions.w = _viewportHeight;
  12957. };
  12958. this.setScissor = function ( x, y, width, height ) {
  12959. _gl.scissor(
  12960. x * pixelRatio,
  12961. y * pixelRatio,
  12962. width * pixelRatio,
  12963. height * pixelRatio
  12964. );
  12965. };
  12966. this.enableScissorTest = function ( boolean ) {
  12967. state.setScissorTest( boolean );
  12968. };
  12969. // Clearing
  12970. this.getClearColor = function () {
  12971. return _clearColor;
  12972. };
  12973. this.setClearColor = function ( color, alpha ) {
  12974. _clearColor.set( color );
  12975. _clearAlpha = alpha !== undefined ? alpha : 1;
  12976. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12977. };
  12978. this.getClearAlpha = function () {
  12979. return _clearAlpha;
  12980. };
  12981. this.setClearAlpha = function ( alpha ) {
  12982. _clearAlpha = alpha;
  12983. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12984. };
  12985. this.clear = function ( color, depth, stencil ) {
  12986. var bits = 0;
  12987. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  12988. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  12989. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  12990. _gl.clear( bits );
  12991. };
  12992. this.clearColor = function () {
  12993. _gl.clear( _gl.COLOR_BUFFER_BIT );
  12994. };
  12995. this.clearDepth = function () {
  12996. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  12997. };
  12998. this.clearStencil = function () {
  12999. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  13000. };
  13001. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  13002. this.setRenderTarget( renderTarget );
  13003. this.clear( color, depth, stencil );
  13004. };
  13005. // Reset
  13006. this.resetGLState = resetGLState;
  13007. this.dispose = function() {
  13008. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  13009. };
  13010. // Events
  13011. function onContextLost( event ) {
  13012. event.preventDefault();
  13013. resetGLState();
  13014. setDefaultGLState();
  13015. properties.clear();
  13016. };
  13017. function onTextureDispose( event ) {
  13018. var texture = event.target;
  13019. texture.removeEventListener( 'dispose', onTextureDispose );
  13020. deallocateTexture( texture );
  13021. _infoMemory.textures --;
  13022. }
  13023. function onRenderTargetDispose( event ) {
  13024. var renderTarget = event.target;
  13025. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  13026. deallocateRenderTarget( renderTarget );
  13027. _infoMemory.textures --;
  13028. }
  13029. function onMaterialDispose( event ) {
  13030. var material = event.target;
  13031. material.removeEventListener( 'dispose', onMaterialDispose );
  13032. deallocateMaterial( material );
  13033. }
  13034. // Buffer deallocation
  13035. function deallocateTexture( texture ) {
  13036. var textureProperties = properties.get( texture );
  13037. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  13038. // cube texture
  13039. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  13040. } else {
  13041. // 2D texture
  13042. if ( textureProperties.__webglInit === undefined ) return;
  13043. _gl.deleteTexture( textureProperties.__webglTexture );
  13044. }
  13045. // remove all webgl properties
  13046. properties.delete( texture );
  13047. }
  13048. function deallocateRenderTarget( renderTarget ) {
  13049. var renderTargetProperties = properties.get( renderTarget );
  13050. if ( ! renderTarget || renderTargetProperties.__webglTexture === undefined ) return;
  13051. _gl.deleteTexture( renderTargetProperties.__webglTexture );
  13052. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  13053. for ( var i = 0; i < 6; i ++ ) {
  13054. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  13055. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  13056. }
  13057. } else {
  13058. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  13059. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  13060. }
  13061. properties.delete( renderTarget );
  13062. }
  13063. function deallocateMaterial( material ) {
  13064. releaseMaterialProgramReference( material );
  13065. properties.delete( material );
  13066. }
  13067. function releaseMaterialProgramReference( material ) {
  13068. var programInfo = properties.get( material ).program;
  13069. material.program = undefined;
  13070. if ( programInfo !== undefined ) {
  13071. programCache.releaseProgram( programInfo );
  13072. }
  13073. }
  13074. // Buffer rendering
  13075. this.renderBufferImmediate = function ( object, program, material ) {
  13076. state.initAttributes();
  13077. var buffers = properties.get( object );
  13078. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13079. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13080. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13081. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13082. var attributes = program.getAttributes();
  13083. if ( object.hasPositions ) {
  13084. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  13085. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  13086. state.enableAttribute( attributes.position );
  13087. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  13088. }
  13089. if ( object.hasNormals ) {
  13090. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  13091. if ( material.type !== 'MeshPhongMaterial' && material.shading === THREE.FlatShading ) {
  13092. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  13093. var array = object.normalArray;
  13094. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  13095. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  13096. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  13097. array[ i + 0 ] = nx;
  13098. array[ i + 1 ] = ny;
  13099. array[ i + 2 ] = nz;
  13100. array[ i + 3 ] = nx;
  13101. array[ i + 4 ] = ny;
  13102. array[ i + 5 ] = nz;
  13103. array[ i + 6 ] = nx;
  13104. array[ i + 7 ] = ny;
  13105. array[ i + 8 ] = nz;
  13106. }
  13107. }
  13108. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  13109. state.enableAttribute( attributes.normal );
  13110. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  13111. }
  13112. if ( object.hasUvs && material.map ) {
  13113. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  13114. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  13115. state.enableAttribute( attributes.uv );
  13116. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  13117. }
  13118. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  13119. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  13120. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  13121. state.enableAttribute( attributes.color );
  13122. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  13123. }
  13124. state.disableUnusedAttributes();
  13125. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  13126. object.count = 0;
  13127. };
  13128. this.renderBufferDirect = function ( camera, lights, fog, geometry, material, object, group ) {
  13129. setMaterial( material );
  13130. var program = setProgram( camera, lights, fog, material, object );
  13131. var updateBuffers = false;
  13132. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  13133. if ( geometryProgram !== _currentGeometryProgram ) {
  13134. _currentGeometryProgram = geometryProgram;
  13135. updateBuffers = true;
  13136. }
  13137. // morph targets
  13138. var morphTargetInfluences = object.morphTargetInfluences;
  13139. if ( morphTargetInfluences !== undefined ) {
  13140. var activeInfluences = [];
  13141. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  13142. var influence = morphTargetInfluences[ i ];
  13143. activeInfluences.push( [ influence, i ] );
  13144. }
  13145. activeInfluences.sort( numericalSort );
  13146. if ( activeInfluences.length > 8 ) {
  13147. activeInfluences.length = 8;
  13148. }
  13149. var morphAttributes = geometry.morphAttributes;
  13150. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  13151. var influence = activeInfluences[ i ];
  13152. morphInfluences[ i ] = influence[ 0 ];
  13153. if ( influence[ 0 ] !== 0 ) {
  13154. var index = influence[ 1 ];
  13155. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  13156. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  13157. } else {
  13158. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  13159. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  13160. }
  13161. }
  13162. var uniforms = program.getUniforms();
  13163. if ( uniforms.morphTargetInfluences !== null ) {
  13164. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  13165. }
  13166. updateBuffers = true;
  13167. }
  13168. //
  13169. var index = geometry.index;
  13170. var position = geometry.attributes.position;
  13171. if ( material.wireframe === true ) {
  13172. index = objects.getWireframeAttribute( geometry );
  13173. }
  13174. var renderer;
  13175. if ( index !== null ) {
  13176. renderer = indexedBufferRenderer;
  13177. renderer.setIndex( index );
  13178. } else {
  13179. renderer = bufferRenderer;
  13180. }
  13181. if ( updateBuffers ) {
  13182. setupVertexAttributes( material, program, geometry );
  13183. if ( index !== null ) {
  13184. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  13185. }
  13186. }
  13187. if ( group === null ) {
  13188. var count;
  13189. if ( index !== null ) {
  13190. count = index.array.length;
  13191. } else {
  13192. count = position.count;
  13193. }
  13194. var drawRange = geometry.drawRange;
  13195. group = {
  13196. start: drawRange.start,
  13197. count: Math.min( drawRange.count, count )
  13198. };
  13199. }
  13200. if ( object instanceof THREE.Mesh ) {
  13201. if ( material.wireframe === true ) {
  13202. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  13203. renderer.setMode( _gl.LINES );
  13204. } else {
  13205. renderer.setMode( _gl.TRIANGLES );
  13206. }
  13207. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  13208. renderer.renderInstances( geometry );
  13209. } else {
  13210. renderer.render( group.start, group.count );
  13211. }
  13212. } else if ( object instanceof THREE.Line ) {
  13213. var lineWidth = material.linewidth;
  13214. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13215. state.setLineWidth( lineWidth * pixelRatio );
  13216. if ( object instanceof THREE.LineSegments ) {
  13217. renderer.setMode( _gl.LINES );
  13218. } else {
  13219. renderer.setMode( _gl.LINE_STRIP );
  13220. }
  13221. renderer.render( group.start, group.count );
  13222. } else if ( object instanceof THREE.Points ) {
  13223. renderer.setMode( _gl.POINTS );
  13224. renderer.render( group.start, group.count );
  13225. }
  13226. };
  13227. function setupVertexAttributes( material, program, geometry, startIndex ) {
  13228. var extension;
  13229. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  13230. extension = extensions.get( 'ANGLE_instanced_arrays' );
  13231. if ( extension === null ) {
  13232. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13233. return;
  13234. }
  13235. }
  13236. if ( startIndex === undefined ) startIndex = 0;
  13237. state.initAttributes();
  13238. var geometryAttributes = geometry.attributes;
  13239. var programAttributes = program.getAttributes();
  13240. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13241. for ( var name in programAttributes ) {
  13242. var programAttribute = programAttributes[ name ];
  13243. if ( programAttribute >= 0 ) {
  13244. var geometryAttribute = geometryAttributes[ name ];
  13245. if ( geometryAttribute !== undefined ) {
  13246. var size = geometryAttribute.itemSize;
  13247. var buffer = objects.getAttributeBuffer( geometryAttribute );
  13248. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  13249. var data = geometryAttribute.data;
  13250. var stride = data.stride;
  13251. var offset = geometryAttribute.offset;
  13252. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  13253. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  13254. if ( geometry.maxInstancedCount === undefined ) {
  13255. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13256. }
  13257. } else {
  13258. state.enableAttribute( programAttribute );
  13259. }
  13260. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13261. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  13262. } else {
  13263. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  13264. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  13265. if ( geometry.maxInstancedCount === undefined ) {
  13266. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  13267. }
  13268. } else {
  13269. state.enableAttribute( programAttribute );
  13270. }
  13271. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13272. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  13273. }
  13274. } else if ( materialDefaultAttributeValues !== undefined ) {
  13275. var value = materialDefaultAttributeValues[ name ];
  13276. if ( value !== undefined ) {
  13277. switch ( value.length ) {
  13278. case 2:
  13279. _gl.vertexAttrib2fv( programAttribute, value );
  13280. break;
  13281. case 3:
  13282. _gl.vertexAttrib3fv( programAttribute, value );
  13283. break;
  13284. case 4:
  13285. _gl.vertexAttrib4fv( programAttribute, value );
  13286. break;
  13287. default:
  13288. _gl.vertexAttrib1fv( programAttribute, value );
  13289. }
  13290. }
  13291. }
  13292. }
  13293. }
  13294. state.disableUnusedAttributes();
  13295. }
  13296. // Sorting
  13297. function numericalSort ( a, b ) {
  13298. return b[ 0 ] - a[ 0 ];
  13299. }
  13300. function painterSortStable ( a, b ) {
  13301. if ( a.object.renderOrder !== b.object.renderOrder ) {
  13302. return a.object.renderOrder - b.object.renderOrder;
  13303. } else if ( a.material.id !== b.material.id ) {
  13304. return a.material.id - b.material.id;
  13305. } else if ( a.z !== b.z ) {
  13306. return a.z - b.z;
  13307. } else {
  13308. return a.id - b.id;
  13309. }
  13310. }
  13311. function reversePainterSortStable ( a, b ) {
  13312. if ( a.object.renderOrder !== b.object.renderOrder ) {
  13313. return a.object.renderOrder - b.object.renderOrder;
  13314. } if ( a.z !== b.z ) {
  13315. return b.z - a.z;
  13316. } else {
  13317. return a.id - b.id;
  13318. }
  13319. }
  13320. // Rendering
  13321. this.render = function ( scene, camera, renderTarget, forceClear ) {
  13322. if ( camera instanceof THREE.Camera === false ) {
  13323. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13324. return;
  13325. }
  13326. var fog = scene.fog;
  13327. // reset caching for this frame
  13328. _currentGeometryProgram = '';
  13329. _currentMaterialId = - 1;
  13330. _currentCamera = null;
  13331. _lightsNeedUpdate = true;
  13332. // update scene graph
  13333. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13334. // update camera matrices and frustum
  13335. if ( camera.parent === null ) camera.updateMatrixWorld();
  13336. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13337. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13338. _frustum.setFromMatrix( _projScreenMatrix );
  13339. lights.length = 0;
  13340. opaqueObjectsLastIndex = -1;
  13341. transparentObjectsLastIndex = -1;
  13342. sprites.length = 0;
  13343. lensFlares.length = 0;
  13344. projectObject( scene );
  13345. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  13346. transparentObjects.length = transparentObjectsLastIndex + 1;
  13347. if ( _this.sortObjects === true ) {
  13348. opaqueObjects.sort( painterSortStable );
  13349. transparentObjects.sort( reversePainterSortStable );
  13350. }
  13351. //
  13352. shadowMap.render( scene );
  13353. //
  13354. _infoRender.calls = 0;
  13355. _infoRender.vertices = 0;
  13356. _infoRender.faces = 0;
  13357. _infoRender.points = 0;
  13358. this.setRenderTarget( renderTarget );
  13359. if ( this.autoClear || forceClear ) {
  13360. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  13361. }
  13362. //
  13363. if ( scene.overrideMaterial ) {
  13364. var overrideMaterial = scene.overrideMaterial;
  13365. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  13366. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  13367. } else {
  13368. // opaque pass (front-to-back order)
  13369. state.setBlending( THREE.NoBlending );
  13370. renderObjects( opaqueObjects, camera, lights, fog );
  13371. // transparent pass (back-to-front order)
  13372. renderObjects( transparentObjects, camera, lights, fog );
  13373. }
  13374. // custom render plugins (post pass)
  13375. spritePlugin.render( scene, camera );
  13376. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  13377. // Generate mipmap if we're using any kind of mipmap filtering
  13378. if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
  13379. updateRenderTargetMipmap( renderTarget );
  13380. }
  13381. // Ensure depth buffer writing is enabled so it can be cleared on next render
  13382. state.setDepthTest( true );
  13383. state.setDepthWrite( true );
  13384. state.setColorWrite( true );
  13385. // _gl.finish();
  13386. };
  13387. function pushRenderItem( object, geometry, material, z, group ) {
  13388. var array, index;
  13389. // allocate the next position in the appropriate array
  13390. if ( material.transparent ) {
  13391. array = transparentObjects;
  13392. index = ++ transparentObjectsLastIndex;
  13393. } else {
  13394. array = opaqueObjects;
  13395. index = ++ opaqueObjectsLastIndex;
  13396. }
  13397. // recycle existing render item or grow the array
  13398. var renderItem = array[ index ];
  13399. if ( renderItem !== undefined ) {
  13400. renderItem.id = object.id;
  13401. renderItem.object = object;
  13402. renderItem.geometry = geometry;
  13403. renderItem.material = material;
  13404. renderItem.z = _vector3.z;
  13405. renderItem.group = group;
  13406. } else {
  13407. renderItem = {
  13408. id: object.id,
  13409. object: object,
  13410. geometry: geometry,
  13411. material: material,
  13412. z: _vector3.z,
  13413. group: group
  13414. };
  13415. // assert( index === array.length );
  13416. array.push( renderItem );
  13417. }
  13418. }
  13419. function projectObject( object ) {
  13420. if ( object.visible === false ) return;
  13421. if ( object instanceof THREE.Light ) {
  13422. lights.push( object );
  13423. } else if ( object instanceof THREE.Sprite ) {
  13424. sprites.push( object );
  13425. } else if ( object instanceof THREE.LensFlare ) {
  13426. lensFlares.push( object );
  13427. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  13428. if ( _this.sortObjects === true ) {
  13429. _vector3.setFromMatrixPosition( object.matrixWorld );
  13430. _vector3.applyProjection( _projScreenMatrix );
  13431. }
  13432. pushRenderItem( object, null, object.material, _vector3.z, null );
  13433. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  13434. if ( object instanceof THREE.SkinnedMesh ) {
  13435. object.skeleton.update();
  13436. }
  13437. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  13438. var material = object.material;
  13439. if ( material.visible === true ) {
  13440. if ( _this.sortObjects === true ) {
  13441. _vector3.setFromMatrixPosition( object.matrixWorld );
  13442. _vector3.applyProjection( _projScreenMatrix );
  13443. }
  13444. var geometry = objects.update( object );
  13445. if ( material instanceof THREE.MeshFaceMaterial ) {
  13446. var groups = geometry.groups;
  13447. var materials = material.materials;
  13448. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  13449. var group = groups[ i ];
  13450. var groupMaterial = materials[ group.materialIndex ];
  13451. if ( groupMaterial.visible === true ) {
  13452. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  13453. }
  13454. }
  13455. } else {
  13456. pushRenderItem( object, geometry, material, _vector3.z, null );
  13457. }
  13458. }
  13459. }
  13460. }
  13461. var children = object.children;
  13462. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13463. projectObject( children[ i ] );
  13464. }
  13465. }
  13466. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  13467. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  13468. var renderItem = renderList[ i ];
  13469. var object = renderItem.object;
  13470. var geometry = renderItem.geometry;
  13471. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  13472. var group = renderItem.group;
  13473. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13474. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  13475. if ( object instanceof THREE.ImmediateRenderObject ) {
  13476. setMaterial( material );
  13477. var program = setProgram( camera, lights, fog, material, object );
  13478. _currentGeometryProgram = '';
  13479. object.render( function ( object ) {
  13480. _this.renderBufferImmediate( object, program, material );
  13481. } );
  13482. } else {
  13483. _this.renderBufferDirect( camera, lights, fog, geometry, material, object, group );
  13484. }
  13485. }
  13486. }
  13487. function initMaterial( material, lights, fog, object ) {
  13488. var materialProperties = properties.get( material );
  13489. var parameters = programCache.getParameters( material, lights, fog, object );
  13490. var code = programCache.getProgramCode( material, parameters );
  13491. var program = materialProperties.program;
  13492. var programChange = true;
  13493. if ( program === undefined ) {
  13494. // new material
  13495. material.addEventListener( 'dispose', onMaterialDispose );
  13496. } else if ( program.code !== code ) {
  13497. // changed glsl or parameters
  13498. releaseMaterialProgramReference( material );
  13499. } else if ( parameters.shaderID !== undefined ) {
  13500. // same glsl and uniform list
  13501. return;
  13502. } else {
  13503. // only rebuild uniform list
  13504. programChange = false;
  13505. }
  13506. if ( programChange ) {
  13507. if ( parameters.shaderID ) {
  13508. var shader = THREE.ShaderLib[ parameters.shaderID ];
  13509. materialProperties.__webglShader = {
  13510. name: material.type,
  13511. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  13512. vertexShader: shader.vertexShader,
  13513. fragmentShader: shader.fragmentShader
  13514. };
  13515. } else {
  13516. materialProperties.__webglShader = {
  13517. name: material.type,
  13518. uniforms: material.uniforms,
  13519. vertexShader: material.vertexShader,
  13520. fragmentShader: material.fragmentShader
  13521. };
  13522. }
  13523. material.__webglShader = materialProperties.__webglShader;
  13524. program = programCache.acquireProgram( material, parameters, code );
  13525. materialProperties.program = program;
  13526. material.program = program;
  13527. }
  13528. var attributes = program.getAttributes();
  13529. if ( material.morphTargets ) {
  13530. material.numSupportedMorphTargets = 0;
  13531. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  13532. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  13533. material.numSupportedMorphTargets ++;
  13534. }
  13535. }
  13536. }
  13537. if ( material.morphNormals ) {
  13538. material.numSupportedMorphNormals = 0;
  13539. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  13540. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  13541. material.numSupportedMorphNormals ++;
  13542. }
  13543. }
  13544. }
  13545. materialProperties.uniformsList = [];
  13546. var uniformLocations = materialProperties.program.getUniforms();
  13547. for ( var u in materialProperties.__webglShader.uniforms ) {
  13548. var location = uniformLocations[ u ];
  13549. if ( location ) {
  13550. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  13551. }
  13552. }
  13553. }
  13554. function setMaterial( material ) {
  13555. setMaterialFaces( material );
  13556. if ( material.transparent === true ) {
  13557. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  13558. } else {
  13559. state.setBlending( THREE.NoBlending );
  13560. }
  13561. state.setDepthFunc( material.depthFunc );
  13562. state.setDepthTest( material.depthTest );
  13563. state.setDepthWrite( material.depthWrite );
  13564. state.setColorWrite( material.colorWrite );
  13565. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  13566. }
  13567. function setMaterialFaces( material ) {
  13568. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  13569. state.setFlipSided( material.side === THREE.BackSide );
  13570. }
  13571. function setProgram( camera, lights, fog, material, object ) {
  13572. _usedTextureUnits = 0;
  13573. var materialProperties = properties.get( material );
  13574. if ( material.needsUpdate || ! materialProperties.program ) {
  13575. initMaterial( material, lights, fog, object );
  13576. material.needsUpdate = false;
  13577. }
  13578. var refreshProgram = false;
  13579. var refreshMaterial = false;
  13580. var refreshLights = false;
  13581. var program = materialProperties.program,
  13582. p_uniforms = program.getUniforms(),
  13583. m_uniforms = materialProperties.__webglShader.uniforms;
  13584. if ( program.id !== _currentProgram ) {
  13585. _gl.useProgram( program.program );
  13586. _currentProgram = program.id;
  13587. refreshProgram = true;
  13588. refreshMaterial = true;
  13589. refreshLights = true;
  13590. }
  13591. if ( material.id !== _currentMaterialId ) {
  13592. if ( _currentMaterialId === - 1 ) refreshLights = true;
  13593. _currentMaterialId = material.id;
  13594. refreshMaterial = true;
  13595. }
  13596. if ( refreshProgram || camera !== _currentCamera ) {
  13597. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  13598. if ( capabilities.logarithmicDepthBuffer ) {
  13599. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  13600. }
  13601. if ( camera !== _currentCamera ) _currentCamera = camera;
  13602. // load material specific uniforms
  13603. // (shader material also gets them for the sake of genericity)
  13604. if ( material instanceof THREE.ShaderMaterial ||
  13605. material instanceof THREE.MeshPhongMaterial ||
  13606. material.envMap ) {
  13607. if ( p_uniforms.cameraPosition !== undefined ) {
  13608. _vector3.setFromMatrixPosition( camera.matrixWorld );
  13609. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  13610. }
  13611. }
  13612. if ( material instanceof THREE.MeshPhongMaterial ||
  13613. material instanceof THREE.MeshLambertMaterial ||
  13614. material instanceof THREE.MeshBasicMaterial ||
  13615. material instanceof THREE.ShaderMaterial ||
  13616. material.skinning ) {
  13617. if ( p_uniforms.viewMatrix !== undefined ) {
  13618. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  13619. }
  13620. }
  13621. }
  13622. // skinning uniforms must be set even if material didn't change
  13623. // auto-setting of texture unit for bone texture must go before other textures
  13624. // not sure why, but otherwise weird things happen
  13625. if ( material.skinning ) {
  13626. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  13627. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  13628. }
  13629. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  13630. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  13631. }
  13632. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  13633. if ( p_uniforms.boneTexture !== undefined ) {
  13634. var textureUnit = getTextureUnit();
  13635. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  13636. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  13637. }
  13638. if ( p_uniforms.boneTextureWidth !== undefined ) {
  13639. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  13640. }
  13641. if ( p_uniforms.boneTextureHeight !== undefined ) {
  13642. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  13643. }
  13644. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  13645. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  13646. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  13647. }
  13648. }
  13649. }
  13650. if ( refreshMaterial ) {
  13651. // refresh uniforms common to several materials
  13652. if ( fog && material.fog ) {
  13653. refreshUniformsFog( m_uniforms, fog );
  13654. }
  13655. if ( material instanceof THREE.MeshPhongMaterial ||
  13656. material instanceof THREE.MeshLambertMaterial ||
  13657. material.lights ) {
  13658. if ( _lightsNeedUpdate ) {
  13659. refreshLights = true;
  13660. setupLights( lights, camera );
  13661. _lightsNeedUpdate = false;
  13662. }
  13663. if ( refreshLights ) {
  13664. refreshUniformsLights( m_uniforms, _lights );
  13665. markUniformsLightsNeedsUpdate( m_uniforms, true );
  13666. } else {
  13667. markUniformsLightsNeedsUpdate( m_uniforms, false );
  13668. }
  13669. }
  13670. if ( material instanceof THREE.MeshBasicMaterial ||
  13671. material instanceof THREE.MeshLambertMaterial ||
  13672. material instanceof THREE.MeshPhongMaterial ) {
  13673. refreshUniformsCommon( m_uniforms, material );
  13674. }
  13675. // refresh single material specific uniforms
  13676. if ( material instanceof THREE.LineBasicMaterial ) {
  13677. refreshUniformsLine( m_uniforms, material );
  13678. } else if ( material instanceof THREE.LineDashedMaterial ) {
  13679. refreshUniformsLine( m_uniforms, material );
  13680. refreshUniformsDash( m_uniforms, material );
  13681. } else if ( material instanceof THREE.PointsMaterial ) {
  13682. refreshUniformsParticle( m_uniforms, material );
  13683. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  13684. refreshUniformsPhong( m_uniforms, material );
  13685. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  13686. m_uniforms.mNear.value = camera.near;
  13687. m_uniforms.mFar.value = camera.far;
  13688. m_uniforms.opacity.value = material.opacity;
  13689. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  13690. m_uniforms.opacity.value = material.opacity;
  13691. }
  13692. if ( object.receiveShadow && ! material._shadowPass ) {
  13693. refreshUniformsShadow( m_uniforms, lights, camera );
  13694. }
  13695. // load common uniforms
  13696. loadUniformsGeneric( materialProperties.uniformsList );
  13697. }
  13698. loadUniformsMatrices( p_uniforms, object );
  13699. if ( p_uniforms.modelMatrix !== undefined ) {
  13700. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  13701. }
  13702. return program;
  13703. }
  13704. // Uniforms (refresh uniforms objects)
  13705. function refreshUniformsCommon ( uniforms, material ) {
  13706. uniforms.opacity.value = material.opacity;
  13707. uniforms.diffuse.value = material.color;
  13708. if ( material.emissive ) {
  13709. uniforms.emissive.value = material.emissive;
  13710. }
  13711. uniforms.map.value = material.map;
  13712. uniforms.specularMap.value = material.specularMap;
  13713. uniforms.alphaMap.value = material.alphaMap;
  13714. if ( material.aoMap ) {
  13715. uniforms.aoMap.value = material.aoMap;
  13716. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13717. }
  13718. // uv repeat and offset setting priorities
  13719. // 1. color map
  13720. // 2. specular map
  13721. // 3. normal map
  13722. // 4. bump map
  13723. // 5. alpha map
  13724. // 6. emissive map
  13725. var uvScaleMap;
  13726. if ( material.map ) {
  13727. uvScaleMap = material.map;
  13728. } else if ( material.specularMap ) {
  13729. uvScaleMap = material.specularMap;
  13730. } else if ( material.displacementMap ) {
  13731. uvScaleMap = material.displacementMap;
  13732. } else if ( material.normalMap ) {
  13733. uvScaleMap = material.normalMap;
  13734. } else if ( material.bumpMap ) {
  13735. uvScaleMap = material.bumpMap;
  13736. } else if ( material.alphaMap ) {
  13737. uvScaleMap = material.alphaMap;
  13738. } else if ( material.emissiveMap ) {
  13739. uvScaleMap = material.emissiveMap;
  13740. }
  13741. if ( uvScaleMap !== undefined ) {
  13742. var offset = uvScaleMap.offset;
  13743. var repeat = uvScaleMap.repeat;
  13744. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13745. }
  13746. uniforms.envMap.value = material.envMap;
  13747. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  13748. uniforms.reflectivity.value = material.reflectivity;
  13749. uniforms.refractionRatio.value = material.refractionRatio;
  13750. }
  13751. function refreshUniformsLine ( uniforms, material ) {
  13752. uniforms.diffuse.value = material.color;
  13753. uniforms.opacity.value = material.opacity;
  13754. }
  13755. function refreshUniformsDash ( uniforms, material ) {
  13756. uniforms.dashSize.value = material.dashSize;
  13757. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13758. uniforms.scale.value = material.scale;
  13759. }
  13760. function refreshUniformsParticle ( uniforms, material ) {
  13761. uniforms.psColor.value = material.color;
  13762. uniforms.opacity.value = material.opacity;
  13763. uniforms.size.value = material.size;
  13764. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  13765. uniforms.map.value = material.map;
  13766. if ( material.map !== null ) {
  13767. var offset = material.map.offset;
  13768. var repeat = material.map.repeat;
  13769. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13770. }
  13771. }
  13772. function refreshUniformsFog ( uniforms, fog ) {
  13773. uniforms.fogColor.value = fog.color;
  13774. if ( fog instanceof THREE.Fog ) {
  13775. uniforms.fogNear.value = fog.near;
  13776. uniforms.fogFar.value = fog.far;
  13777. } else if ( fog instanceof THREE.FogExp2 ) {
  13778. uniforms.fogDensity.value = fog.density;
  13779. }
  13780. }
  13781. function refreshUniformsPhong ( uniforms, material ) {
  13782. uniforms.specular.value = material.specular;
  13783. uniforms.shininess.value = material.shininess;
  13784. if ( material.lightMap ) {
  13785. uniforms.lightMap.value = material.lightMap;
  13786. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13787. }
  13788. if ( material.emissiveMap ) {
  13789. uniforms.emissiveMap.value = material.emissiveMap;
  13790. }
  13791. if ( material.bumpMap ) {
  13792. uniforms.bumpMap.value = material.bumpMap;
  13793. uniforms.bumpScale.value = material.bumpScale;
  13794. }
  13795. if ( material.normalMap ) {
  13796. uniforms.normalMap.value = material.normalMap;
  13797. uniforms.normalScale.value.copy( material.normalScale );
  13798. }
  13799. if ( material.displacementMap ) {
  13800. uniforms.displacementMap.value = material.displacementMap;
  13801. uniforms.displacementScale.value = material.displacementScale;
  13802. uniforms.displacementBias.value = material.displacementBias;
  13803. }
  13804. }
  13805. function refreshUniformsLights ( uniforms, lights ) {
  13806. uniforms.ambientLightColor.value = lights.ambient;
  13807. uniforms.directionalLightColor.value = lights.directional.colors;
  13808. uniforms.directionalLightDirection.value = lights.directional.positions;
  13809. uniforms.pointLightColor.value = lights.point.colors;
  13810. uniforms.pointLightPosition.value = lights.point.positions;
  13811. uniforms.pointLightDistance.value = lights.point.distances;
  13812. uniforms.pointLightDecay.value = lights.point.decays;
  13813. uniforms.spotLightColor.value = lights.spot.colors;
  13814. uniforms.spotLightPosition.value = lights.spot.positions;
  13815. uniforms.spotLightDistance.value = lights.spot.distances;
  13816. uniforms.spotLightDirection.value = lights.spot.directions;
  13817. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  13818. uniforms.spotLightExponent.value = lights.spot.exponents;
  13819. uniforms.spotLightDecay.value = lights.spot.decays;
  13820. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  13821. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  13822. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  13823. }
  13824. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13825. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  13826. uniforms.ambientLightColor.needsUpdate = value;
  13827. uniforms.directionalLightColor.needsUpdate = value;
  13828. uniforms.directionalLightDirection.needsUpdate = value;
  13829. uniforms.pointLightColor.needsUpdate = value;
  13830. uniforms.pointLightPosition.needsUpdate = value;
  13831. uniforms.pointLightDistance.needsUpdate = value;
  13832. uniforms.pointLightDecay.needsUpdate = value;
  13833. uniforms.spotLightColor.needsUpdate = value;
  13834. uniforms.spotLightPosition.needsUpdate = value;
  13835. uniforms.spotLightDistance.needsUpdate = value;
  13836. uniforms.spotLightDirection.needsUpdate = value;
  13837. uniforms.spotLightAngleCos.needsUpdate = value;
  13838. uniforms.spotLightExponent.needsUpdate = value;
  13839. uniforms.spotLightDecay.needsUpdate = value;
  13840. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  13841. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  13842. uniforms.hemisphereLightDirection.needsUpdate = value;
  13843. }
  13844. function refreshUniformsShadow ( uniforms, lights, camera ) {
  13845. if ( uniforms.shadowMatrix ) {
  13846. var j = 0;
  13847. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  13848. var light = lights[ i ];
  13849. if ( ! light.castShadow ) continue;
  13850. if ( light instanceof THREE.PointLight || light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) {
  13851. if ( light instanceof THREE.PointLight ) {
  13852. // for point lights we set the sign of the shadowDarkness uniform to be negative
  13853. uniforms.shadowDarkness.value[ j ] = - light.shadowDarkness;
  13854. } else {
  13855. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  13856. }
  13857. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  13858. uniforms.shadowMap.value[ j ] = light.shadowMap;
  13859. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  13860. uniforms.shadowBias.value[ j ] = light.shadowBias;
  13861. j ++;
  13862. }
  13863. }
  13864. }
  13865. }
  13866. // Uniforms (load to GPU)
  13867. function loadUniformsMatrices ( uniforms, object ) {
  13868. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  13869. if ( uniforms.normalMatrix ) {
  13870. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  13871. }
  13872. }
  13873. function getTextureUnit() {
  13874. var textureUnit = _usedTextureUnits;
  13875. if ( textureUnit >= capabilities.maxTextures ) {
  13876. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  13877. }
  13878. _usedTextureUnits += 1;
  13879. return textureUnit;
  13880. }
  13881. function loadUniformsGeneric ( uniforms ) {
  13882. var texture, textureUnit;
  13883. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  13884. var uniform = uniforms[ j ][ 0 ];
  13885. // needsUpdate property is not added to all uniforms.
  13886. if ( uniform.needsUpdate === false ) continue;
  13887. var type = uniform.type;
  13888. var value = uniform.value;
  13889. var location = uniforms[ j ][ 1 ];
  13890. switch ( type ) {
  13891. case '1i':
  13892. _gl.uniform1i( location, value );
  13893. break;
  13894. case '1f':
  13895. _gl.uniform1f( location, value );
  13896. break;
  13897. case '2f':
  13898. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  13899. break;
  13900. case '3f':
  13901. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  13902. break;
  13903. case '4f':
  13904. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  13905. break;
  13906. case '1iv':
  13907. _gl.uniform1iv( location, value );
  13908. break;
  13909. case '3iv':
  13910. _gl.uniform3iv( location, value );
  13911. break;
  13912. case '1fv':
  13913. _gl.uniform1fv( location, value );
  13914. break;
  13915. case '2fv':
  13916. _gl.uniform2fv( location, value );
  13917. break;
  13918. case '3fv':
  13919. _gl.uniform3fv( location, value );
  13920. break;
  13921. case '4fv':
  13922. _gl.uniform4fv( location, value );
  13923. break;
  13924. case 'Matrix3fv':
  13925. _gl.uniformMatrix3fv( location, false, value );
  13926. break;
  13927. case 'Matrix4fv':
  13928. _gl.uniformMatrix4fv( location, false, value );
  13929. break;
  13930. //
  13931. case 'i':
  13932. // single integer
  13933. _gl.uniform1i( location, value );
  13934. break;
  13935. case 'f':
  13936. // single float
  13937. _gl.uniform1f( location, value );
  13938. break;
  13939. case 'v2':
  13940. // single THREE.Vector2
  13941. _gl.uniform2f( location, value.x, value.y );
  13942. break;
  13943. case 'v3':
  13944. // single THREE.Vector3
  13945. _gl.uniform3f( location, value.x, value.y, value.z );
  13946. break;
  13947. case 'v4':
  13948. // single THREE.Vector4
  13949. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  13950. break;
  13951. case 'c':
  13952. // single THREE.Color
  13953. _gl.uniform3f( location, value.r, value.g, value.b );
  13954. break;
  13955. case 'iv1':
  13956. // flat array of integers (JS or typed array)
  13957. _gl.uniform1iv( location, value );
  13958. break;
  13959. case 'iv':
  13960. // flat array of integers with 3 x N size (JS or typed array)
  13961. _gl.uniform3iv( location, value );
  13962. break;
  13963. case 'fv1':
  13964. // flat array of floats (JS or typed array)
  13965. _gl.uniform1fv( location, value );
  13966. break;
  13967. case 'fv':
  13968. // flat array of floats with 3 x N size (JS or typed array)
  13969. _gl.uniform3fv( location, value );
  13970. break;
  13971. case 'v2v':
  13972. // array of THREE.Vector2
  13973. if ( uniform._array === undefined ) {
  13974. uniform._array = new Float32Array( 2 * value.length );
  13975. }
  13976. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  13977. uniform._array[ i2 + 0 ] = value[ i ].x;
  13978. uniform._array[ i2 + 1 ] = value[ i ].y;
  13979. }
  13980. _gl.uniform2fv( location, uniform._array );
  13981. break;
  13982. case 'v3v':
  13983. // array of THREE.Vector3
  13984. if ( uniform._array === undefined ) {
  13985. uniform._array = new Float32Array( 3 * value.length );
  13986. }
  13987. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  13988. uniform._array[ i3 + 0 ] = value[ i ].x;
  13989. uniform._array[ i3 + 1 ] = value[ i ].y;
  13990. uniform._array[ i3 + 2 ] = value[ i ].z;
  13991. }
  13992. _gl.uniform3fv( location, uniform._array );
  13993. break;
  13994. case 'v4v':
  13995. // array of THREE.Vector4
  13996. if ( uniform._array === undefined ) {
  13997. uniform._array = new Float32Array( 4 * value.length );
  13998. }
  13999. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  14000. uniform._array[ i4 + 0 ] = value[ i ].x;
  14001. uniform._array[ i4 + 1 ] = value[ i ].y;
  14002. uniform._array[ i4 + 2 ] = value[ i ].z;
  14003. uniform._array[ i4 + 3 ] = value[ i ].w;
  14004. }
  14005. _gl.uniform4fv( location, uniform._array );
  14006. break;
  14007. case 'm3':
  14008. // single THREE.Matrix3
  14009. _gl.uniformMatrix3fv( location, false, value.elements );
  14010. break;
  14011. case 'm3v':
  14012. // array of THREE.Matrix3
  14013. if ( uniform._array === undefined ) {
  14014. uniform._array = new Float32Array( 9 * value.length );
  14015. }
  14016. for ( var i = 0, il = value.length; i < il; i ++ ) {
  14017. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  14018. }
  14019. _gl.uniformMatrix3fv( location, false, uniform._array );
  14020. break;
  14021. case 'm4':
  14022. // single THREE.Matrix4
  14023. _gl.uniformMatrix4fv( location, false, value.elements );
  14024. break;
  14025. case 'm4v':
  14026. // array of THREE.Matrix4
  14027. if ( uniform._array === undefined ) {
  14028. uniform._array = new Float32Array( 16 * value.length );
  14029. }
  14030. for ( var i = 0, il = value.length; i < il; i ++ ) {
  14031. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  14032. }
  14033. _gl.uniformMatrix4fv( location, false, uniform._array );
  14034. break;
  14035. case 't':
  14036. // single THREE.Texture (2d or cube)
  14037. texture = value;
  14038. textureUnit = getTextureUnit();
  14039. _gl.uniform1i( location, textureUnit );
  14040. if ( ! texture ) continue;
  14041. if ( texture instanceof THREE.CubeTexture ||
  14042. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  14043. // CompressedTexture can have Array in image :/
  14044. setCubeTexture( texture, textureUnit );
  14045. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  14046. setCubeTextureDynamic( texture, textureUnit );
  14047. } else {
  14048. _this.setTexture( texture, textureUnit );
  14049. }
  14050. break;
  14051. case 'tv':
  14052. // array of THREE.Texture (2d or cube)
  14053. if ( uniform._array === undefined ) {
  14054. uniform._array = [];
  14055. }
  14056. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  14057. uniform._array[ i ] = getTextureUnit();
  14058. }
  14059. _gl.uniform1iv( location, uniform._array );
  14060. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  14061. texture = uniform.value[ i ];
  14062. textureUnit = uniform._array[ i ];
  14063. if ( ! texture ) continue;
  14064. if ( texture instanceof THREE.CubeTexture ||
  14065. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  14066. // CompressedTexture can have Array in image :/
  14067. setCubeTexture( texture, textureUnit );
  14068. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  14069. setCubeTextureDynamic( texture, textureUnit );
  14070. } else {
  14071. _this.setTexture( texture, textureUnit );
  14072. }
  14073. }
  14074. break;
  14075. default:
  14076. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  14077. }
  14078. }
  14079. }
  14080. function setColorLinear( array, offset, color, intensity ) {
  14081. array[ offset + 0 ] = color.r * intensity;
  14082. array[ offset + 1 ] = color.g * intensity;
  14083. array[ offset + 2 ] = color.b * intensity;
  14084. }
  14085. function setupLights ( lights, camera ) {
  14086. var l, ll, light,
  14087. r = 0, g = 0, b = 0,
  14088. color, skyColor, groundColor,
  14089. intensity,
  14090. distance,
  14091. zlights = _lights,
  14092. viewMatrix = camera.matrixWorldInverse,
  14093. dirColors = zlights.directional.colors,
  14094. dirPositions = zlights.directional.positions,
  14095. pointColors = zlights.point.colors,
  14096. pointPositions = zlights.point.positions,
  14097. pointDistances = zlights.point.distances,
  14098. pointDecays = zlights.point.decays,
  14099. spotColors = zlights.spot.colors,
  14100. spotPositions = zlights.spot.positions,
  14101. spotDistances = zlights.spot.distances,
  14102. spotDirections = zlights.spot.directions,
  14103. spotAnglesCos = zlights.spot.anglesCos,
  14104. spotExponents = zlights.spot.exponents,
  14105. spotDecays = zlights.spot.decays,
  14106. hemiSkyColors = zlights.hemi.skyColors,
  14107. hemiGroundColors = zlights.hemi.groundColors,
  14108. hemiPositions = zlights.hemi.positions,
  14109. dirLength = 0,
  14110. pointLength = 0,
  14111. spotLength = 0,
  14112. hemiLength = 0,
  14113. dirCount = 0,
  14114. pointCount = 0,
  14115. spotCount = 0,
  14116. hemiCount = 0,
  14117. dirOffset = 0,
  14118. pointOffset = 0,
  14119. spotOffset = 0,
  14120. hemiOffset = 0;
  14121. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  14122. light = lights[ l ];
  14123. if ( light.onlyShadow ) continue;
  14124. color = light.color;
  14125. intensity = light.intensity;
  14126. distance = light.distance;
  14127. if ( light instanceof THREE.AmbientLight ) {
  14128. if ( ! light.visible ) continue;
  14129. r += color.r;
  14130. g += color.g;
  14131. b += color.b;
  14132. } else if ( light instanceof THREE.DirectionalLight ) {
  14133. dirCount += 1;
  14134. if ( ! light.visible ) continue;
  14135. _direction.setFromMatrixPosition( light.matrixWorld );
  14136. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  14137. _direction.sub( _vector3 );
  14138. _direction.transformDirection( viewMatrix );
  14139. dirOffset = dirLength * 3;
  14140. dirPositions[ dirOffset + 0 ] = _direction.x;
  14141. dirPositions[ dirOffset + 1 ] = _direction.y;
  14142. dirPositions[ dirOffset + 2 ] = _direction.z;
  14143. setColorLinear( dirColors, dirOffset, color, intensity );
  14144. dirLength += 1;
  14145. } else if ( light instanceof THREE.PointLight ) {
  14146. pointCount += 1;
  14147. if ( ! light.visible ) continue;
  14148. pointOffset = pointLength * 3;
  14149. setColorLinear( pointColors, pointOffset, color, intensity );
  14150. _vector3.setFromMatrixPosition( light.matrixWorld );
  14151. _vector3.applyMatrix4( viewMatrix );
  14152. pointPositions[ pointOffset + 0 ] = _vector3.x;
  14153. pointPositions[ pointOffset + 1 ] = _vector3.y;
  14154. pointPositions[ pointOffset + 2 ] = _vector3.z;
  14155. // distance is 0 if decay is 0, because there is no attenuation at all.
  14156. pointDistances[ pointLength ] = distance;
  14157. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  14158. pointLength += 1;
  14159. } else if ( light instanceof THREE.SpotLight ) {
  14160. spotCount += 1;
  14161. if ( ! light.visible ) continue;
  14162. spotOffset = spotLength * 3;
  14163. setColorLinear( spotColors, spotOffset, color, intensity );
  14164. _direction.setFromMatrixPosition( light.matrixWorld );
  14165. _vector3.copy( _direction ).applyMatrix4( viewMatrix );
  14166. spotPositions[ spotOffset + 0 ] = _vector3.x;
  14167. spotPositions[ spotOffset + 1 ] = _vector3.y;
  14168. spotPositions[ spotOffset + 2 ] = _vector3.z;
  14169. spotDistances[ spotLength ] = distance;
  14170. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  14171. _direction.sub( _vector3 );
  14172. _direction.transformDirection( viewMatrix );
  14173. spotDirections[ spotOffset + 0 ] = _direction.x;
  14174. spotDirections[ spotOffset + 1 ] = _direction.y;
  14175. spotDirections[ spotOffset + 2 ] = _direction.z;
  14176. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  14177. spotExponents[ spotLength ] = light.exponent;
  14178. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  14179. spotLength += 1;
  14180. } else if ( light instanceof THREE.HemisphereLight ) {
  14181. hemiCount += 1;
  14182. if ( ! light.visible ) continue;
  14183. _direction.setFromMatrixPosition( light.matrixWorld );
  14184. _direction.transformDirection( viewMatrix );
  14185. hemiOffset = hemiLength * 3;
  14186. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  14187. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  14188. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  14189. skyColor = light.color;
  14190. groundColor = light.groundColor;
  14191. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  14192. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  14193. hemiLength += 1;
  14194. }
  14195. }
  14196. // null eventual remains from removed lights
  14197. // (this is to avoid if in shader)
  14198. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  14199. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  14200. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  14201. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  14202. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  14203. zlights.directional.length = dirLength;
  14204. zlights.point.length = pointLength;
  14205. zlights.spot.length = spotLength;
  14206. zlights.hemi.length = hemiLength;
  14207. zlights.ambient[ 0 ] = r;
  14208. zlights.ambient[ 1 ] = g;
  14209. zlights.ambient[ 2 ] = b;
  14210. }
  14211. // GL state setting
  14212. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  14213. if ( cullFace === THREE.CullFaceNone ) {
  14214. state.disable( _gl.CULL_FACE );
  14215. } else {
  14216. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  14217. _gl.frontFace( _gl.CW );
  14218. } else {
  14219. _gl.frontFace( _gl.CCW );
  14220. }
  14221. if ( cullFace === THREE.CullFaceBack ) {
  14222. _gl.cullFace( _gl.BACK );
  14223. } else if ( cullFace === THREE.CullFaceFront ) {
  14224. _gl.cullFace( _gl.FRONT );
  14225. } else {
  14226. _gl.cullFace( _gl.FRONT_AND_BACK );
  14227. }
  14228. state.enable( _gl.CULL_FACE );
  14229. }
  14230. };
  14231. // Textures
  14232. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  14233. var extension;
  14234. if ( isImagePowerOfTwo ) {
  14235. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  14236. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  14237. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  14238. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  14239. } else {
  14240. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  14241. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  14242. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  14243. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. ( ' + texture.sourceFile + ' )' );
  14244. }
  14245. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  14246. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  14247. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  14248. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. ( ' + texture.sourceFile + ' )' );
  14249. }
  14250. }
  14251. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14252. if ( extension ) {
  14253. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  14254. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  14255. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  14256. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  14257. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  14258. }
  14259. }
  14260. }
  14261. function uploadTexture( textureProperties, texture, slot ) {
  14262. if ( textureProperties.__webglInit === undefined ) {
  14263. textureProperties.__webglInit = true;
  14264. texture.__webglInit = true;
  14265. texture.addEventListener( 'dispose', onTextureDispose );
  14266. textureProperties.__webglTexture = _gl.createTexture();
  14267. _infoMemory.textures ++;
  14268. }
  14269. state.activeTexture( _gl.TEXTURE0 + slot );
  14270. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14271. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  14272. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  14273. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  14274. texture.image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  14275. var image = texture.image,
  14276. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  14277. glFormat = paramThreeToGL( texture.format ),
  14278. glType = paramThreeToGL( texture.type );
  14279. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  14280. var mipmap, mipmaps = texture.mipmaps;
  14281. if ( texture instanceof THREE.DataTexture ) {
  14282. // use manually created mipmaps if available
  14283. // if there are no manual mipmaps
  14284. // set 0 level mipmap and then use GL to generate other mipmap levels
  14285. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  14286. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14287. mipmap = mipmaps[ i ];
  14288. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14289. }
  14290. texture.generateMipmaps = false;
  14291. } else {
  14292. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  14293. }
  14294. } else if ( texture instanceof THREE.CompressedTexture ) {
  14295. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14296. mipmap = mipmaps[ i ];
  14297. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  14298. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  14299. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  14300. } else {
  14301. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  14302. }
  14303. } else {
  14304. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14305. }
  14306. }
  14307. } else {
  14308. // regular Texture (image, video, canvas)
  14309. // use manually created mipmaps if available
  14310. // if there are no manual mipmaps
  14311. // set 0 level mipmap and then use GL to generate other mipmap levels
  14312. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  14313. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14314. mipmap = mipmaps[ i ];
  14315. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  14316. }
  14317. texture.generateMipmaps = false;
  14318. } else {
  14319. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  14320. }
  14321. }
  14322. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  14323. textureProperties.__version = texture.version;
  14324. if ( texture.onUpdate ) texture.onUpdate( texture );
  14325. }
  14326. this.setTexture = function ( texture, slot ) {
  14327. var textureProperties = properties.get( texture );
  14328. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  14329. var image = texture.image;
  14330. if ( image === undefined ) {
  14331. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  14332. return;
  14333. }
  14334. if ( image.complete === false ) {
  14335. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  14336. return;
  14337. }
  14338. uploadTexture( textureProperties, texture, slot );
  14339. return;
  14340. }
  14341. state.activeTexture( _gl.TEXTURE0 + slot );
  14342. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14343. };
  14344. function clampToMaxSize ( image, maxSize ) {
  14345. if ( image.width > maxSize || image.height > maxSize ) {
  14346. // Warning: Scaling through the canvas will only work with images that use
  14347. // premultiplied alpha.
  14348. var scale = maxSize / Math.max( image.width, image.height );
  14349. var canvas = document.createElement( 'canvas' );
  14350. canvas.width = Math.floor( image.width * scale );
  14351. canvas.height = Math.floor( image.height * scale );
  14352. var context = canvas.getContext( '2d' );
  14353. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  14354. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  14355. return canvas;
  14356. }
  14357. return image;
  14358. }
  14359. function setCubeTexture ( texture, slot ) {
  14360. var textureProperties = properties.get( texture );
  14361. if ( texture.image.length === 6 ) {
  14362. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  14363. if ( ! textureProperties.__image__webglTextureCube ) {
  14364. texture.addEventListener( 'dispose', onTextureDispose );
  14365. textureProperties.__image__webglTextureCube = _gl.createTexture();
  14366. _infoMemory.textures ++;
  14367. }
  14368. state.activeTexture( _gl.TEXTURE0 + slot );
  14369. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  14370. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  14371. var isCompressed = texture instanceof THREE.CompressedTexture;
  14372. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  14373. var cubeImage = [];
  14374. for ( var i = 0; i < 6; i ++ ) {
  14375. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  14376. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  14377. } else {
  14378. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  14379. }
  14380. }
  14381. var image = cubeImage[ 0 ],
  14382. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  14383. glFormat = paramThreeToGL( texture.format ),
  14384. glType = paramThreeToGL( texture.type );
  14385. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  14386. for ( var i = 0; i < 6; i ++ ) {
  14387. if ( ! isCompressed ) {
  14388. if ( isDataTexture ) {
  14389. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  14390. } else {
  14391. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  14392. }
  14393. } else {
  14394. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  14395. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  14396. mipmap = mipmaps[ j ];
  14397. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  14398. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  14399. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  14400. } else {
  14401. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  14402. }
  14403. } else {
  14404. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14405. }
  14406. }
  14407. }
  14408. }
  14409. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  14410. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  14411. }
  14412. textureProperties.__version = texture.version;
  14413. if ( texture.onUpdate ) texture.onUpdate( texture );
  14414. } else {
  14415. state.activeTexture( _gl.TEXTURE0 + slot );
  14416. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  14417. }
  14418. }
  14419. }
  14420. function setCubeTextureDynamic ( texture, slot ) {
  14421. state.activeTexture( _gl.TEXTURE0 + slot );
  14422. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  14423. }
  14424. // Render targets
  14425. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  14426. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14427. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget ).__webglTexture, 0 );
  14428. }
  14429. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  14430. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  14431. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  14432. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  14433. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14434. /* For some reason this is not working. Defaulting to RGBA4.
  14435. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14436. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  14437. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14438. */
  14439. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14440. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  14441. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14442. } else {
  14443. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  14444. }
  14445. }
  14446. this.setRenderTarget = function ( renderTarget ) {
  14447. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  14448. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14449. var renderTargetProperties = properties.get( renderTarget );
  14450. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  14451. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  14452. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  14453. renderTargetProperties.__webglTexture = _gl.createTexture();
  14454. _infoMemory.textures ++;
  14455. // Setup texture, create render and frame buffers
  14456. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
  14457. glFormat = paramThreeToGL( renderTarget.format ),
  14458. glType = paramThreeToGL( renderTarget.type );
  14459. if ( isCube ) {
  14460. renderTargetProperties.__webglFramebuffer = [];
  14461. renderTargetProperties.__webglRenderbuffer = [];
  14462. state.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTargetProperties.__webglTexture );
  14463. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
  14464. for ( var i = 0; i < 6; i ++ ) {
  14465. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  14466. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  14467. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  14468. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  14469. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  14470. }
  14471. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  14472. } else {
  14473. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  14474. if ( renderTarget.shareDepthFrom ) {
  14475. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  14476. } else {
  14477. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  14478. }
  14479. state.bindTexture( _gl.TEXTURE_2D, renderTargetProperties.__webglTexture );
  14480. setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
  14481. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  14482. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  14483. if ( renderTarget.shareDepthFrom ) {
  14484. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  14485. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  14486. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14487. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  14488. }
  14489. } else {
  14490. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  14491. }
  14492. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  14493. }
  14494. // Release everything
  14495. if ( isCube ) {
  14496. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  14497. } else {
  14498. state.bindTexture( _gl.TEXTURE_2D, null );
  14499. }
  14500. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  14501. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  14502. }
  14503. var framebuffer, width, height, vx, vy;
  14504. if ( renderTarget ) {
  14505. var renderTargetProperties = properties.get( renderTarget );
  14506. if ( isCube ) {
  14507. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  14508. } else {
  14509. framebuffer = renderTargetProperties.__webglFramebuffer;
  14510. }
  14511. width = renderTarget.width;
  14512. height = renderTarget.height;
  14513. vx = 0;
  14514. vy = 0;
  14515. } else {
  14516. framebuffer = null;
  14517. width = _viewportWidth;
  14518. height = _viewportHeight;
  14519. vx = _viewportX;
  14520. vy = _viewportY;
  14521. }
  14522. if ( framebuffer !== _currentFramebuffer ) {
  14523. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14524. _gl.viewport( vx, vy, width, height );
  14525. _currentFramebuffer = framebuffer;
  14526. }
  14527. if ( isCube ) {
  14528. var renderTargetProperties = properties.get( renderTarget );
  14529. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, renderTargetProperties.__webglTexture, 0 );
  14530. }
  14531. _currentWidth = width;
  14532. _currentHeight = height;
  14533. };
  14534. this.readRenderTargetPixels = function( renderTarget, x, y, width, height, buffer ) {
  14535. if ( ! ( renderTarget instanceof THREE.WebGLRenderTarget ) ) {
  14536. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14537. return;
  14538. }
  14539. if ( properties.get( renderTarget ).__webglFramebuffer ) {
  14540. var restore = false;
  14541. if ( properties.get( renderTarget ).__webglFramebuffer !== _currentFramebuffer ) {
  14542. _gl.bindFramebuffer( _gl.FRAMEBUFFER, properties.get( renderTarget ).__webglFramebuffer );
  14543. restore = true;
  14544. }
  14545. if ( renderTarget.format !== THREE.RGBAFormat && paramThreeToGL( renderTarget.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  14546. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14547. return;
  14548. }
  14549. if ( renderTarget.type !== THREE.UnsignedByteType && paramThreeToGL( renderTarget.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) ) {
  14550. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14551. return;
  14552. }
  14553. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  14554. _gl.readPixels( x, y, width, height, paramThreeToGL( renderTarget.format ), paramThreeToGL( renderTarget.type ), buffer );
  14555. } else {
  14556. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14557. }
  14558. if ( restore ) {
  14559. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  14560. }
  14561. }
  14562. };
  14563. function updateRenderTargetMipmap( renderTarget ) {
  14564. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  14565. var texture = properties.get( renderTarget ).__webglTexture;
  14566. state.bindTexture( target, texture );
  14567. _gl.generateMipmap( target );
  14568. state.bindTexture( target, null );
  14569. }
  14570. // Fallback filters for non-power-of-2 textures
  14571. function filterFallback ( f ) {
  14572. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  14573. return _gl.NEAREST;
  14574. }
  14575. return _gl.LINEAR;
  14576. }
  14577. // Map three.js constants to WebGL constants
  14578. function paramThreeToGL ( p ) {
  14579. var extension;
  14580. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  14581. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  14582. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  14583. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  14584. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  14585. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  14586. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  14587. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  14588. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  14589. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  14590. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  14591. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  14592. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  14593. if ( p === THREE.ByteType ) return _gl.BYTE;
  14594. if ( p === THREE.ShortType ) return _gl.SHORT;
  14595. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  14596. if ( p === THREE.IntType ) return _gl.INT;
  14597. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  14598. if ( p === THREE.FloatType ) return _gl.FLOAT;
  14599. extension = extensions.get( 'OES_texture_half_float' );
  14600. if ( extension !== null ) {
  14601. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  14602. }
  14603. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  14604. if ( p === THREE.RGBFormat ) return _gl.RGB;
  14605. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  14606. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  14607. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  14608. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  14609. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  14610. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  14611. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  14612. if ( p === THREE.OneFactor ) return _gl.ONE;
  14613. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  14614. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  14615. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  14616. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  14617. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  14618. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  14619. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  14620. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  14621. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  14622. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14623. if ( extension !== null ) {
  14624. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  14625. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  14626. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  14627. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  14628. }
  14629. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14630. if ( extension !== null ) {
  14631. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  14632. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  14633. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  14634. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  14635. }
  14636. extension = extensions.get( 'EXT_blend_minmax' );
  14637. if ( extension !== null ) {
  14638. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  14639. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  14640. }
  14641. return 0;
  14642. }
  14643. // DEPRECATED
  14644. this.supportsFloatTextures = function () {
  14645. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  14646. return extensions.get( 'OES_texture_float' );
  14647. };
  14648. this.supportsHalfFloatTextures = function () {
  14649. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  14650. return extensions.get( 'OES_texture_half_float' );
  14651. };
  14652. this.supportsStandardDerivatives = function () {
  14653. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  14654. return extensions.get( 'OES_standard_derivatives' );
  14655. };
  14656. this.supportsCompressedTextureS3TC = function () {
  14657. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  14658. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14659. };
  14660. this.supportsCompressedTexturePVRTC = function () {
  14661. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  14662. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14663. };
  14664. this.supportsBlendMinMax = function () {
  14665. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  14666. return extensions.get( 'EXT_blend_minmax' );
  14667. };
  14668. this.supportsVertexTextures = function () {
  14669. return capabilities.vertexTextures;
  14670. };
  14671. this.supportsInstancedArrays = function () {
  14672. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  14673. return extensions.get( 'ANGLE_instanced_arrays' );
  14674. };
  14675. //
  14676. this.initMaterial = function () {
  14677. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  14678. };
  14679. this.addPrePlugin = function () {
  14680. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  14681. };
  14682. this.addPostPlugin = function () {
  14683. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  14684. };
  14685. this.updateShadowMap = function () {
  14686. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  14687. };
  14688. Object.defineProperties( this, {
  14689. shadowMapEnabled: {
  14690. get: function () {
  14691. return shadowMap.enabled;
  14692. },
  14693. set: function ( value ) {
  14694. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  14695. shadowMap.enabled = value;
  14696. }
  14697. },
  14698. shadowMapType: {
  14699. get: function () {
  14700. return shadowMap.type;
  14701. },
  14702. set: function ( value ) {
  14703. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  14704. shadowMap.type = value;
  14705. }
  14706. },
  14707. shadowMapCullFace: {
  14708. get: function () {
  14709. return shadowMap.cullFace;
  14710. },
  14711. set: function ( value ) {
  14712. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  14713. shadowMap.cullFace = value;
  14714. }
  14715. },
  14716. shadowMapDebug: {
  14717. get: function () {
  14718. return shadowMap.debug;
  14719. },
  14720. set: function ( value ) {
  14721. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  14722. shadowMap.debug = value;
  14723. }
  14724. }
  14725. } );
  14726. };
  14727. // File:src/renderers/WebGLRenderTarget.js
  14728. /**
  14729. * @author szimek / https://github.com/szimek/
  14730. * @author alteredq / http://alteredqualia.com/
  14731. */
  14732. THREE.WebGLRenderTarget = function ( width, height, options ) {
  14733. this.uuid = THREE.Math.generateUUID();
  14734. this.width = width;
  14735. this.height = height;
  14736. options = options || {};
  14737. this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
  14738. this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
  14739. this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
  14740. this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
  14741. this.anisotropy = options.anisotropy !== undefined ? options.anisotropy : 1;
  14742. this.offset = new THREE.Vector2( 0, 0 );
  14743. this.repeat = new THREE.Vector2( 1, 1 );
  14744. this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
  14745. this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
  14746. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  14747. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  14748. this.generateMipmaps = true;
  14749. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  14750. };
  14751. THREE.WebGLRenderTarget.prototype = {
  14752. constructor: THREE.WebGLRenderTarget,
  14753. setSize: function ( width, height ) {
  14754. if ( this.width !== width || this.height !== height ) {
  14755. this.width = width;
  14756. this.height = height;
  14757. this.dispose();
  14758. }
  14759. },
  14760. clone: function () {
  14761. return new this.constructor().copy( this );
  14762. },
  14763. copy: function ( source ) {
  14764. this.width = source.width;
  14765. this.height = source.height;
  14766. this.wrapS = source.wrapS;
  14767. this.wrapT = source.wrapT;
  14768. this.magFilter = source.magFilter;
  14769. this.minFilter = source.minFilter;
  14770. this.anisotropy = source.anisotropy;
  14771. this.offset.copy( source.offset );
  14772. this.repeat.copy( source.repeat );
  14773. this.format = source.format;
  14774. this.type = source.type;
  14775. this.depthBuffer = source.depthBuffer;
  14776. this.stencilBuffer = source.stencilBuffer;
  14777. this.generateMipmaps = source.generateMipmaps;
  14778. this.shareDepthFrom = source.shareDepthFrom;
  14779. return this;
  14780. },
  14781. dispose: function () {
  14782. this.dispatchEvent( { type: 'dispose' } );
  14783. }
  14784. };
  14785. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  14786. // File:src/renderers/WebGLRenderTargetCube.js
  14787. /**
  14788. * @author alteredq / http://alteredqualia.com
  14789. */
  14790. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  14791. THREE.WebGLRenderTarget.call( this, width, height, options );
  14792. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  14793. };
  14794. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  14795. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  14796. // File:src/renderers/webgl/WebGLBufferRenderer.js
  14797. /**
  14798. * @author mrdoob / http://mrdoob.com/
  14799. */
  14800. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  14801. var mode;
  14802. function setMode( value ) {
  14803. mode = value;
  14804. }
  14805. function render( start, count ) {
  14806. _gl.drawArrays( mode, start, count );
  14807. _infoRender.calls ++;
  14808. _infoRender.vertices += count;
  14809. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  14810. }
  14811. function renderInstances( geometry ) {
  14812. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  14813. if ( extension === null ) {
  14814. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14815. return;
  14816. }
  14817. var position = geometry.attributes.position;
  14818. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  14819. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount );
  14820. } else {
  14821. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount );
  14822. }
  14823. }
  14824. this.setMode = setMode;
  14825. this.render = render;
  14826. this.renderInstances = renderInstances;
  14827. };
  14828. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  14829. /**
  14830. * @author mrdoob / http://mrdoob.com/
  14831. */
  14832. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  14833. var mode;
  14834. function setMode( value ) {
  14835. mode = value;
  14836. }
  14837. var type, size;
  14838. function setIndex( index ) {
  14839. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  14840. type = _gl.UNSIGNED_INT;
  14841. size = 4;
  14842. } else {
  14843. type = _gl.UNSIGNED_SHORT;
  14844. size = 2;
  14845. }
  14846. }
  14847. function render( start, count ) {
  14848. _gl.drawElements( mode, count, type, start * size );
  14849. _infoRender.calls ++;
  14850. _infoRender.vertices += count;
  14851. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  14852. }
  14853. function renderInstances( geometry ) {
  14854. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  14855. if ( extension === null ) {
  14856. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14857. return;
  14858. }
  14859. var index = geometry.index;
  14860. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount );
  14861. }
  14862. this.setMode = setMode;
  14863. this.setIndex = setIndex;
  14864. this.render = render;
  14865. this.renderInstances = renderInstances;
  14866. };
  14867. // File:src/renderers/webgl/WebGLExtensions.js
  14868. /**
  14869. * @author mrdoob / http://mrdoob.com/
  14870. */
  14871. THREE.WebGLExtensions = function ( gl ) {
  14872. var extensions = {};
  14873. this.get = function ( name ) {
  14874. if ( extensions[ name ] !== undefined ) {
  14875. return extensions[ name ];
  14876. }
  14877. var extension;
  14878. switch ( name ) {
  14879. case 'EXT_texture_filter_anisotropic':
  14880. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  14881. break;
  14882. case 'WEBGL_compressed_texture_s3tc':
  14883. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  14884. break;
  14885. case 'WEBGL_compressed_texture_pvrtc':
  14886. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  14887. break;
  14888. default:
  14889. extension = gl.getExtension( name );
  14890. }
  14891. if ( extension === null ) {
  14892. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  14893. }
  14894. extensions[ name ] = extension;
  14895. return extension;
  14896. };
  14897. };
  14898. // File:src/renderers/webgl/WebGLCapabilities.js
  14899. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  14900. function getMaxPrecision( precision ) {
  14901. if ( precision === 'highp' ) {
  14902. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  14903. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  14904. return 'highp';
  14905. }
  14906. precision = 'mediump';
  14907. }
  14908. if ( precision === 'mediump' ) {
  14909. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  14910. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  14911. return 'mediump';
  14912. }
  14913. }
  14914. return 'lowp';
  14915. }
  14916. this.getMaxPrecision = getMaxPrecision;
  14917. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  14918. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  14919. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14920. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  14921. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  14922. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  14923. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  14924. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  14925. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  14926. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  14927. this.vertexTextures = this.maxVertexTextures > 0;
  14928. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  14929. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  14930. var _maxPrecision = getMaxPrecision( this.precision );
  14931. if ( _maxPrecision !== this.precision ) {
  14932. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  14933. this.precision = _maxPrecision;
  14934. }
  14935. if ( this.logarithmicDepthBuffer ) {
  14936. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  14937. }
  14938. };
  14939. // File:src/renderers/webgl/WebGLGeometries.js
  14940. /**
  14941. * @author mrdoob / http://mrdoob.com/
  14942. */
  14943. THREE.WebGLGeometries = function ( gl, properties, info ) {
  14944. var geometries = {};
  14945. function get( object ) {
  14946. var geometry = object.geometry;
  14947. if ( geometries[ geometry.id ] !== undefined ) {
  14948. return geometries[ geometry.id ];
  14949. }
  14950. geometry.addEventListener( 'dispose', onGeometryDispose );
  14951. var buffergeometry;
  14952. if ( geometry instanceof THREE.BufferGeometry ) {
  14953. buffergeometry = geometry;
  14954. } else if ( geometry instanceof THREE.Geometry ) {
  14955. if ( geometry._bufferGeometry === undefined ) {
  14956. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  14957. }
  14958. buffergeometry = geometry._bufferGeometry;
  14959. }
  14960. geometries[ geometry.id ] = buffergeometry;
  14961. info.memory.geometries ++;
  14962. return buffergeometry;
  14963. }
  14964. function onGeometryDispose( event ) {
  14965. var geometry = event.target;
  14966. var buffergeometry = geometries[ geometry.id ];
  14967. deleteAttributes( buffergeometry.attributes );
  14968. geometry.removeEventListener( 'dispose', onGeometryDispose );
  14969. delete geometries[ geometry.id ];
  14970. var property = properties.get( geometry );
  14971. if ( property.wireframe ) deleteAttribute( property.wireframe );
  14972. info.memory.geometries --;
  14973. }
  14974. function getAttributeBuffer( attribute ) {
  14975. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14976. return properties.get( attribute.data ).__webglBuffer;
  14977. }
  14978. return properties.get( attribute ).__webglBuffer;
  14979. }
  14980. function deleteAttribute( attribute ) {
  14981. var buffer = getAttributeBuffer( attribute );
  14982. if ( buffer !== undefined ) {
  14983. gl.deleteBuffer( buffer );
  14984. removeAttributeBuffer( attribute );
  14985. }
  14986. }
  14987. function deleteAttributes( attributes ) {
  14988. for ( var name in attributes ) {
  14989. deleteAttribute( attributes[ name ] );
  14990. }
  14991. }
  14992. function removeAttributeBuffer( attribute ) {
  14993. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14994. properties.delete( attribute.data );
  14995. } else {
  14996. properties.delete( attribute );
  14997. }
  14998. }
  14999. this.get = get;
  15000. };
  15001. // File:src/renderers/webgl/WebGLObjects.js
  15002. /**
  15003. * @author mrdoob / http://mrdoob.com/
  15004. */
  15005. THREE.WebGLObjects = function ( gl, properties, info ) {
  15006. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  15007. //
  15008. function update( object ) {
  15009. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  15010. var geometry = geometries.get( object );
  15011. if ( object.geometry instanceof THREE.Geometry ) {
  15012. geometry.updateFromObject( object );
  15013. }
  15014. var index = geometry.index;
  15015. var attributes = geometry.attributes;
  15016. if ( index !== null ) {
  15017. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  15018. }
  15019. for ( var name in attributes ) {
  15020. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  15021. }
  15022. // morph targets
  15023. var morphAttributes = geometry.morphAttributes;
  15024. for ( var name in morphAttributes ) {
  15025. var array = morphAttributes[ name ];
  15026. for ( var i = 0, l = array.length; i < l; i ++ ) {
  15027. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  15028. }
  15029. }
  15030. return geometry;
  15031. }
  15032. function updateAttribute( attribute, bufferType ) {
  15033. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  15034. var attributeProperties = properties.get( data );
  15035. if ( attributeProperties.__webglBuffer === undefined ) {
  15036. createBuffer( attributeProperties, data, bufferType );
  15037. } else if ( attributeProperties.version !== data.version ) {
  15038. updateBuffer( attributeProperties, data, bufferType );
  15039. }
  15040. }
  15041. function createBuffer( attributeProperties, data, bufferType ) {
  15042. attributeProperties.__webglBuffer = gl.createBuffer();
  15043. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  15044. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  15045. gl.bufferData( bufferType, data.array, usage );
  15046. attributeProperties.version = data.version;
  15047. }
  15048. function updateBuffer( attributeProperties, data, bufferType ) {
  15049. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  15050. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  15051. // Not using update ranges
  15052. gl.bufferSubData( bufferType, 0, data.array );
  15053. } else if ( data.updateRange.count === 0 ) {
  15054. console.error( 'THREE.WebGLObjects.updateBuffer: dynamic THREE.BufferAttribute marked as needsUpdate but updateRange.count is 0, ensure you are using set methods or updating manually.' );
  15055. } else {
  15056. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  15057. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  15058. data.updateRange.count = 0; // reset range
  15059. }
  15060. attributeProperties.version = data.version;
  15061. }
  15062. function getAttributeBuffer( attribute ) {
  15063. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15064. return properties.get( attribute.data ).__webglBuffer;
  15065. }
  15066. return properties.get( attribute ).__webglBuffer;
  15067. }
  15068. function getWireframeAttribute( geometry ) {
  15069. var property = properties.get( geometry );
  15070. if ( property.wireframe !== undefined ) {
  15071. return property.wireframe;
  15072. }
  15073. var indices = [];
  15074. var index = geometry.index;
  15075. var attributes = geometry.attributes;
  15076. var position = attributes.position;
  15077. // console.time( 'wireframe' );
  15078. if ( index !== null ) {
  15079. var edges = {};
  15080. var array = index.array;
  15081. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  15082. var a = array[ i + 0 ];
  15083. var b = array[ i + 1 ];
  15084. var c = array[ i + 2 ];
  15085. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  15086. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  15087. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  15088. }
  15089. } else {
  15090. var array = attributes.position.array;
  15091. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  15092. var a = i + 0;
  15093. var b = i + 1;
  15094. var c = i + 2;
  15095. indices.push( a, b, b, c, c, a );
  15096. }
  15097. }
  15098. // console.timeEnd( 'wireframe' );
  15099. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  15100. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  15101. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  15102. property.wireframe = attribute;
  15103. return attribute;
  15104. }
  15105. function checkEdge( edges, a, b ) {
  15106. if ( a > b ) {
  15107. var tmp = a;
  15108. a = b;
  15109. b = tmp;
  15110. }
  15111. var list = edges[ a ];
  15112. if ( list === undefined ) {
  15113. edges[ a ] = [ b ];
  15114. return true;
  15115. } else if ( list.indexOf( b ) === -1 ) {
  15116. list.push( b );
  15117. return true;
  15118. }
  15119. return false;
  15120. }
  15121. this.getAttributeBuffer = getAttributeBuffer;
  15122. this.getWireframeAttribute = getWireframeAttribute;
  15123. this.update = update;
  15124. };
  15125. // File:src/renderers/webgl/WebGLProgram.js
  15126. THREE.WebGLProgram = ( function () {
  15127. var programIdCount = 0;
  15128. function generateDefines( defines ) {
  15129. var chunks = [];
  15130. for ( var name in defines ) {
  15131. var value = defines[ name ];
  15132. if ( value === false ) continue;
  15133. chunks.push( '#define ' + name + ' ' + value );
  15134. }
  15135. return chunks.join( '\n' );
  15136. }
  15137. function fetchUniformLocations( gl, program, identifiers ) {
  15138. var uniforms = {};
  15139. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  15140. for ( var i = 0; i < n; i ++ ) {
  15141. var info = gl.getActiveUniform( program, i );
  15142. var name = info.name;
  15143. var location = gl.getUniformLocation( program, name );
  15144. // console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  15145. var suffixPos = name.lastIndexOf( '[0]' );
  15146. if ( suffixPos !== - 1 && suffixPos === name.length - 3 ) {
  15147. uniforms[ name.substr( 0, suffixPos ) ] = location;
  15148. }
  15149. uniforms[ name ] = location;
  15150. }
  15151. return uniforms;
  15152. }
  15153. function fetchAttributeLocations( gl, program, identifiers ) {
  15154. var attributes = {};
  15155. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  15156. for ( var i = 0; i < n; i ++ ) {
  15157. var info = gl.getActiveAttrib( program, i );
  15158. var name = info.name;
  15159. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  15160. attributes[ name ] = gl.getAttribLocation( program, name );
  15161. }
  15162. return attributes;
  15163. }
  15164. function filterEmptyLine( string ) {
  15165. return string !== '';
  15166. }
  15167. return function WebGLProgram( renderer, code, material, parameters ) {
  15168. var gl = renderer.context;
  15169. var defines = material.defines;
  15170. var vertexShader = material.__webglShader.vertexShader;
  15171. var fragmentShader = material.__webglShader.fragmentShader;
  15172. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  15173. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  15174. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  15175. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  15176. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  15177. }
  15178. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  15179. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  15180. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  15181. if ( parameters.envMap ) {
  15182. switch ( material.envMap.mapping ) {
  15183. case THREE.CubeReflectionMapping:
  15184. case THREE.CubeRefractionMapping:
  15185. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  15186. break;
  15187. case THREE.EquirectangularReflectionMapping:
  15188. case THREE.EquirectangularRefractionMapping:
  15189. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  15190. break;
  15191. case THREE.SphericalReflectionMapping:
  15192. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  15193. break;
  15194. }
  15195. switch ( material.envMap.mapping ) {
  15196. case THREE.CubeRefractionMapping:
  15197. case THREE.EquirectangularRefractionMapping:
  15198. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  15199. break;
  15200. }
  15201. switch ( material.combine ) {
  15202. case THREE.MultiplyOperation:
  15203. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  15204. break;
  15205. case THREE.MixOperation:
  15206. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  15207. break;
  15208. case THREE.AddOperation:
  15209. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  15210. break;
  15211. }
  15212. }
  15213. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  15214. // console.log( 'building new program ' );
  15215. //
  15216. var customDefines = generateDefines( defines );
  15217. //
  15218. var program = gl.createProgram();
  15219. var prefixVertex, prefixFragment;
  15220. if ( material instanceof THREE.RawShaderMaterial ) {
  15221. prefixVertex = '';
  15222. prefixFragment = '';
  15223. } else {
  15224. prefixVertex = [
  15225. 'precision ' + parameters.precision + ' float;',
  15226. 'precision ' + parameters.precision + ' int;',
  15227. '#define SHADER_NAME ' + material.__webglShader.name,
  15228. customDefines,
  15229. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  15230. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  15231. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  15232. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  15233. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  15234. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  15235. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  15236. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  15237. '#define MAX_SHADOWS ' + parameters.maxShadows,
  15238. '#define MAX_BONES ' + parameters.maxBones,
  15239. parameters.map ? '#define USE_MAP' : '',
  15240. parameters.envMap ? '#define USE_ENVMAP' : '',
  15241. parameters.envMap ? '#define ' + envMapModeDefine : '',
  15242. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  15243. parameters.aoMap ? '#define USE_AOMAP' : '',
  15244. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  15245. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  15246. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  15247. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  15248. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  15249. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  15250. parameters.vertexColors ? '#define USE_COLOR' : '',
  15251. parameters.flatShading ? '#define FLAT_SHADED' : '',
  15252. parameters.skinning ? '#define USE_SKINNING' : '',
  15253. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  15254. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  15255. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  15256. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  15257. parameters.flipSided ? '#define FLIP_SIDED' : '',
  15258. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  15259. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  15260. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  15261. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  15262. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  15263. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  15264. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  15265. 'uniform mat4 modelMatrix;',
  15266. 'uniform mat4 modelViewMatrix;',
  15267. 'uniform mat4 projectionMatrix;',
  15268. 'uniform mat4 viewMatrix;',
  15269. 'uniform mat3 normalMatrix;',
  15270. 'uniform vec3 cameraPosition;',
  15271. 'attribute vec3 position;',
  15272. 'attribute vec3 normal;',
  15273. 'attribute vec2 uv;',
  15274. '#ifdef USE_COLOR',
  15275. ' attribute vec3 color;',
  15276. '#endif',
  15277. '#ifdef USE_MORPHTARGETS',
  15278. ' attribute vec3 morphTarget0;',
  15279. ' attribute vec3 morphTarget1;',
  15280. ' attribute vec3 morphTarget2;',
  15281. ' attribute vec3 morphTarget3;',
  15282. ' #ifdef USE_MORPHNORMALS',
  15283. ' attribute vec3 morphNormal0;',
  15284. ' attribute vec3 morphNormal1;',
  15285. ' attribute vec3 morphNormal2;',
  15286. ' attribute vec3 morphNormal3;',
  15287. ' #else',
  15288. ' attribute vec3 morphTarget4;',
  15289. ' attribute vec3 morphTarget5;',
  15290. ' attribute vec3 morphTarget6;',
  15291. ' attribute vec3 morphTarget7;',
  15292. ' #endif',
  15293. '#endif',
  15294. '#ifdef USE_SKINNING',
  15295. ' attribute vec4 skinIndex;',
  15296. ' attribute vec4 skinWeight;',
  15297. '#endif',
  15298. '\n'
  15299. ].filter( filterEmptyLine ).join( '\n' );
  15300. prefixFragment = [
  15301. parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ? '#extension GL_OES_standard_derivatives : enable' : '',
  15302. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  15303. 'precision ' + parameters.precision + ' float;',
  15304. 'precision ' + parameters.precision + ' int;',
  15305. '#define SHADER_NAME ' + material.__webglShader.name,
  15306. customDefines,
  15307. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  15308. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  15309. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  15310. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  15311. '#define MAX_SHADOWS ' + parameters.maxShadows,
  15312. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  15313. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  15314. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  15315. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  15316. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  15317. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  15318. parameters.map ? '#define USE_MAP' : '',
  15319. parameters.envMap ? '#define USE_ENVMAP' : '',
  15320. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  15321. parameters.envMap ? '#define ' + envMapModeDefine : '',
  15322. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  15323. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  15324. parameters.aoMap ? '#define USE_AOMAP' : '',
  15325. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  15326. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  15327. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  15328. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  15329. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  15330. parameters.vertexColors ? '#define USE_COLOR' : '',
  15331. parameters.flatShading ? '#define FLAT_SHADED' : '',
  15332. parameters.metal ? '#define METAL' : '',
  15333. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  15334. parameters.flipSided ? '#define FLIP_SIDED' : '',
  15335. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  15336. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  15337. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  15338. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  15339. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  15340. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  15341. 'uniform mat4 viewMatrix;',
  15342. 'uniform vec3 cameraPosition;',
  15343. '\n'
  15344. ].filter( filterEmptyLine ).join( '\n' );
  15345. }
  15346. var vertexGlsl = prefixVertex + vertexShader;
  15347. var fragmentGlsl = prefixFragment + fragmentShader;
  15348. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  15349. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  15350. gl.attachShader( program, glVertexShader );
  15351. gl.attachShader( program, glFragmentShader );
  15352. // Force a particular attribute to index 0.
  15353. if ( material.index0AttributeName !== undefined ) {
  15354. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  15355. } else if ( parameters.morphTargets === true ) {
  15356. // programs with morphTargets displace position out of attribute 0
  15357. gl.bindAttribLocation( program, 0, 'position' );
  15358. }
  15359. gl.linkProgram( program );
  15360. var programLog = gl.getProgramInfoLog( program );
  15361. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  15362. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  15363. var runnable = true;
  15364. var haveDiagnostics = true;
  15365. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  15366. runnable = false;
  15367. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  15368. } else if ( programLog !== '' ) {
  15369. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  15370. } else if ( vertexLog === '' || fragmentLog === '' ) {
  15371. haveDiagnostics = false;
  15372. }
  15373. if ( haveDiagnostics ) {
  15374. this.diagnostics = {
  15375. runnable: runnable,
  15376. material: material,
  15377. programLog: programLog,
  15378. vertexShader: {
  15379. log: vertexLog,
  15380. prefix: prefixVertex
  15381. },
  15382. fragmentShader: {
  15383. log: fragmentLog,
  15384. prefix: prefixFragment
  15385. }
  15386. };
  15387. }
  15388. // clean up
  15389. gl.deleteShader( glVertexShader );
  15390. gl.deleteShader( glFragmentShader );
  15391. // set up caching for uniform locations
  15392. var cachedUniforms;
  15393. this.getUniforms = function() {
  15394. if ( cachedUniforms === undefined ) {
  15395. cachedUniforms = fetchUniformLocations( gl, program );
  15396. }
  15397. return cachedUniforms;
  15398. };
  15399. // set up caching for attribute locations
  15400. var cachedAttributes;
  15401. this.getAttributes = function() {
  15402. if ( cachedAttributes === undefined ) {
  15403. cachedAttributes = fetchAttributeLocations( gl, program );
  15404. }
  15405. return cachedAttributes;
  15406. };
  15407. // free resource
  15408. this.destroy = function() {
  15409. gl.deleteProgram( program );
  15410. this.program = undefined;
  15411. };
  15412. // DEPRECATED
  15413. Object.defineProperties( this, {
  15414. uniforms: {
  15415. get: function() {
  15416. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  15417. return this.getUniforms();
  15418. }
  15419. },
  15420. attributes: {
  15421. get: function() {
  15422. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  15423. return this.getAttributes();
  15424. }
  15425. }
  15426. } );
  15427. //
  15428. this.id = programIdCount ++;
  15429. this.code = code;
  15430. this.usedTimes = 1;
  15431. this.program = program;
  15432. this.vertexShader = glVertexShader;
  15433. this.fragmentShader = glFragmentShader;
  15434. return this;
  15435. };
  15436. } )();
  15437. // File:src/renderers/webgl/WebGLPrograms.js
  15438. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  15439. var programs = [];
  15440. var shaderIDs = {
  15441. MeshDepthMaterial: 'depth',
  15442. MeshNormalMaterial: 'normal',
  15443. MeshBasicMaterial: 'basic',
  15444. MeshLambertMaterial: 'lambert',
  15445. MeshPhongMaterial: 'phong',
  15446. LineBasicMaterial: 'basic',
  15447. LineDashedMaterial: 'dashed',
  15448. PointsMaterial: 'points'
  15449. };
  15450. var parameterNames = [
  15451. "precision", "supportsVertexTextures", "map", "envMap", "envMapMode",
  15452. "lightMap", "aoMap", "emissiveMap", "bumpMap", "normalMap", "specularMap",
  15453. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  15454. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  15455. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  15456. "maxMorphTargets", "maxMorphNormals", "maxDirLights", "maxPointLights",
  15457. "maxSpotLights", "maxHemiLights", "maxShadows", "shadowMapEnabled", "pointLightShadows",
  15458. "shadowMapType", "shadowMapDebug", "alphaTest", "metal", "doubleSided",
  15459. "flipSided"
  15460. ];
  15461. function allocateBones ( object ) {
  15462. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  15463. return 1024;
  15464. } else {
  15465. // default for when object is not specified
  15466. // ( for example when prebuilding shader to be used with multiple objects )
  15467. //
  15468. // - leave some extra space for other uniforms
  15469. // - limit here is ANGLE's 254 max uniform vectors
  15470. // (up to 54 should be safe)
  15471. var nVertexUniforms = capabilities.maxVertexUniforms;
  15472. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  15473. var maxBones = nVertexMatrices;
  15474. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  15475. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  15476. if ( maxBones < object.skeleton.bones.length ) {
  15477. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  15478. }
  15479. }
  15480. return maxBones;
  15481. }
  15482. }
  15483. function allocateLights( lights ) {
  15484. var dirLights = 0;
  15485. var pointLights = 0;
  15486. var spotLights = 0;
  15487. var hemiLights = 0;
  15488. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  15489. var light = lights[ l ];
  15490. if ( light.onlyShadow || light.visible === false ) continue;
  15491. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  15492. if ( light instanceof THREE.PointLight ) pointLights ++;
  15493. if ( light instanceof THREE.SpotLight ) spotLights ++;
  15494. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  15495. }
  15496. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  15497. }
  15498. function allocateShadows( lights ) {
  15499. var maxShadows = 0;
  15500. var pointLightShadows = 0;
  15501. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  15502. var light = lights[ l ];
  15503. if ( ! light.castShadow ) continue;
  15504. if ( light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) maxShadows ++;
  15505. if ( light instanceof THREE.PointLight ) {
  15506. maxShadows ++;
  15507. pointLightShadows ++;
  15508. }
  15509. }
  15510. return { 'maxShadows': maxShadows, 'pointLightShadows': pointLightShadows };
  15511. }
  15512. this.getParameters = function ( material, lights, fog, object ) {
  15513. var shaderID = shaderIDs[ material.type ];
  15514. // heuristics to create shader parameters according to lights in the scene
  15515. // (not to blow over maxLights budget)
  15516. var maxLightCount = allocateLights( lights );
  15517. var allocatedShadows = allocateShadows( lights );
  15518. var maxBones = allocateBones( object );
  15519. var precision = renderer.getPrecision();
  15520. if ( material.precision !== null ) {
  15521. precision = capabilities.getMaxPrecision( material.precision );
  15522. if ( precision !== material.precision ) {
  15523. console.warn( 'THREE.WebGLRenderer.initMaterial:', material.precision, 'not supported, using', precision, 'instead.' );
  15524. }
  15525. }
  15526. var parameters = {
  15527. shaderID: shaderID,
  15528. precision: precision,
  15529. supportsVertexTextures: capabilities.vertexTextures,
  15530. map: !! material.map,
  15531. envMap: !! material.envMap,
  15532. envMapMode: material.envMap && material.envMap.mapping,
  15533. lightMap: !! material.lightMap,
  15534. aoMap: !! material.aoMap,
  15535. emissiveMap: !! material.emissiveMap,
  15536. bumpMap: !! material.bumpMap,
  15537. normalMap: !! material.normalMap,
  15538. displacementMap: !! material.displacementMap,
  15539. specularMap: !! material.specularMap,
  15540. alphaMap: !! material.alphaMap,
  15541. combine: material.combine,
  15542. vertexColors: material.vertexColors,
  15543. fog: fog,
  15544. useFog: material.fog,
  15545. fogExp: fog instanceof THREE.FogExp2,
  15546. flatShading: material.shading === THREE.FlatShading,
  15547. sizeAttenuation: material.sizeAttenuation,
  15548. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  15549. skinning: material.skinning,
  15550. maxBones: maxBones,
  15551. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  15552. morphTargets: material.morphTargets,
  15553. morphNormals: material.morphNormals,
  15554. maxMorphTargets: renderer.maxMorphTargets,
  15555. maxMorphNormals: renderer.maxMorphNormals,
  15556. maxDirLights: maxLightCount.directional,
  15557. maxPointLights: maxLightCount.point,
  15558. maxSpotLights: maxLightCount.spot,
  15559. maxHemiLights: maxLightCount.hemi,
  15560. maxShadows: allocatedShadows.maxShadows,
  15561. pointLightShadows: allocatedShadows.pointLightShadows,
  15562. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && allocatedShadows.maxShadows > 0,
  15563. shadowMapType: renderer.shadowMap.type,
  15564. shadowMapDebug: renderer.shadowMap.debug,
  15565. alphaTest: material.alphaTest,
  15566. metal: material.metal,
  15567. doubleSided: material.side === THREE.DoubleSide,
  15568. flipSided: material.side === THREE.BackSide
  15569. };
  15570. return parameters;
  15571. };
  15572. this.getProgramCode = function ( material, parameters ) {
  15573. var chunks = [];
  15574. if ( parameters.shaderID ) {
  15575. chunks.push( parameters.shaderID );
  15576. } else {
  15577. chunks.push( material.fragmentShader );
  15578. chunks.push( material.vertexShader );
  15579. }
  15580. if ( material.defines !== undefined ) {
  15581. for ( var name in material.defines ) {
  15582. chunks.push( name );
  15583. chunks.push( material.defines[ name ] );
  15584. }
  15585. }
  15586. for ( var i = 0; i < parameterNames.length; i ++ ) {
  15587. var parameterName = parameterNames[ i ];
  15588. chunks.push( parameterName );
  15589. chunks.push( parameters[ parameterName ] );
  15590. }
  15591. return chunks.join();
  15592. };
  15593. this.acquireProgram = function ( material, parameters, code ) {
  15594. var program;
  15595. // Check if code has been already compiled
  15596. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  15597. var programInfo = programs[ p ];
  15598. if ( programInfo.code === code ) {
  15599. program = programInfo;
  15600. ++ program.usedTimes;
  15601. break;
  15602. }
  15603. }
  15604. if ( program === undefined ) {
  15605. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  15606. programs.push( program );
  15607. }
  15608. return program;
  15609. };
  15610. this.releaseProgram = function( program ) {
  15611. if ( -- program.usedTimes === 0 ) {
  15612. // Remove from unordered set
  15613. var i = programs.indexOf( program );
  15614. programs[ i ] = programs[ programs.length - 1 ];
  15615. programs.pop();
  15616. // Free WebGL resources
  15617. program.destroy();
  15618. }
  15619. };
  15620. // Exposed for resource monitoring & error feedback via renderer.info:
  15621. this.programs = programs;
  15622. };
  15623. // File:src/renderers/webgl/WebGLProperties.js
  15624. /**
  15625. * @author fordacious / fordacious.github.io
  15626. */
  15627. THREE.WebGLProperties = function () {
  15628. var properties = {};
  15629. this.get = function ( object ) {
  15630. var uuid = object.uuid;
  15631. var map = properties[ uuid ];
  15632. if ( map === undefined ) {
  15633. map = {};
  15634. properties[ uuid ] = map;
  15635. }
  15636. return map;
  15637. };
  15638. this.delete = function ( object ) {
  15639. delete properties[ object.uuid ];
  15640. };
  15641. this.clear = function () {
  15642. properties = {};
  15643. };
  15644. };
  15645. // File:src/renderers/webgl/WebGLShader.js
  15646. THREE.WebGLShader = ( function () {
  15647. var addLineNumbers = function ( string ) {
  15648. var lines = string.split( '\n' );
  15649. for ( var i = 0; i < lines.length; i ++ ) {
  15650. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  15651. }
  15652. return lines.join( '\n' );
  15653. };
  15654. return function WebGLShader( gl, type, string ) {
  15655. var shader = gl.createShader( type );
  15656. gl.shaderSource( shader, string );
  15657. gl.compileShader( shader );
  15658. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  15659. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  15660. }
  15661. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  15662. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  15663. }
  15664. // --enable-privileged-webgl-extension
  15665. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  15666. return shader;
  15667. };
  15668. } )();
  15669. // File:src/renderers/webgl/WebGLShadowMap.js
  15670. /**
  15671. * @author alteredq / http://alteredqualia.com/
  15672. * @author mrdoob / http://mrdoob.com/
  15673. */
  15674. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  15675. var _gl = _renderer.context,
  15676. _state = _renderer.state,
  15677. _frustum = new THREE.Frustum(),
  15678. _projScreenMatrix = new THREE.Matrix4(),
  15679. _min = new THREE.Vector3(),
  15680. _max = new THREE.Vector3(),
  15681. _lookTarget = new THREE.Vector3(),
  15682. _lightPositionWorld = new THREE.Vector3(),
  15683. _renderList = [],
  15684. _MorphingFlag = 1,
  15685. _SkinningFlag = 2,
  15686. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  15687. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  15688. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  15689. var cubeDirections = [
  15690. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  15691. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  15692. ];
  15693. var cubeUps = [
  15694. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  15695. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  15696. ];
  15697. var cube2DViewPorts = [
  15698. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  15699. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  15700. ];
  15701. var _vector4 = new THREE.Vector4();
  15702. // init
  15703. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  15704. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  15705. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  15706. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  15707. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  15708. var useMorphing = ( i & _MorphingFlag ) !== 0;
  15709. var useSkinning = ( i & _SkinningFlag ) !== 0;
  15710. var depthMaterial = new THREE.ShaderMaterial( {
  15711. uniforms: depthUniforms,
  15712. vertexShader: depthShader.vertexShader,
  15713. fragmentShader: depthShader.fragmentShader,
  15714. morphTargets: useMorphing,
  15715. skinning: useSkinning
  15716. } );
  15717. depthMaterial._shadowPass = true;
  15718. _depthMaterials[ i ] = depthMaterial;
  15719. var distanceMaterial = new THREE.ShaderMaterial( {
  15720. uniforms: distanceUniforms,
  15721. vertexShader: distanceShader.vertexShader,
  15722. fragmentShader: distanceShader.fragmentShader,
  15723. morphTargets: useMorphing,
  15724. skinning: useSkinning
  15725. } );
  15726. distanceMaterial._shadowPass = true;
  15727. _distanceMaterials[ i ] = distanceMaterial;
  15728. }
  15729. //
  15730. var scope = this;
  15731. this.enabled = false;
  15732. this.autoUpdate = true;
  15733. this.needsUpdate = false;
  15734. this.type = THREE.PCFShadowMap;
  15735. this.cullFace = THREE.CullFaceFront;
  15736. this.render = function ( scene ) {
  15737. var faceCount, isPointLight;
  15738. if ( scope.enabled === false ) return;
  15739. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  15740. // set GL state for depth map
  15741. _gl.clearColor( 1, 1, 1, 1 );
  15742. _state.disable( _gl.BLEND );
  15743. _state.enable( _gl.CULL_FACE );
  15744. _gl.frontFace( _gl.CCW );
  15745. if ( scope.cullFace === THREE.CullFaceFront ) {
  15746. _gl.cullFace( _gl.FRONT );
  15747. } else {
  15748. _gl.cullFace( _gl.BACK );
  15749. }
  15750. _state.setDepthTest( true );
  15751. // render depth map
  15752. for ( var i = 0, il = _lights.length; i < il; i ++ ) {
  15753. var light = _lights[ i ];
  15754. if ( light instanceof THREE.PointLight ) {
  15755. faceCount = 6;
  15756. isPointLight = true;
  15757. var vpWidth = light.shadowMapWidth / 4.0;
  15758. var vpHeight = light.shadowMapHeight / 2.0;
  15759. // These viewports map a cube-map onto a 2D texture with the
  15760. // following orientation:
  15761. //
  15762. // xzXZ
  15763. // y Y
  15764. //
  15765. // X - Positive x direction
  15766. // x - Negative x direction
  15767. // Y - Positive y direction
  15768. // y - Negative y direction
  15769. // Z - Positive z direction
  15770. // z - Negative z direction
  15771. // positive X
  15772. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  15773. // negative X
  15774. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  15775. // positive Z
  15776. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  15777. // negative Z
  15778. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  15779. // positive Y
  15780. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  15781. // negative Y
  15782. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  15783. } else {
  15784. faceCount = 1;
  15785. isPointLight = false;
  15786. }
  15787. if ( ! light.castShadow ) continue;
  15788. if ( ! light.shadowMap ) {
  15789. var shadowFilter = THREE.LinearFilter;
  15790. if ( scope.type === THREE.PCFSoftShadowMap ) {
  15791. shadowFilter = THREE.NearestFilter;
  15792. }
  15793. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  15794. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  15795. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  15796. light.shadowMatrix = new THREE.Matrix4();
  15797. }
  15798. if ( ! light.shadowCamera ) {
  15799. if ( light instanceof THREE.SpotLight ) {
  15800. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  15801. } else if ( light instanceof THREE.DirectionalLight ) {
  15802. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  15803. } else {
  15804. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, 1.0, light.shadowCameraNear, light.shadowCameraFar );
  15805. }
  15806. scene.add( light.shadowCamera );
  15807. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15808. }
  15809. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  15810. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  15811. scene.add( light.cameraHelper );
  15812. }
  15813. var shadowMap = light.shadowMap;
  15814. var shadowMatrix = light.shadowMatrix;
  15815. var shadowCamera = light.shadowCamera;
  15816. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  15817. shadowCamera.position.copy( _lightPositionWorld );
  15818. // save the existing viewport so it can be restored later
  15819. _renderer.getViewport( _vector4 );
  15820. _renderer.setRenderTarget( shadowMap );
  15821. _renderer.clear();
  15822. // render shadow map for each cube face (if omni-directional) or
  15823. // run a single pass if not
  15824. for ( var face = 0; face < faceCount; face ++ ) {
  15825. if ( isPointLight ) {
  15826. _lookTarget.copy( shadowCamera.position );
  15827. _lookTarget.add( cubeDirections[ face ] );
  15828. shadowCamera.up.copy( cubeUps[ face ] );
  15829. shadowCamera.lookAt( _lookTarget );
  15830. var vpDimensions = cube2DViewPorts[ face ];
  15831. _renderer.setViewport( vpDimensions.x, vpDimensions.y, vpDimensions.z, vpDimensions.w );
  15832. } else {
  15833. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  15834. shadowCamera.lookAt( _lookTarget );
  15835. }
  15836. shadowCamera.updateMatrixWorld();
  15837. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  15838. if ( light.cameraHelper ) light.cameraHelper.visible = light.shadowCameraVisible;
  15839. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  15840. // compute shadow matrix
  15841. shadowMatrix.set(
  15842. 0.5, 0.0, 0.0, 0.5,
  15843. 0.0, 0.5, 0.0, 0.5,
  15844. 0.0, 0.0, 0.5, 0.5,
  15845. 0.0, 0.0, 0.0, 1.0
  15846. );
  15847. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  15848. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  15849. // update camera matrices and frustum
  15850. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  15851. _frustum.setFromMatrix( _projScreenMatrix );
  15852. // set object matrices & frustum culling
  15853. _renderList.length = 0;
  15854. projectObject( scene, shadowCamera );
  15855. // render shadow map
  15856. // render regular objects
  15857. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  15858. var object = _renderList[ j ];
  15859. var geometry = _objects.update( object );
  15860. var material = object.material;
  15861. if ( material instanceof THREE.MeshFaceMaterial ) {
  15862. var groups = geometry.groups;
  15863. var materials = material.materials;
  15864. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  15865. var group = groups[ k ];
  15866. var groupMaterial = materials[ group.materialIndex ];
  15867. if ( groupMaterial.visible === true ) {
  15868. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  15869. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, group );
  15870. }
  15871. }
  15872. } else {
  15873. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  15874. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, null );
  15875. }
  15876. }
  15877. }
  15878. }
  15879. // restore GL state
  15880. var clearColor = _renderer.getClearColor(),
  15881. clearAlpha = _renderer.getClearAlpha();
  15882. _renderer.setClearColor( clearColor, clearAlpha );
  15883. _state.enable( _gl.BLEND );
  15884. if ( scope.cullFace === THREE.CullFaceFront ) {
  15885. _gl.cullFace( _gl.BACK );
  15886. }
  15887. _renderer.setViewport( _vector4.x, _vector4.y, _vector4.z, _vector4.w );
  15888. _renderer.resetGLState();
  15889. scope.needsUpdate = false;
  15890. };
  15891. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  15892. var geometry = object.geometry;
  15893. var newMaterial = null;
  15894. var materialVariants = _depthMaterials;
  15895. var customMaterial = object.customDepthMaterial;
  15896. if ( isPointLight ) {
  15897. materialVariants = _distanceMaterials;
  15898. customMaterial = object.customDistanceMaterial;
  15899. }
  15900. if ( ! customMaterial ) {
  15901. var useMorphing = geometry.morphTargets !== undefined &&
  15902. geometry.morphTargets.length > 0 && material.morphTargets;
  15903. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  15904. var variantIndex = 0;
  15905. if ( useMorphing ) variantIndex |= _MorphingFlag;
  15906. if ( useSkinning ) variantIndex |= _SkinningFlag;
  15907. newMaterial = materialVariants[ variantIndex ];
  15908. } else {
  15909. newMaterial = customMaterial;
  15910. }
  15911. newMaterial.visible = material.visible;
  15912. newMaterial.wireframe = material.wireframe;
  15913. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  15914. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  15915. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  15916. }
  15917. return newMaterial;
  15918. }
  15919. function projectObject( object, camera ) {
  15920. if ( object.visible === false ) return;
  15921. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15922. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  15923. var material = object.material;
  15924. if ( material.visible === true ) {
  15925. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15926. _renderList.push( object );
  15927. }
  15928. }
  15929. }
  15930. var children = object.children;
  15931. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15932. projectObject( children[ i ], camera );
  15933. }
  15934. }
  15935. };
  15936. // File:src/renderers/webgl/WebGLState.js
  15937. /**
  15938. * @author mrdoob / http://mrdoob.com/
  15939. */
  15940. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  15941. var _this = this;
  15942. var newAttributes = new Uint8Array( 16 );
  15943. var enabledAttributes = new Uint8Array( 16 );
  15944. var attributeDivisors = new Uint8Array( 16 );
  15945. var capabilities = {};
  15946. var compressedTextureFormats = null;
  15947. var currentBlending = null;
  15948. var currentBlendEquation = null;
  15949. var currentBlendSrc = null;
  15950. var currentBlendDst = null;
  15951. var currentBlendEquationAlpha = null;
  15952. var currentBlendSrcAlpha = null;
  15953. var currentBlendDstAlpha = null;
  15954. var currentDepthFunc = null;
  15955. var currentDepthWrite = null;
  15956. var currentColorWrite = null;
  15957. var currentFlipSided = null;
  15958. var currentLineWidth = null;
  15959. var currentPolygonOffsetFactor = null;
  15960. var currentPolygonOffsetUnits = null;
  15961. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  15962. var currentTextureSlot = undefined;
  15963. var currentBoundTextures = {};
  15964. this.init = function () {
  15965. gl.clearColor( 0, 0, 0, 1 );
  15966. gl.clearDepth( 1 );
  15967. gl.clearStencil( 0 );
  15968. this.enable( gl.DEPTH_TEST );
  15969. gl.depthFunc( gl.LEQUAL );
  15970. gl.frontFace( gl.CCW );
  15971. gl.cullFace( gl.BACK );
  15972. this.enable( gl.CULL_FACE );
  15973. this.enable( gl.BLEND );
  15974. gl.blendEquation( gl.FUNC_ADD );
  15975. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  15976. };
  15977. this.initAttributes = function () {
  15978. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  15979. newAttributes[ i ] = 0;
  15980. }
  15981. };
  15982. this.enableAttribute = function ( attribute ) {
  15983. newAttributes[ attribute ] = 1;
  15984. if ( enabledAttributes[ attribute ] === 0 ) {
  15985. gl.enableVertexAttribArray( attribute );
  15986. enabledAttributes[ attribute ] = 1;
  15987. }
  15988. if ( attributeDivisors[ attribute ] !== 0 ) {
  15989. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  15990. extension.vertexAttribDivisorANGLE( attribute, 0 );
  15991. attributeDivisors[ attribute ] = 0;
  15992. }
  15993. };
  15994. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  15995. newAttributes[ attribute ] = 1;
  15996. if ( enabledAttributes[ attribute ] === 0 ) {
  15997. gl.enableVertexAttribArray( attribute );
  15998. enabledAttributes[ attribute ] = 1;
  15999. }
  16000. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  16001. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  16002. attributeDivisors[ attribute ] = meshPerAttribute;
  16003. }
  16004. };
  16005. this.disableUnusedAttributes = function () {
  16006. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  16007. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  16008. gl.disableVertexAttribArray( i );
  16009. enabledAttributes[ i ] = 0;
  16010. }
  16011. }
  16012. };
  16013. this.enable = function ( id ) {
  16014. if ( capabilities[ id ] !== true ) {
  16015. gl.enable( id );
  16016. capabilities[ id ] = true;
  16017. }
  16018. };
  16019. this.disable = function ( id ) {
  16020. if ( capabilities[ id ] !== false ) {
  16021. gl.disable( id );
  16022. capabilities[ id ] = false;
  16023. }
  16024. };
  16025. this.getCompressedTextureFormats = function () {
  16026. if ( compressedTextureFormats === null ) {
  16027. compressedTextureFormats = [];
  16028. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  16029. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  16030. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  16031. for ( var i = 0; i < formats.length; i ++ ) {
  16032. compressedTextureFormats.push( formats[ i ] );
  16033. }
  16034. }
  16035. }
  16036. return compressedTextureFormats;
  16037. };
  16038. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  16039. if ( blending !== currentBlending ) {
  16040. if ( blending === THREE.NoBlending ) {
  16041. this.disable( gl.BLEND );
  16042. } else if ( blending === THREE.AdditiveBlending ) {
  16043. this.enable( gl.BLEND );
  16044. gl.blendEquation( gl.FUNC_ADD );
  16045. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  16046. } else if ( blending === THREE.SubtractiveBlending ) {
  16047. // TODO: Find blendFuncSeparate() combination
  16048. this.enable( gl.BLEND );
  16049. gl.blendEquation( gl.FUNC_ADD );
  16050. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  16051. } else if ( blending === THREE.MultiplyBlending ) {
  16052. // TODO: Find blendFuncSeparate() combination
  16053. this.enable( gl.BLEND );
  16054. gl.blendEquation( gl.FUNC_ADD );
  16055. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  16056. } else if ( blending === THREE.CustomBlending ) {
  16057. this.enable( gl.BLEND );
  16058. } else {
  16059. this.enable( gl.BLEND );
  16060. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  16061. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  16062. }
  16063. currentBlending = blending;
  16064. }
  16065. if ( blending === THREE.CustomBlending ) {
  16066. blendEquationAlpha = blendEquationAlpha || blendEquation;
  16067. blendSrcAlpha = blendSrcAlpha || blendSrc;
  16068. blendDstAlpha = blendDstAlpha || blendDst;
  16069. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  16070. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  16071. currentBlendEquation = blendEquation;
  16072. currentBlendEquationAlpha = blendEquationAlpha;
  16073. }
  16074. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  16075. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  16076. currentBlendSrc = blendSrc;
  16077. currentBlendDst = blendDst;
  16078. currentBlendSrcAlpha = blendSrcAlpha;
  16079. currentBlendDstAlpha = blendDstAlpha;
  16080. }
  16081. } else {
  16082. currentBlendEquation = null;
  16083. currentBlendSrc = null;
  16084. currentBlendDst = null;
  16085. currentBlendEquationAlpha = null;
  16086. currentBlendSrcAlpha = null;
  16087. currentBlendDstAlpha = null;
  16088. }
  16089. };
  16090. this.setDepthFunc = function ( depthFunc ) {
  16091. if ( currentDepthFunc !== depthFunc ) {
  16092. if ( depthFunc ) {
  16093. switch ( depthFunc ) {
  16094. case THREE.NeverDepth:
  16095. gl.depthFunc( gl.NEVER );
  16096. break;
  16097. case THREE.AlwaysDepth:
  16098. gl.depthFunc( gl.ALWAYS );
  16099. break;
  16100. case THREE.LessDepth:
  16101. gl.depthFunc( gl.LESS );
  16102. break;
  16103. case THREE.LessEqualDepth:
  16104. gl.depthFunc( gl.LEQUAL );
  16105. break;
  16106. case THREE.EqualDepth:
  16107. gl.depthFunc( gl.EQUAL );
  16108. break;
  16109. case THREE.GreaterEqualDepth:
  16110. gl.depthFunc( gl.GEQUAL );
  16111. break;
  16112. case THREE.GreaterDepth:
  16113. gl.depthFunc( gl.GREATER );
  16114. break;
  16115. case THREE.NotEqualDepth:
  16116. gl.depthFunc( gl.NOTEQUAL );
  16117. break;
  16118. default:
  16119. gl.depthFunc( gl.LEQUAL );
  16120. }
  16121. } else {
  16122. gl.depthFunc( gl.LEQUAL );
  16123. }
  16124. currentDepthFunc = depthFunc;
  16125. }
  16126. };
  16127. this.setDepthTest = function ( depthTest ) {
  16128. if ( depthTest ) {
  16129. this.enable( gl.DEPTH_TEST );
  16130. } else {
  16131. this.disable( gl.DEPTH_TEST );
  16132. }
  16133. };
  16134. this.setDepthWrite = function ( depthWrite ) {
  16135. if ( currentDepthWrite !== depthWrite ) {
  16136. gl.depthMask( depthWrite );
  16137. currentDepthWrite = depthWrite;
  16138. }
  16139. };
  16140. this.setColorWrite = function ( colorWrite ) {
  16141. if ( currentColorWrite !== colorWrite ) {
  16142. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  16143. currentColorWrite = colorWrite;
  16144. }
  16145. };
  16146. this.setFlipSided = function ( flipSided ) {
  16147. if ( currentFlipSided !== flipSided ) {
  16148. if ( flipSided ) {
  16149. gl.frontFace( gl.CW );
  16150. } else {
  16151. gl.frontFace( gl.CCW );
  16152. }
  16153. currentFlipSided = flipSided;
  16154. }
  16155. };
  16156. this.setLineWidth = function ( width ) {
  16157. if ( width !== currentLineWidth ) {
  16158. gl.lineWidth( width );
  16159. currentLineWidth = width;
  16160. }
  16161. };
  16162. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  16163. if ( polygonOffset ) {
  16164. this.enable( gl.POLYGON_OFFSET_FILL );
  16165. } else {
  16166. this.disable( gl.POLYGON_OFFSET_FILL );
  16167. }
  16168. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  16169. gl.polygonOffset( factor, units );
  16170. currentPolygonOffsetFactor = factor;
  16171. currentPolygonOffsetUnits = units;
  16172. }
  16173. };
  16174. this.setScissorTest = function ( scissorTest ) {
  16175. if ( scissorTest ) {
  16176. this.enable( gl.SCISSOR_TEST );
  16177. } else {
  16178. this.disable( gl.SCISSOR_TEST );
  16179. }
  16180. };
  16181. // texture
  16182. this.activeTexture = function ( webglSlot ) {
  16183. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  16184. if ( currentTextureSlot !== webglSlot ) {
  16185. gl.activeTexture( webglSlot );
  16186. currentTextureSlot = webglSlot;
  16187. }
  16188. }
  16189. this.bindTexture = function ( webglType, webglTexture ) {
  16190. if ( currentTextureSlot === undefined ) {
  16191. _this.activeTexture();
  16192. }
  16193. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  16194. if ( boundTexture === undefined ) {
  16195. boundTexture = { type: undefined, texture: undefined };
  16196. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  16197. }
  16198. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  16199. gl.bindTexture( webglType, webglTexture );
  16200. boundTexture.type = webglType;
  16201. boundTexture.texture = webglTexture;
  16202. }
  16203. };
  16204. this.compressedTexImage2D = function () {
  16205. try {
  16206. gl.compressedTexImage2D.apply( gl, arguments );
  16207. } catch ( error ) {
  16208. console.error( error );
  16209. }
  16210. };
  16211. this.texImage2D = function () {
  16212. try {
  16213. gl.texImage2D.apply( gl, arguments );
  16214. } catch ( error ) {
  16215. console.error( error );
  16216. }
  16217. };
  16218. //
  16219. this.reset = function () {
  16220. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  16221. if ( enabledAttributes[ i ] === 1 ) {
  16222. gl.disableVertexAttribArray( i );
  16223. enabledAttributes[ i ] = 0;
  16224. }
  16225. }
  16226. capabilities = {};
  16227. compressedTextureFormats = null;
  16228. currentBlending = null;
  16229. currentDepthWrite = null;
  16230. currentColorWrite = null;
  16231. currentFlipSided = null;
  16232. };
  16233. };
  16234. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  16235. /**
  16236. * @author mikael emtinger / http://gomo.se/
  16237. * @author alteredq / http://alteredqualia.com/
  16238. */
  16239. THREE.LensFlarePlugin = function ( renderer, flares ) {
  16240. var gl = renderer.context;
  16241. var state = renderer.state;
  16242. var vertexBuffer, elementBuffer;
  16243. var program, attributes, uniforms;
  16244. var hasVertexTexture;
  16245. var tempTexture, occlusionTexture;
  16246. var init = function () {
  16247. var vertices = new Float32Array( [
  16248. - 1, - 1, 0, 0,
  16249. 1, - 1, 1, 0,
  16250. 1, 1, 1, 1,
  16251. - 1, 1, 0, 1
  16252. ] );
  16253. var faces = new Uint16Array( [
  16254. 0, 1, 2,
  16255. 0, 2, 3
  16256. ] );
  16257. // buffers
  16258. vertexBuffer = gl.createBuffer();
  16259. elementBuffer = gl.createBuffer();
  16260. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16261. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  16262. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16263. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  16264. // textures
  16265. tempTexture = gl.createTexture();
  16266. occlusionTexture = gl.createTexture();
  16267. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16268. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  16269. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  16270. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  16271. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  16272. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  16273. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  16274. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  16275. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  16276. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  16277. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  16278. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  16279. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  16280. var shader;
  16281. if ( hasVertexTexture ) {
  16282. shader = {
  16283. vertexShader: [
  16284. "uniform lowp int renderType;",
  16285. "uniform vec3 screenPosition;",
  16286. "uniform vec2 scale;",
  16287. "uniform float rotation;",
  16288. "uniform sampler2D occlusionMap;",
  16289. "attribute vec2 position;",
  16290. "attribute vec2 uv;",
  16291. "varying vec2 vUV;",
  16292. "varying float vVisibility;",
  16293. "void main() {",
  16294. "vUV = uv;",
  16295. "vec2 pos = position;",
  16296. "if( renderType == 2 ) {",
  16297. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  16298. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  16299. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  16300. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  16301. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  16302. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  16303. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  16304. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  16305. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  16306. "vVisibility = visibility.r / 9.0;",
  16307. "vVisibility *= 1.0 - visibility.g / 9.0;",
  16308. "vVisibility *= visibility.b / 9.0;",
  16309. "vVisibility *= 1.0 - visibility.a / 9.0;",
  16310. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  16311. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  16312. "}",
  16313. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  16314. "}"
  16315. ].join( "\n" ),
  16316. fragmentShader: [
  16317. "uniform lowp int renderType;",
  16318. "uniform sampler2D map;",
  16319. "uniform float opacity;",
  16320. "uniform vec3 color;",
  16321. "varying vec2 vUV;",
  16322. "varying float vVisibility;",
  16323. "void main() {",
  16324. // pink square
  16325. "if( renderType == 0 ) {",
  16326. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  16327. // restore
  16328. "} else if( renderType == 1 ) {",
  16329. "gl_FragColor = texture2D( map, vUV );",
  16330. // flare
  16331. "} else {",
  16332. "vec4 texture = texture2D( map, vUV );",
  16333. "texture.a *= opacity * vVisibility;",
  16334. "gl_FragColor = texture;",
  16335. "gl_FragColor.rgb *= color;",
  16336. "}",
  16337. "}"
  16338. ].join( "\n" )
  16339. };
  16340. } else {
  16341. shader = {
  16342. vertexShader: [
  16343. "uniform lowp int renderType;",
  16344. "uniform vec3 screenPosition;",
  16345. "uniform vec2 scale;",
  16346. "uniform float rotation;",
  16347. "attribute vec2 position;",
  16348. "attribute vec2 uv;",
  16349. "varying vec2 vUV;",
  16350. "void main() {",
  16351. "vUV = uv;",
  16352. "vec2 pos = position;",
  16353. "if( renderType == 2 ) {",
  16354. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  16355. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  16356. "}",
  16357. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  16358. "}"
  16359. ].join( "\n" ),
  16360. fragmentShader: [
  16361. "precision mediump float;",
  16362. "uniform lowp int renderType;",
  16363. "uniform sampler2D map;",
  16364. "uniform sampler2D occlusionMap;",
  16365. "uniform float opacity;",
  16366. "uniform vec3 color;",
  16367. "varying vec2 vUV;",
  16368. "void main() {",
  16369. // pink square
  16370. "if( renderType == 0 ) {",
  16371. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  16372. // restore
  16373. "} else if( renderType == 1 ) {",
  16374. "gl_FragColor = texture2D( map, vUV );",
  16375. // flare
  16376. "} else {",
  16377. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  16378. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  16379. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  16380. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  16381. "visibility = ( 1.0 - visibility / 4.0 );",
  16382. "vec4 texture = texture2D( map, vUV );",
  16383. "texture.a *= opacity * visibility;",
  16384. "gl_FragColor = texture;",
  16385. "gl_FragColor.rgb *= color;",
  16386. "}",
  16387. "}"
  16388. ].join( "\n" )
  16389. };
  16390. }
  16391. program = createProgram( shader );
  16392. attributes = {
  16393. vertex: gl.getAttribLocation ( program, "position" ),
  16394. uv: gl.getAttribLocation ( program, "uv" )
  16395. };
  16396. uniforms = {
  16397. renderType: gl.getUniformLocation( program, "renderType" ),
  16398. map: gl.getUniformLocation( program, "map" ),
  16399. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  16400. opacity: gl.getUniformLocation( program, "opacity" ),
  16401. color: gl.getUniformLocation( program, "color" ),
  16402. scale: gl.getUniformLocation( program, "scale" ),
  16403. rotation: gl.getUniformLocation( program, "rotation" ),
  16404. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  16405. };
  16406. };
  16407. /*
  16408. * Render lens flares
  16409. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  16410. * reads these back and calculates occlusion.
  16411. */
  16412. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  16413. if ( flares.length === 0 ) return;
  16414. var tempPosition = new THREE.Vector3();
  16415. var invAspect = viewportHeight / viewportWidth,
  16416. halfViewportWidth = viewportWidth * 0.5,
  16417. halfViewportHeight = viewportHeight * 0.5;
  16418. var size = 16 / viewportHeight,
  16419. scale = new THREE.Vector2( size * invAspect, size );
  16420. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  16421. screenPositionPixels = new THREE.Vector2( 1, 1 );
  16422. if ( program === undefined ) {
  16423. init();
  16424. }
  16425. gl.useProgram( program );
  16426. state.initAttributes();
  16427. state.enableAttribute( attributes.vertex );
  16428. state.enableAttribute( attributes.uv );
  16429. state.disableUnusedAttributes();
  16430. // loop through all lens flares to update their occlusion and positions
  16431. // setup gl and common used attribs/uniforms
  16432. gl.uniform1i( uniforms.occlusionMap, 0 );
  16433. gl.uniform1i( uniforms.map, 1 );
  16434. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16435. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  16436. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  16437. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16438. state.disable( gl.CULL_FACE );
  16439. gl.depthMask( false );
  16440. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  16441. size = 16 / viewportHeight;
  16442. scale.set( size * invAspect, size );
  16443. // calc object screen position
  16444. var flare = flares[ i ];
  16445. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  16446. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  16447. tempPosition.applyProjection( camera.projectionMatrix );
  16448. // setup arrays for gl programs
  16449. screenPosition.copy( tempPosition );
  16450. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  16451. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  16452. // screen cull
  16453. if ( hasVertexTexture || (
  16454. screenPositionPixels.x > 0 &&
  16455. screenPositionPixels.x < viewportWidth &&
  16456. screenPositionPixels.y > 0 &&
  16457. screenPositionPixels.y < viewportHeight ) ) {
  16458. // save current RGB to temp texture
  16459. state.activeTexture( gl.TEXTURE0 );
  16460. state.bindTexture( gl.TEXTURE_2D, null );
  16461. state.activeTexture( gl.TEXTURE1 );
  16462. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16463. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  16464. // render pink quad
  16465. gl.uniform1i( uniforms.renderType, 0 );
  16466. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  16467. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  16468. state.disable( gl.BLEND );
  16469. state.enable( gl.DEPTH_TEST );
  16470. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16471. // copy result to occlusionMap
  16472. state.activeTexture( gl.TEXTURE0 );
  16473. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  16474. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  16475. // restore graphics
  16476. gl.uniform1i( uniforms.renderType, 1 );
  16477. state.disable( gl.DEPTH_TEST );
  16478. state.activeTexture( gl.TEXTURE1 );
  16479. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16480. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16481. // update object positions
  16482. flare.positionScreen.copy( screenPosition );
  16483. if ( flare.customUpdateCallback ) {
  16484. flare.customUpdateCallback( flare );
  16485. } else {
  16486. flare.updateLensFlares();
  16487. }
  16488. // render flares
  16489. gl.uniform1i( uniforms.renderType, 2 );
  16490. state.enable( gl.BLEND );
  16491. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  16492. var sprite = flare.lensFlares[ j ];
  16493. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  16494. screenPosition.x = sprite.x;
  16495. screenPosition.y = sprite.y;
  16496. screenPosition.z = sprite.z;
  16497. size = sprite.size * sprite.scale / viewportHeight;
  16498. scale.x = size * invAspect;
  16499. scale.y = size;
  16500. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  16501. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  16502. gl.uniform1f( uniforms.rotation, sprite.rotation );
  16503. gl.uniform1f( uniforms.opacity, sprite.opacity );
  16504. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  16505. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  16506. renderer.setTexture( sprite.texture, 1 );
  16507. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16508. }
  16509. }
  16510. }
  16511. }
  16512. // restore gl
  16513. state.enable( gl.CULL_FACE );
  16514. state.enable( gl.DEPTH_TEST );
  16515. gl.depthMask( true );
  16516. renderer.resetGLState();
  16517. };
  16518. function createProgram ( shader ) {
  16519. var program = gl.createProgram();
  16520. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  16521. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  16522. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  16523. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  16524. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  16525. gl.compileShader( fragmentShader );
  16526. gl.compileShader( vertexShader );
  16527. gl.attachShader( program, fragmentShader );
  16528. gl.attachShader( program, vertexShader );
  16529. gl.linkProgram( program );
  16530. return program;
  16531. }
  16532. };
  16533. // File:src/renderers/webgl/plugins/SpritePlugin.js
  16534. /**
  16535. * @author mikael emtinger / http://gomo.se/
  16536. * @author alteredq / http://alteredqualia.com/
  16537. */
  16538. THREE.SpritePlugin = function ( renderer, sprites ) {
  16539. var gl = renderer.context;
  16540. var state = renderer.state;
  16541. var vertexBuffer, elementBuffer;
  16542. var program, attributes, uniforms;
  16543. var texture;
  16544. // decompose matrixWorld
  16545. var spritePosition = new THREE.Vector3();
  16546. var spriteRotation = new THREE.Quaternion();
  16547. var spriteScale = new THREE.Vector3();
  16548. var init = function () {
  16549. var vertices = new Float32Array( [
  16550. - 0.5, - 0.5, 0, 0,
  16551. 0.5, - 0.5, 1, 0,
  16552. 0.5, 0.5, 1, 1,
  16553. - 0.5, 0.5, 0, 1
  16554. ] );
  16555. var faces = new Uint16Array( [
  16556. 0, 1, 2,
  16557. 0, 2, 3
  16558. ] );
  16559. vertexBuffer = gl.createBuffer();
  16560. elementBuffer = gl.createBuffer();
  16561. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16562. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  16563. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16564. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  16565. program = createProgram();
  16566. attributes = {
  16567. position: gl.getAttribLocation ( program, 'position' ),
  16568. uv: gl.getAttribLocation ( program, 'uv' )
  16569. };
  16570. uniforms = {
  16571. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  16572. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  16573. rotation: gl.getUniformLocation( program, 'rotation' ),
  16574. scale: gl.getUniformLocation( program, 'scale' ),
  16575. color: gl.getUniformLocation( program, 'color' ),
  16576. map: gl.getUniformLocation( program, 'map' ),
  16577. opacity: gl.getUniformLocation( program, 'opacity' ),
  16578. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  16579. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  16580. fogType: gl.getUniformLocation( program, 'fogType' ),
  16581. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  16582. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  16583. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  16584. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  16585. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  16586. };
  16587. var canvas = document.createElement( 'canvas' );
  16588. canvas.width = 8;
  16589. canvas.height = 8;
  16590. var context = canvas.getContext( '2d' );
  16591. context.fillStyle = 'white';
  16592. context.fillRect( 0, 0, 8, 8 );
  16593. texture = new THREE.Texture( canvas );
  16594. texture.needsUpdate = true;
  16595. };
  16596. this.render = function ( scene, camera ) {
  16597. if ( sprites.length === 0 ) return;
  16598. // setup gl
  16599. if ( program === undefined ) {
  16600. init();
  16601. }
  16602. gl.useProgram( program );
  16603. state.initAttributes();
  16604. state.enableAttribute( attributes.position );
  16605. state.enableAttribute( attributes.uv );
  16606. state.disableUnusedAttributes();
  16607. state.disable( gl.CULL_FACE );
  16608. state.enable( gl.BLEND );
  16609. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16610. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  16611. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  16612. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16613. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  16614. state.activeTexture( gl.TEXTURE0 );
  16615. gl.uniform1i( uniforms.map, 0 );
  16616. var oldFogType = 0;
  16617. var sceneFogType = 0;
  16618. var fog = scene.fog;
  16619. if ( fog ) {
  16620. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  16621. if ( fog instanceof THREE.Fog ) {
  16622. gl.uniform1f( uniforms.fogNear, fog.near );
  16623. gl.uniform1f( uniforms.fogFar, fog.far );
  16624. gl.uniform1i( uniforms.fogType, 1 );
  16625. oldFogType = 1;
  16626. sceneFogType = 1;
  16627. } else if ( fog instanceof THREE.FogExp2 ) {
  16628. gl.uniform1f( uniforms.fogDensity, fog.density );
  16629. gl.uniform1i( uniforms.fogType, 2 );
  16630. oldFogType = 2;
  16631. sceneFogType = 2;
  16632. }
  16633. } else {
  16634. gl.uniform1i( uniforms.fogType, 0 );
  16635. oldFogType = 0;
  16636. sceneFogType = 0;
  16637. }
  16638. // update positions and sort
  16639. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  16640. var sprite = sprites[ i ];
  16641. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  16642. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  16643. }
  16644. sprites.sort( painterSortStable );
  16645. // render all sprites
  16646. var scale = [];
  16647. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  16648. var sprite = sprites[ i ];
  16649. var material = sprite.material;
  16650. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  16651. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  16652. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  16653. scale[ 0 ] = spriteScale.x;
  16654. scale[ 1 ] = spriteScale.y;
  16655. var fogType = 0;
  16656. if ( scene.fog && material.fog ) {
  16657. fogType = sceneFogType;
  16658. }
  16659. if ( oldFogType !== fogType ) {
  16660. gl.uniform1i( uniforms.fogType, fogType );
  16661. oldFogType = fogType;
  16662. }
  16663. if ( material.map !== null ) {
  16664. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  16665. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  16666. } else {
  16667. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  16668. gl.uniform2f( uniforms.uvScale, 1, 1 );
  16669. }
  16670. gl.uniform1f( uniforms.opacity, material.opacity );
  16671. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  16672. gl.uniform1f( uniforms.rotation, material.rotation );
  16673. gl.uniform2fv( uniforms.scale, scale );
  16674. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  16675. state.setDepthTest( material.depthTest );
  16676. state.setDepthWrite( material.depthWrite );
  16677. if ( material.map && material.map.image && material.map.image.width ) {
  16678. renderer.setTexture( material.map, 0 );
  16679. } else {
  16680. renderer.setTexture( texture, 0 );
  16681. }
  16682. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16683. }
  16684. // restore gl
  16685. state.enable( gl.CULL_FACE );
  16686. renderer.resetGLState();
  16687. };
  16688. function createProgram () {
  16689. var program = gl.createProgram();
  16690. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  16691. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  16692. gl.shaderSource( vertexShader, [
  16693. 'precision ' + renderer.getPrecision() + ' float;',
  16694. 'uniform mat4 modelViewMatrix;',
  16695. 'uniform mat4 projectionMatrix;',
  16696. 'uniform float rotation;',
  16697. 'uniform vec2 scale;',
  16698. 'uniform vec2 uvOffset;',
  16699. 'uniform vec2 uvScale;',
  16700. 'attribute vec2 position;',
  16701. 'attribute vec2 uv;',
  16702. 'varying vec2 vUV;',
  16703. 'void main() {',
  16704. 'vUV = uvOffset + uv * uvScale;',
  16705. 'vec2 alignedPosition = position * scale;',
  16706. 'vec2 rotatedPosition;',
  16707. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  16708. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  16709. 'vec4 finalPosition;',
  16710. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  16711. 'finalPosition.xy += rotatedPosition;',
  16712. 'finalPosition = projectionMatrix * finalPosition;',
  16713. 'gl_Position = finalPosition;',
  16714. '}'
  16715. ].join( '\n' ) );
  16716. gl.shaderSource( fragmentShader, [
  16717. 'precision ' + renderer.getPrecision() + ' float;',
  16718. 'uniform vec3 color;',
  16719. 'uniform sampler2D map;',
  16720. 'uniform float opacity;',
  16721. 'uniform int fogType;',
  16722. 'uniform vec3 fogColor;',
  16723. 'uniform float fogDensity;',
  16724. 'uniform float fogNear;',
  16725. 'uniform float fogFar;',
  16726. 'uniform float alphaTest;',
  16727. 'varying vec2 vUV;',
  16728. 'void main() {',
  16729. 'vec4 texture = texture2D( map, vUV );',
  16730. 'if ( texture.a < alphaTest ) discard;',
  16731. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  16732. 'if ( fogType > 0 ) {',
  16733. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  16734. 'float fogFactor = 0.0;',
  16735. 'if ( fogType == 1 ) {',
  16736. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  16737. '} else {',
  16738. 'const float LOG2 = 1.442695;',
  16739. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  16740. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  16741. '}',
  16742. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  16743. '}',
  16744. '}'
  16745. ].join( '\n' ) );
  16746. gl.compileShader( vertexShader );
  16747. gl.compileShader( fragmentShader );
  16748. gl.attachShader( program, vertexShader );
  16749. gl.attachShader( program, fragmentShader );
  16750. gl.linkProgram( program );
  16751. return program;
  16752. }
  16753. function painterSortStable ( a, b ) {
  16754. if ( a.z !== b.z ) {
  16755. return b.z - a.z;
  16756. } else {
  16757. return b.id - a.id;
  16758. }
  16759. }
  16760. };
  16761. // File:src/extras/GeometryUtils.js
  16762. /**
  16763. * @author mrdoob / http://mrdoob.com/
  16764. */
  16765. THREE.GeometryUtils = {
  16766. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  16767. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  16768. var matrix;
  16769. if ( geometry2 instanceof THREE.Mesh ) {
  16770. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  16771. matrix = geometry2.matrix;
  16772. geometry2 = geometry2.geometry;
  16773. }
  16774. geometry1.merge( geometry2, matrix, materialIndexOffset );
  16775. },
  16776. center: function ( geometry ) {
  16777. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  16778. return geometry.center();
  16779. }
  16780. };
  16781. // File:src/extras/ImageUtils.js
  16782. /**
  16783. * @author alteredq / http://alteredqualia.com/
  16784. * @author mrdoob / http://mrdoob.com/
  16785. * @author Daosheng Mu / https://github.com/DaoshengMu/
  16786. */
  16787. THREE.ImageUtils = {
  16788. crossOrigin: undefined,
  16789. loadTexture: function ( url, mapping, onLoad, onError ) {
  16790. var loader = new THREE.ImageLoader();
  16791. loader.crossOrigin = this.crossOrigin;
  16792. var texture = new THREE.Texture( undefined, mapping );
  16793. loader.load( url, function ( image ) {
  16794. texture.image = image;
  16795. texture.needsUpdate = true;
  16796. if ( onLoad ) onLoad( texture );
  16797. }, undefined, function ( event ) {
  16798. if ( onError ) onError( event );
  16799. } );
  16800. texture.sourceFile = url;
  16801. return texture;
  16802. },
  16803. loadTextureCube: function ( array, mapping, onLoad, onError ) {
  16804. var images = [];
  16805. var loader = new THREE.ImageLoader();
  16806. loader.crossOrigin = this.crossOrigin;
  16807. var texture = new THREE.CubeTexture( images, mapping );
  16808. var loaded = 0;
  16809. var loadTexture = function ( i ) {
  16810. loader.load( array[ i ], function ( image ) {
  16811. texture.images[ i ] = image;
  16812. loaded += 1;
  16813. if ( loaded === 6 ) {
  16814. texture.needsUpdate = true;
  16815. if ( onLoad ) onLoad( texture );
  16816. }
  16817. }, undefined, onError );
  16818. };
  16819. for ( var i = 0, il = array.length; i < il; ++ i ) {
  16820. loadTexture( i );
  16821. }
  16822. return texture;
  16823. },
  16824. loadCompressedTexture: function () {
  16825. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  16826. },
  16827. loadCompressedTextureCube: function () {
  16828. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  16829. },
  16830. getNormalMap: function ( image, depth ) {
  16831. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  16832. var cross = function ( a, b ) {
  16833. 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 ] ];
  16834. };
  16835. var subtract = function ( a, b ) {
  16836. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  16837. };
  16838. var normalize = function ( a ) {
  16839. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  16840. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  16841. };
  16842. depth = depth | 1;
  16843. var width = image.width;
  16844. var height = image.height;
  16845. var canvas = document.createElement( 'canvas' );
  16846. canvas.width = width;
  16847. canvas.height = height;
  16848. var context = canvas.getContext( '2d' );
  16849. context.drawImage( image, 0, 0 );
  16850. var data = context.getImageData( 0, 0, width, height ).data;
  16851. var imageData = context.createImageData( width, height );
  16852. var output = imageData.data;
  16853. for ( var x = 0; x < width; x ++ ) {
  16854. for ( var y = 0; y < height; y ++ ) {
  16855. var ly = y - 1 < 0 ? 0 : y - 1;
  16856. var uy = y + 1 > height - 1 ? height - 1 : y + 1;
  16857. var lx = x - 1 < 0 ? 0 : x - 1;
  16858. var ux = x + 1 > width - 1 ? width - 1 : x + 1;
  16859. var points = [];
  16860. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  16861. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  16862. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  16863. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  16864. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  16865. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  16866. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  16867. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  16868. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  16869. var normals = [];
  16870. var num_points = points.length;
  16871. for ( var i = 0; i < num_points; i ++ ) {
  16872. var v1 = points[ i ];
  16873. var v2 = points[ ( i + 1 ) % num_points ];
  16874. v1 = subtract( v1, origin );
  16875. v2 = subtract( v2, origin );
  16876. normals.push( normalize( cross( v1, v2 ) ) );
  16877. }
  16878. var normal = [ 0, 0, 0 ];
  16879. for ( var i = 0; i < normals.length; i ++ ) {
  16880. normal[ 0 ] += normals[ i ][ 0 ];
  16881. normal[ 1 ] += normals[ i ][ 1 ];
  16882. normal[ 2 ] += normals[ i ][ 2 ];
  16883. }
  16884. normal[ 0 ] /= normals.length;
  16885. normal[ 1 ] /= normals.length;
  16886. normal[ 2 ] /= normals.length;
  16887. var idx = ( y * width + x ) * 4;
  16888. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  16889. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
  16890. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  16891. output[ idx + 3 ] = 255;
  16892. }
  16893. }
  16894. context.putImageData( imageData, 0, 0 );
  16895. return canvas;
  16896. },
  16897. generateDataTexture: function ( width, height, color ) {
  16898. var size = width * height;
  16899. var data = new Uint8Array( 3 * size );
  16900. var r = Math.floor( color.r * 255 );
  16901. var g = Math.floor( color.g * 255 );
  16902. var b = Math.floor( color.b * 255 );
  16903. for ( var i = 0; i < size; i ++ ) {
  16904. data[ i * 3 ] = r;
  16905. data[ i * 3 + 1 ] = g;
  16906. data[ i * 3 + 2 ] = b;
  16907. }
  16908. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  16909. texture.needsUpdate = true;
  16910. return texture;
  16911. }
  16912. };
  16913. // File:src/extras/SceneUtils.js
  16914. /**
  16915. * @author alteredq / http://alteredqualia.com/
  16916. */
  16917. THREE.SceneUtils = {
  16918. createMultiMaterialObject: function ( geometry, materials ) {
  16919. var group = new THREE.Group();
  16920. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  16921. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  16922. }
  16923. return group;
  16924. },
  16925. detach: function ( child, parent, scene ) {
  16926. child.applyMatrix( parent.matrixWorld );
  16927. parent.remove( child );
  16928. scene.add( child );
  16929. },
  16930. attach: function ( child, scene, parent ) {
  16931. var matrixWorldInverse = new THREE.Matrix4();
  16932. matrixWorldInverse.getInverse( parent.matrixWorld );
  16933. child.applyMatrix( matrixWorldInverse );
  16934. scene.remove( child );
  16935. parent.add( child );
  16936. }
  16937. };
  16938. // File:src/extras/FontUtils.js
  16939. /**
  16940. * @author zz85 / http://www.lab4games.net/zz85/blog
  16941. * @author alteredq / http://alteredqualia.com/
  16942. *
  16943. * For Text operations in three.js (See TextGeometry)
  16944. *
  16945. * It uses techniques used in:
  16946. *
  16947. * Triangulation ported from AS3
  16948. * Simple Polygon Triangulation
  16949. * http://actionsnippet.com/?p=1462
  16950. *
  16951. * A Method to triangulate shapes with holes
  16952. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  16953. *
  16954. */
  16955. THREE.FontUtils = {
  16956. faces: {},
  16957. // Just for now. face[weight][style]
  16958. face: 'helvetiker',
  16959. weight: 'normal',
  16960. style: 'normal',
  16961. size: 150,
  16962. divisions: 10,
  16963. getFace: function () {
  16964. try {
  16965. return this.faces[ this.face.toLowerCase() ][ this.weight ][ this.style ];
  16966. } catch ( e ) {
  16967. throw "The font " + this.face + " with " + this.weight + " weight and " + this.style + " style is missing."
  16968. }
  16969. },
  16970. loadFace: function ( data ) {
  16971. var family = data.familyName.toLowerCase();
  16972. var ThreeFont = this;
  16973. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  16974. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  16975. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  16976. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  16977. return data;
  16978. },
  16979. drawText: function ( text ) {
  16980. // RenderText
  16981. var i,
  16982. face = this.getFace(),
  16983. scale = this.size / face.resolution,
  16984. offset = 0,
  16985. chars = String( text ).split( '' ),
  16986. length = chars.length;
  16987. var fontPaths = [];
  16988. for ( i = 0; i < length; i ++ ) {
  16989. var path = new THREE.Path();
  16990. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  16991. offset += ret.offset;
  16992. fontPaths.push( ret.path );
  16993. }
  16994. // get the width
  16995. var width = offset / 2;
  16996. //
  16997. // for ( p = 0; p < allPts.length; p++ ) {
  16998. //
  16999. // allPts[ p ].x -= width;
  17000. //
  17001. // }
  17002. //var extract = this.extractPoints( allPts, characterPts );
  17003. //extract.contour = allPts;
  17004. //extract.paths = fontPaths;
  17005. //extract.offset = width;
  17006. return { paths: fontPaths, offset: width };
  17007. },
  17008. extractGlyphPoints: function ( c, face, scale, offset, path ) {
  17009. var pts = [];
  17010. var i, i2, divisions,
  17011. outline, action, length,
  17012. scaleX, scaleY,
  17013. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  17014. laste,
  17015. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  17016. if ( ! glyph ) return;
  17017. if ( glyph.o ) {
  17018. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  17019. length = outline.length;
  17020. scaleX = scale;
  17021. scaleY = scale;
  17022. for ( i = 0; i < length; ) {
  17023. action = outline[ i ++ ];
  17024. //console.log( action );
  17025. switch ( action ) {
  17026. case 'm':
  17027. // Move To
  17028. x = outline[ i ++ ] * scaleX + offset;
  17029. y = outline[ i ++ ] * scaleY;
  17030. path.moveTo( x, y );
  17031. break;
  17032. case 'l':
  17033. // Line To
  17034. x = outline[ i ++ ] * scaleX + offset;
  17035. y = outline[ i ++ ] * scaleY;
  17036. path.lineTo( x, y );
  17037. break;
  17038. case 'q':
  17039. // QuadraticCurveTo
  17040. cpx = outline[ i ++ ] * scaleX + offset;
  17041. cpy = outline[ i ++ ] * scaleY;
  17042. cpx1 = outline[ i ++ ] * scaleX + offset;
  17043. cpy1 = outline[ i ++ ] * scaleY;
  17044. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  17045. laste = pts[ pts.length - 1 ];
  17046. if ( laste ) {
  17047. cpx0 = laste.x;
  17048. cpy0 = laste.y;
  17049. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  17050. var t = i2 / divisions;
  17051. THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  17052. THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  17053. }
  17054. }
  17055. break;
  17056. case 'b':
  17057. // Cubic Bezier Curve
  17058. cpx = outline[ i ++ ] * scaleX + offset;
  17059. cpy = outline[ i ++ ] * scaleY;
  17060. cpx1 = outline[ i ++ ] * scaleX + offset;
  17061. cpy1 = outline[ i ++ ] * scaleY;
  17062. cpx2 = outline[ i ++ ] * scaleX + offset;
  17063. cpy2 = outline[ i ++ ] * scaleY;
  17064. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  17065. laste = pts[ pts.length - 1 ];
  17066. if ( laste ) {
  17067. cpx0 = laste.x;
  17068. cpy0 = laste.y;
  17069. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  17070. var t = i2 / divisions;
  17071. THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  17072. THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  17073. }
  17074. }
  17075. break;
  17076. }
  17077. }
  17078. }
  17079. return { offset: glyph.ha * scale, path: path };
  17080. }
  17081. };
  17082. THREE.FontUtils.generateShapes = function ( text, parameters ) {
  17083. // Parameters
  17084. parameters = parameters || {};
  17085. var size = parameters.size !== undefined ? parameters.size : 100;
  17086. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments : 4;
  17087. var font = parameters.font !== undefined ? parameters.font : 'helvetiker';
  17088. var weight = parameters.weight !== undefined ? parameters.weight : 'normal';
  17089. var style = parameters.style !== undefined ? parameters.style : 'normal';
  17090. THREE.FontUtils.size = size;
  17091. THREE.FontUtils.divisions = curveSegments;
  17092. THREE.FontUtils.face = font;
  17093. THREE.FontUtils.weight = weight;
  17094. THREE.FontUtils.style = style;
  17095. // Get a Font data json object
  17096. var data = THREE.FontUtils.drawText( text );
  17097. var paths = data.paths;
  17098. var shapes = [];
  17099. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  17100. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  17101. }
  17102. return shapes;
  17103. };
  17104. /**
  17105. * This code is a quick port of code written in C++ which was submitted to
  17106. * flipcode.com by John W. Ratcliff // July 22, 2000
  17107. * See original code and more information here:
  17108. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  17109. *
  17110. * ported to actionscript by Zevan Rosser
  17111. * www.actionsnippet.com
  17112. *
  17113. * ported to javascript by Joshua Koo
  17114. * http://www.lab4games.net/zz85/blog
  17115. *
  17116. */
  17117. ( function ( namespace ) {
  17118. var EPSILON = 0.0000000001;
  17119. // takes in an contour array and returns
  17120. var process = function ( contour, indices ) {
  17121. var n = contour.length;
  17122. if ( n < 3 ) return null;
  17123. var result = [],
  17124. verts = [],
  17125. vertIndices = [];
  17126. /* we want a counter-clockwise polygon in verts */
  17127. var u, v, w;
  17128. if ( area( contour ) > 0.0 ) {
  17129. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  17130. } else {
  17131. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  17132. }
  17133. var nv = n;
  17134. /* remove nv - 2 vertices, creating 1 triangle every time */
  17135. var count = 2 * nv; /* error detection */
  17136. for ( v = nv - 1; nv > 2; ) {
  17137. /* if we loop, it is probably a non-simple polygon */
  17138. if ( ( count -- ) <= 0 ) {
  17139. //** Triangulate: ERROR - probable bad polygon!
  17140. //throw ( "Warning, unable to triangulate polygon!" );
  17141. //return null;
  17142. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  17143. console.warn( 'THREE.FontUtils: Warning, unable to triangulate polygon! in Triangulate.process()' );
  17144. if ( indices ) return vertIndices;
  17145. return result;
  17146. }
  17147. /* three consecutive vertices in current polygon, <u,v,w> */
  17148. u = v; if ( nv <= u ) u = 0; /* previous */
  17149. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  17150. w = v + 1; if ( nv <= w ) w = 0; /* next */
  17151. if ( snip( contour, u, v, w, nv, verts ) ) {
  17152. var a, b, c, s, t;
  17153. /* true names of the vertices */
  17154. a = verts[ u ];
  17155. b = verts[ v ];
  17156. c = verts[ w ];
  17157. /* output Triangle */
  17158. result.push( [ contour[ a ],
  17159. contour[ b ],
  17160. contour[ c ] ] );
  17161. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  17162. /* remove v from the remaining polygon */
  17163. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  17164. verts[ s ] = verts[ t ];
  17165. }
  17166. nv --;
  17167. /* reset error detection counter */
  17168. count = 2 * nv;
  17169. }
  17170. }
  17171. if ( indices ) return vertIndices;
  17172. return result;
  17173. };
  17174. // calculate area of the contour polygon
  17175. var area = function ( contour ) {
  17176. var n = contour.length;
  17177. var a = 0.0;
  17178. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17179. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17180. }
  17181. return a * 0.5;
  17182. };
  17183. var snip = function ( contour, u, v, w, n, verts ) {
  17184. var p;
  17185. var ax, ay, bx, by;
  17186. var cx, cy, px, py;
  17187. ax = contour[ verts[ u ] ].x;
  17188. ay = contour[ verts[ u ] ].y;
  17189. bx = contour[ verts[ v ] ].x;
  17190. by = contour[ verts[ v ] ].y;
  17191. cx = contour[ verts[ w ] ].x;
  17192. cy = contour[ verts[ w ] ].y;
  17193. if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  17194. var aX, aY, bX, bY, cX, cY;
  17195. var apx, apy, bpx, bpy, cpx, cpy;
  17196. var cCROSSap, bCROSScp, aCROSSbp;
  17197. aX = cx - bx; aY = cy - by;
  17198. bX = ax - cx; bY = ay - cy;
  17199. cX = bx - ax; cY = by - ay;
  17200. for ( p = 0; p < n; p ++ ) {
  17201. px = contour[ verts[ p ] ].x;
  17202. py = contour[ verts[ p ] ].y;
  17203. if ( ( ( px === ax ) && ( py === ay ) ) ||
  17204. ( ( px === bx ) && ( py === by ) ) ||
  17205. ( ( px === cx ) && ( py === cy ) ) ) continue;
  17206. apx = px - ax; apy = py - ay;
  17207. bpx = px - bx; bpy = py - by;
  17208. cpx = px - cx; cpy = py - cy;
  17209. // see if p is inside triangle abc
  17210. aCROSSbp = aX * bpy - aY * bpx;
  17211. cCROSSap = cX * apy - cY * apx;
  17212. bCROSScp = bX * cpy - bY * cpx;
  17213. if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
  17214. }
  17215. return true;
  17216. };
  17217. namespace.Triangulate = process;
  17218. namespace.Triangulate.area = area;
  17219. return namespace;
  17220. } )( THREE.FontUtils );
  17221. // To use the typeface.js face files, hook up the API
  17222. THREE.typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  17223. if ( typeof self !== 'undefined' ) self._typeface_js = THREE.typeface_js;
  17224. // File:src/extras/audio/Audio.js
  17225. /**
  17226. * @author mrdoob / http://mrdoob.com/
  17227. */
  17228. THREE.Audio = function ( listener ) {
  17229. THREE.Object3D.call( this );
  17230. this.type = 'Audio';
  17231. this.context = listener.context;
  17232. this.source = this.context.createBufferSource();
  17233. this.source.onended = this.onEnded.bind( this );
  17234. this.gain = this.context.createGain();
  17235. this.gain.connect( this.context.destination );
  17236. this.panner = this.context.createPanner();
  17237. this.panner.connect( this.gain );
  17238. this.autoplay = false;
  17239. this.startTime = 0;
  17240. this.playbackRate = 1;
  17241. this.isPlaying = false;
  17242. };
  17243. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  17244. THREE.Audio.prototype.constructor = THREE.Audio;
  17245. THREE.Audio.prototype.load = function ( file ) {
  17246. var scope = this;
  17247. var request = new XMLHttpRequest();
  17248. request.open( 'GET', file, true );
  17249. request.responseType = 'arraybuffer';
  17250. request.onload = function ( e ) {
  17251. scope.context.decodeAudioData( this.response, function ( buffer ) {
  17252. scope.source.buffer = buffer;
  17253. if ( scope.autoplay ) scope.play();
  17254. } );
  17255. };
  17256. request.send();
  17257. return this;
  17258. };
  17259. THREE.Audio.prototype.play = function () {
  17260. if ( this.isPlaying === true ) {
  17261. console.warn( 'THREE.Audio: Audio is already playing.' );
  17262. return;
  17263. }
  17264. var source = this.context.createBufferSource();
  17265. source.buffer = this.source.buffer;
  17266. source.loop = this.source.loop;
  17267. source.onended = this.source.onended;
  17268. source.start( 0, this.startTime );
  17269. source.playbackRate.value = this.playbackRate;
  17270. this.isPlaying = true;
  17271. this.source = source;
  17272. this.connect();
  17273. };
  17274. THREE.Audio.prototype.pause = function () {
  17275. this.source.stop();
  17276. this.startTime = this.context.currentTime;
  17277. };
  17278. THREE.Audio.prototype.stop = function () {
  17279. this.source.stop();
  17280. this.startTime = 0;
  17281. };
  17282. THREE.Audio.prototype.connect = function () {
  17283. if ( this.filter !== undefined ) {
  17284. this.source.connect( this.filter );
  17285. this.filter.connect( this.panner );
  17286. } else {
  17287. this.source.connect( this.panner );
  17288. }
  17289. };
  17290. THREE.Audio.prototype.disconnect = function () {
  17291. if ( this.filter !== undefined ) {
  17292. this.source.disconnect( this.filter );
  17293. this.filter.disconnect( this.panner );
  17294. } else {
  17295. this.source.disconnect( this.panner );
  17296. }
  17297. };
  17298. THREE.Audio.prototype.setFilter = function ( value ) {
  17299. if ( this.isPlaying === true ) {
  17300. this.disconnect();
  17301. this.filter = value;
  17302. this.connect();
  17303. } else {
  17304. this.filter = value;
  17305. }
  17306. };
  17307. THREE.Audio.prototype.getFilter = function () {
  17308. return this.filter;
  17309. };
  17310. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  17311. this.playbackRate = value;
  17312. if ( this.isPlaying === true ) {
  17313. this.source.playbackRate.value = this.playbackRate;
  17314. }
  17315. };
  17316. THREE.Audio.prototype.getPlaybackRate = function () {
  17317. return this.playbackRate;
  17318. };
  17319. THREE.Audio.prototype.onEnded = function() {
  17320. this.isPlaying = false;
  17321. };
  17322. THREE.Audio.prototype.setLoop = function ( value ) {
  17323. this.source.loop = value;
  17324. };
  17325. THREE.Audio.prototype.getLoop = function () {
  17326. return this.source.loop;
  17327. };
  17328. THREE.Audio.prototype.setRefDistance = function ( value ) {
  17329. this.panner.refDistance = value;
  17330. };
  17331. THREE.Audio.prototype.getRefDistance = function () {
  17332. return this.panner.refDistance;
  17333. };
  17334. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  17335. this.panner.rolloffFactor = value;
  17336. };
  17337. THREE.Audio.prototype.getRolloffFactor = function () {
  17338. return this.panner.rolloffFactor;
  17339. };
  17340. THREE.Audio.prototype.setVolume = function ( value ) {
  17341. this.gain.gain.value = value;
  17342. };
  17343. THREE.Audio.prototype.getVolume = function () {
  17344. return this.gain.gain.value;
  17345. };
  17346. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  17347. var position = new THREE.Vector3();
  17348. return function updateMatrixWorld( force ) {
  17349. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  17350. position.setFromMatrixPosition( this.matrixWorld );
  17351. this.panner.setPosition( position.x, position.y, position.z );
  17352. };
  17353. } )();
  17354. // File:src/extras/audio/AudioListener.js
  17355. /**
  17356. * @author mrdoob / http://mrdoob.com/
  17357. */
  17358. THREE.AudioListener = function () {
  17359. THREE.Object3D.call( this );
  17360. this.type = 'AudioListener';
  17361. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  17362. };
  17363. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  17364. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  17365. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  17366. var position = new THREE.Vector3();
  17367. var quaternion = new THREE.Quaternion();
  17368. var scale = new THREE.Vector3();
  17369. var orientation = new THREE.Vector3();
  17370. return function updateMatrixWorld( force ) {
  17371. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  17372. var listener = this.context.listener;
  17373. var up = this.up;
  17374. this.matrixWorld.decompose( position, quaternion, scale );
  17375. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  17376. listener.setPosition( position.x, position.y, position.z );
  17377. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  17378. };
  17379. } )();
  17380. // File:src/extras/core/Curve.js
  17381. /**
  17382. * @author zz85 / http://www.lab4games.net/zz85/blog
  17383. * Extensible curve object
  17384. *
  17385. * Some common of Curve methods
  17386. * .getPoint(t), getTangent(t)
  17387. * .getPointAt(u), getTagentAt(u)
  17388. * .getPoints(), .getSpacedPoints()
  17389. * .getLength()
  17390. * .updateArcLengths()
  17391. *
  17392. * This following classes subclasses THREE.Curve:
  17393. *
  17394. * -- 2d classes --
  17395. * THREE.LineCurve
  17396. * THREE.QuadraticBezierCurve
  17397. * THREE.CubicBezierCurve
  17398. * THREE.SplineCurve
  17399. * THREE.ArcCurve
  17400. * THREE.EllipseCurve
  17401. *
  17402. * -- 3d classes --
  17403. * THREE.LineCurve3
  17404. * THREE.QuadraticBezierCurve3
  17405. * THREE.CubicBezierCurve3
  17406. * THREE.SplineCurve3
  17407. * THREE.ClosedSplineCurve3
  17408. *
  17409. * A series of curves can be represented as a THREE.CurvePath
  17410. *
  17411. **/
  17412. /**************************************************************
  17413. * Abstract Curve base class
  17414. **************************************************************/
  17415. THREE.Curve = function () {
  17416. };
  17417. // Virtual base class method to overwrite and implement in subclasses
  17418. // - t [0 .. 1]
  17419. THREE.Curve.prototype.getPoint = function ( t ) {
  17420. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  17421. return null;
  17422. };
  17423. // Get point at relative position in curve according to arc length
  17424. // - u [0 .. 1]
  17425. THREE.Curve.prototype.getPointAt = function ( u ) {
  17426. var t = this.getUtoTmapping( u );
  17427. return this.getPoint( t );
  17428. };
  17429. // Get sequence of points using getPoint( t )
  17430. THREE.Curve.prototype.getPoints = function ( divisions ) {
  17431. if ( ! divisions ) divisions = 5;
  17432. var d, pts = [];
  17433. for ( d = 0; d <= divisions; d ++ ) {
  17434. pts.push( this.getPoint( d / divisions ) );
  17435. }
  17436. return pts;
  17437. };
  17438. // Get sequence of points using getPointAt( u )
  17439. THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
  17440. if ( ! divisions ) divisions = 5;
  17441. var d, pts = [];
  17442. for ( d = 0; d <= divisions; d ++ ) {
  17443. pts.push( this.getPointAt( d / divisions ) );
  17444. }
  17445. return pts;
  17446. };
  17447. // Get total curve arc length
  17448. THREE.Curve.prototype.getLength = function () {
  17449. var lengths = this.getLengths();
  17450. return lengths[ lengths.length - 1 ];
  17451. };
  17452. // Get list of cumulative segment lengths
  17453. THREE.Curve.prototype.getLengths = function ( divisions ) {
  17454. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  17455. if ( this.cacheArcLengths
  17456. && ( this.cacheArcLengths.length === divisions + 1 )
  17457. && ! this.needsUpdate ) {
  17458. //console.log( "cached", this.cacheArcLengths );
  17459. return this.cacheArcLengths;
  17460. }
  17461. this.needsUpdate = false;
  17462. var cache = [];
  17463. var current, last = this.getPoint( 0 );
  17464. var p, sum = 0;
  17465. cache.push( 0 );
  17466. for ( p = 1; p <= divisions; p ++ ) {
  17467. current = this.getPoint ( p / divisions );
  17468. sum += current.distanceTo( last );
  17469. cache.push( sum );
  17470. last = current;
  17471. }
  17472. this.cacheArcLengths = cache;
  17473. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  17474. };
  17475. THREE.Curve.prototype.updateArcLengths = function() {
  17476. this.needsUpdate = true;
  17477. this.getLengths();
  17478. };
  17479. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  17480. THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
  17481. var arcLengths = this.getLengths();
  17482. var i = 0, il = arcLengths.length;
  17483. var targetArcLength; // The targeted u distance value to get
  17484. if ( distance ) {
  17485. targetArcLength = distance;
  17486. } else {
  17487. targetArcLength = u * arcLengths[ il - 1 ];
  17488. }
  17489. //var time = Date.now();
  17490. // binary search for the index with largest value smaller than target u distance
  17491. var low = 0, high = il - 1, comparison;
  17492. while ( low <= high ) {
  17493. 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
  17494. comparison = arcLengths[ i ] - targetArcLength;
  17495. if ( comparison < 0 ) {
  17496. low = i + 1;
  17497. } else if ( comparison > 0 ) {
  17498. high = i - 1;
  17499. } else {
  17500. high = i;
  17501. break;
  17502. // DONE
  17503. }
  17504. }
  17505. i = high;
  17506. //console.log('b' , i, low, high, Date.now()- time);
  17507. if ( arcLengths[ i ] === targetArcLength ) {
  17508. var t = i / ( il - 1 );
  17509. return t;
  17510. }
  17511. // we could get finer grain at lengths, or use simple interpolation between two points
  17512. var lengthBefore = arcLengths[ i ];
  17513. var lengthAfter = arcLengths[ i + 1 ];
  17514. var segmentLength = lengthAfter - lengthBefore;
  17515. // determine where we are between the 'before' and 'after' points
  17516. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  17517. // add that fractional amount to t
  17518. var t = ( i + segmentFraction ) / ( il - 1 );
  17519. return t;
  17520. };
  17521. // Returns a unit vector tangent at t
  17522. // In case any sub curve does not implement its tangent derivation,
  17523. // 2 points a small delta apart will be used to find its gradient
  17524. // which seems to give a reasonable approximation
  17525. THREE.Curve.prototype.getTangent = function( t ) {
  17526. var delta = 0.0001;
  17527. var t1 = t - delta;
  17528. var t2 = t + delta;
  17529. // Capping in case of danger
  17530. if ( t1 < 0 ) t1 = 0;
  17531. if ( t2 > 1 ) t2 = 1;
  17532. var pt1 = this.getPoint( t1 );
  17533. var pt2 = this.getPoint( t2 );
  17534. var vec = pt2.clone().sub( pt1 );
  17535. return vec.normalize();
  17536. };
  17537. THREE.Curve.prototype.getTangentAt = function ( u ) {
  17538. var t = this.getUtoTmapping( u );
  17539. return this.getTangent( t );
  17540. };
  17541. /**************************************************************
  17542. * Utils
  17543. **************************************************************/
  17544. THREE.Curve.Utils = {
  17545. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  17546. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  17547. },
  17548. // Puay Bing, thanks for helping with this derivative!
  17549. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  17550. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  17551. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  17552. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  17553. 3 * t * t * p3;
  17554. },
  17555. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  17556. // To check if my formulas are correct
  17557. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  17558. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  17559. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  17560. var h11 = 3 * t * t - 2 * t; // t3 − t2
  17561. return h00 + h10 + h01 + h11;
  17562. },
  17563. // Catmull-Rom
  17564. interpolate: function( p0, p1, p2, p3, t ) {
  17565. var v0 = ( p2 - p0 ) * 0.5;
  17566. var v1 = ( p3 - p1 ) * 0.5;
  17567. var t2 = t * t;
  17568. var t3 = t * t2;
  17569. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  17570. }
  17571. };
  17572. // TODO: Transformation for Curves?
  17573. /**************************************************************
  17574. * 3D Curves
  17575. **************************************************************/
  17576. // A Factory method for creating new curve subclasses
  17577. THREE.Curve.create = function ( constructor, getPointFunc ) {
  17578. constructor.prototype = Object.create( THREE.Curve.prototype );
  17579. constructor.prototype.constructor = constructor;
  17580. constructor.prototype.getPoint = getPointFunc;
  17581. return constructor;
  17582. };
  17583. // File:src/extras/core/CurvePath.js
  17584. /**
  17585. * @author zz85 / http://www.lab4games.net/zz85/blog
  17586. *
  17587. **/
  17588. /**************************************************************
  17589. * Curved Path - a curve path is simply a array of connected
  17590. * curves, but retains the api of a curve
  17591. **************************************************************/
  17592. THREE.CurvePath = function () {
  17593. this.curves = [];
  17594. this.bends = [];
  17595. this.autoClose = false; // Automatically closes the path
  17596. };
  17597. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  17598. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  17599. THREE.CurvePath.prototype.add = function ( curve ) {
  17600. this.curves.push( curve );
  17601. };
  17602. THREE.CurvePath.prototype.checkConnection = function() {
  17603. // TODO
  17604. // If the ending of curve is not connected to the starting
  17605. // or the next curve, then, this is not a real path
  17606. };
  17607. THREE.CurvePath.prototype.closePath = function() {
  17608. // TODO Test
  17609. // and verify for vector3 (needs to implement equals)
  17610. // Add a line curve if start and end of lines are not connected
  17611. var startPoint = this.curves[ 0 ].getPoint( 0 );
  17612. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  17613. if ( ! startPoint.equals( endPoint ) ) {
  17614. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  17615. }
  17616. };
  17617. // To get accurate point with reference to
  17618. // entire path distance at time t,
  17619. // following has to be done:
  17620. // 1. Length of each sub path have to be known
  17621. // 2. Locate and identify type of curve
  17622. // 3. Get t for the curve
  17623. // 4. Return curve.getPointAt(t')
  17624. THREE.CurvePath.prototype.getPoint = function( t ) {
  17625. var d = t * this.getLength();
  17626. var curveLengths = this.getCurveLengths();
  17627. var i = 0, diff, curve;
  17628. // To think about boundaries points.
  17629. while ( i < curveLengths.length ) {
  17630. if ( curveLengths[ i ] >= d ) {
  17631. diff = curveLengths[ i ] - d;
  17632. curve = this.curves[ i ];
  17633. var u = 1 - diff / curve.getLength();
  17634. return curve.getPointAt( u );
  17635. }
  17636. i ++;
  17637. }
  17638. return null;
  17639. // loop where sum != 0, sum > d , sum+1 <d
  17640. };
  17641. /*
  17642. THREE.CurvePath.prototype.getTangent = function( t ) {
  17643. };*/
  17644. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  17645. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  17646. // getPoint() depends on getLength
  17647. THREE.CurvePath.prototype.getLength = function() {
  17648. var lens = this.getCurveLengths();
  17649. return lens[ lens.length - 1 ];
  17650. };
  17651. // Compute lengths and cache them
  17652. // We cannot overwrite getLengths() because UtoT mapping uses it.
  17653. THREE.CurvePath.prototype.getCurveLengths = function() {
  17654. // We use cache values if curves and cache array are same length
  17655. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  17656. return this.cacheLengths;
  17657. }
  17658. // Get length of sub-curve
  17659. // Push sums into cached array
  17660. var lengths = [], sums = 0;
  17661. var i, il = this.curves.length;
  17662. for ( i = 0; i < il; i ++ ) {
  17663. sums += this.curves[ i ].getLength();
  17664. lengths.push( sums );
  17665. }
  17666. this.cacheLengths = lengths;
  17667. return lengths;
  17668. };
  17669. // Returns min and max coordinates
  17670. THREE.CurvePath.prototype.getBoundingBox = function () {
  17671. var points = this.getPoints();
  17672. var maxX, maxY, maxZ;
  17673. var minX, minY, minZ;
  17674. maxX = maxY = Number.NEGATIVE_INFINITY;
  17675. minX = minY = Number.POSITIVE_INFINITY;
  17676. var p, i, il, sum;
  17677. var v3 = points[ 0 ] instanceof THREE.Vector3;
  17678. sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
  17679. for ( i = 0, il = points.length; i < il; i ++ ) {
  17680. p = points[ i ];
  17681. if ( p.x > maxX ) maxX = p.x;
  17682. else if ( p.x < minX ) minX = p.x;
  17683. if ( p.y > maxY ) maxY = p.y;
  17684. else if ( p.y < minY ) minY = p.y;
  17685. if ( v3 ) {
  17686. if ( p.z > maxZ ) maxZ = p.z;
  17687. else if ( p.z < minZ ) minZ = p.z;
  17688. }
  17689. sum.add( p );
  17690. }
  17691. var ret = {
  17692. minX: minX,
  17693. minY: minY,
  17694. maxX: maxX,
  17695. maxY: maxY
  17696. };
  17697. if ( v3 ) {
  17698. ret.maxZ = maxZ;
  17699. ret.minZ = minZ;
  17700. }
  17701. return ret;
  17702. };
  17703. /**************************************************************
  17704. * Create Geometries Helpers
  17705. **************************************************************/
  17706. /// Generate geometry from path points (for Line or Points objects)
  17707. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  17708. var pts = this.getPoints( divisions, true );
  17709. return this.createGeometry( pts );
  17710. };
  17711. // Generate geometry from equidistant sampling along the path
  17712. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  17713. var pts = this.getSpacedPoints( divisions, true );
  17714. return this.createGeometry( pts );
  17715. };
  17716. THREE.CurvePath.prototype.createGeometry = function( points ) {
  17717. var geometry = new THREE.Geometry();
  17718. for ( var i = 0; i < points.length; i ++ ) {
  17719. geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, points[ i ].z || 0 ) );
  17720. }
  17721. return geometry;
  17722. };
  17723. /**************************************************************
  17724. * Bend / Wrap Helper Methods
  17725. **************************************************************/
  17726. // Wrap path / Bend modifiers?
  17727. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  17728. this.bends.push( bendpath );
  17729. };
  17730. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  17731. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  17732. var i, il;
  17733. if ( ! bends ) {
  17734. bends = this.bends;
  17735. }
  17736. for ( i = 0, il = bends.length; i < il; i ++ ) {
  17737. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  17738. }
  17739. return oldPts;
  17740. };
  17741. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  17742. var oldPts = this.getSpacedPoints( segments );
  17743. var i, il;
  17744. if ( ! bends ) {
  17745. bends = this.bends;
  17746. }
  17747. for ( i = 0, il = bends.length; i < il; i ++ ) {
  17748. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  17749. }
  17750. return oldPts;
  17751. };
  17752. // This returns getPoints() bend/wrapped around the contour of a path.
  17753. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  17754. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  17755. var bounds = this.getBoundingBox();
  17756. var i, il, p, oldX, oldY, xNorm;
  17757. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  17758. p = oldPts[ i ];
  17759. oldX = p.x;
  17760. oldY = p.y;
  17761. xNorm = oldX / bounds.maxX;
  17762. // If using actual distance, for length > path, requires line extrusions
  17763. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  17764. xNorm = path.getUtoTmapping( xNorm, oldX );
  17765. // check for out of bounds?
  17766. var pathPt = path.getPoint( xNorm );
  17767. var normal = path.getTangent( xNorm );
  17768. normal.set( - normal.y, normal.x ).multiplyScalar( oldY );
  17769. p.x = pathPt.x + normal.x;
  17770. p.y = pathPt.y + normal.y;
  17771. }
  17772. return oldPts;
  17773. };
  17774. // File:src/extras/core/Path.js
  17775. /**
  17776. * @author zz85 / http://www.lab4games.net/zz85/blog
  17777. * Creates free form 2d path using series of points, lines or curves.
  17778. *
  17779. **/
  17780. THREE.Path = function ( points ) {
  17781. THREE.CurvePath.call( this );
  17782. this.actions = [];
  17783. if ( points ) {
  17784. this.fromPoints( points );
  17785. }
  17786. };
  17787. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  17788. THREE.Path.prototype.constructor = THREE.Path;
  17789. THREE.PathActions = {
  17790. MOVE_TO: 'moveTo',
  17791. LINE_TO: 'lineTo',
  17792. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  17793. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  17794. CSPLINE_THRU: 'splineThru', // Catmull-Rom spline
  17795. ARC: 'arc', // Circle
  17796. ELLIPSE: 'ellipse'
  17797. };
  17798. // TODO Clean up PATH API
  17799. // Create path using straight lines to connect all points
  17800. // - vectors: array of Vector2
  17801. THREE.Path.prototype.fromPoints = function ( vectors ) {
  17802. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  17803. for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
  17804. this.lineTo( vectors[ v ].x, vectors[ v ].y );
  17805. }
  17806. };
  17807. // startPath() endPath()?
  17808. THREE.Path.prototype.moveTo = function ( x, y ) {
  17809. var args = Array.prototype.slice.call( arguments );
  17810. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  17811. };
  17812. THREE.Path.prototype.lineTo = function ( x, y ) {
  17813. var args = Array.prototype.slice.call( arguments );
  17814. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17815. var x0 = lastargs[ lastargs.length - 2 ];
  17816. var y0 = lastargs[ lastargs.length - 1 ];
  17817. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  17818. this.curves.push( curve );
  17819. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  17820. };
  17821. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  17822. var args = Array.prototype.slice.call( arguments );
  17823. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17824. var x0 = lastargs[ lastargs.length - 2 ];
  17825. var y0 = lastargs[ lastargs.length - 1 ];
  17826. var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
  17827. new THREE.Vector2( aCPx, aCPy ),
  17828. new THREE.Vector2( aX, aY ) );
  17829. this.curves.push( curve );
  17830. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  17831. };
  17832. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
  17833. aCP2x, aCP2y,
  17834. aX, aY ) {
  17835. var args = Array.prototype.slice.call( arguments );
  17836. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17837. var x0 = lastargs[ lastargs.length - 2 ];
  17838. var y0 = lastargs[ lastargs.length - 1 ];
  17839. var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
  17840. new THREE.Vector2( aCP1x, aCP1y ),
  17841. new THREE.Vector2( aCP2x, aCP2y ),
  17842. new THREE.Vector2( aX, aY ) );
  17843. this.curves.push( curve );
  17844. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  17845. };
  17846. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  17847. var args = Array.prototype.slice.call( arguments );
  17848. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17849. var x0 = lastargs[ lastargs.length - 2 ];
  17850. var y0 = lastargs[ lastargs.length - 1 ];
  17851. //---
  17852. var npts = [ new THREE.Vector2( x0, y0 ) ];
  17853. Array.prototype.push.apply( npts, pts );
  17854. var curve = new THREE.SplineCurve( npts );
  17855. this.curves.push( curve );
  17856. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  17857. };
  17858. // FUTURE: Change the API or follow canvas API?
  17859. THREE.Path.prototype.arc = function ( aX, aY, aRadius,
  17860. aStartAngle, aEndAngle, aClockwise ) {
  17861. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17862. var x0 = lastargs[ lastargs.length - 2 ];
  17863. var y0 = lastargs[ lastargs.length - 1 ];
  17864. this.absarc( aX + x0, aY + y0, aRadius,
  17865. aStartAngle, aEndAngle, aClockwise );
  17866. };
  17867. THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
  17868. aStartAngle, aEndAngle, aClockwise ) {
  17869. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17870. };
  17871. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
  17872. aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17873. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17874. var x0 = lastargs[ lastargs.length - 2 ];
  17875. var y0 = lastargs[ lastargs.length - 1 ];
  17876. this.absellipse( aX + x0, aY + y0, xRadius, yRadius,
  17877. aStartAngle, aEndAngle, aClockwise, aRotation );
  17878. };
  17879. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
  17880. aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17881. var args = [
  17882. aX, aY,
  17883. xRadius, yRadius,
  17884. aStartAngle, aEndAngle,
  17885. aClockwise,
  17886. aRotation || 0 // aRotation is optional.
  17887. ];
  17888. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
  17889. aStartAngle, aEndAngle, aClockwise, aRotation );
  17890. this.curves.push( curve );
  17891. var lastPoint = curve.getPoint( 1 );
  17892. args.push( lastPoint.x );
  17893. args.push( lastPoint.y );
  17894. this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
  17895. };
  17896. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  17897. if ( ! divisions ) divisions = 40;
  17898. var points = [];
  17899. for ( var i = 0; i < divisions; i ++ ) {
  17900. points.push( this.getPoint( i / divisions ) );
  17901. //if( !this.getPoint( i / divisions ) ) throw "DIE";
  17902. }
  17903. // if ( closedPath ) {
  17904. //
  17905. // points.push( points[ 0 ] );
  17906. //
  17907. // }
  17908. return points;
  17909. };
  17910. /* Return an array of vectors based on contour of the path */
  17911. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  17912. if ( this.useSpacedPoints ) {
  17913. return this.getSpacedPoints( divisions, closedPath );
  17914. }
  17915. divisions = divisions || 12;
  17916. var points = [];
  17917. var i, il, item, action, args;
  17918. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  17919. laste, j,
  17920. t, tx, ty;
  17921. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  17922. item = this.actions[ i ];
  17923. action = item.action;
  17924. args = item.args;
  17925. switch ( action ) {
  17926. case THREE.PathActions.MOVE_TO:
  17927. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  17928. break;
  17929. case THREE.PathActions.LINE_TO:
  17930. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  17931. break;
  17932. case THREE.PathActions.QUADRATIC_CURVE_TO:
  17933. cpx = args[ 2 ];
  17934. cpy = args[ 3 ];
  17935. cpx1 = args[ 0 ];
  17936. cpy1 = args[ 1 ];
  17937. if ( points.length > 0 ) {
  17938. laste = points[ points.length - 1 ];
  17939. cpx0 = laste.x;
  17940. cpy0 = laste.y;
  17941. } else {
  17942. laste = this.actions[ i - 1 ].args;
  17943. cpx0 = laste[ laste.length - 2 ];
  17944. cpy0 = laste[ laste.length - 1 ];
  17945. }
  17946. for ( j = 1; j <= divisions; j ++ ) {
  17947. t = j / divisions;
  17948. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  17949. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  17950. points.push( new THREE.Vector2( tx, ty ) );
  17951. }
  17952. break;
  17953. case THREE.PathActions.BEZIER_CURVE_TO:
  17954. cpx = args[ 4 ];
  17955. cpy = args[ 5 ];
  17956. cpx1 = args[ 0 ];
  17957. cpy1 = args[ 1 ];
  17958. cpx2 = args[ 2 ];
  17959. cpy2 = args[ 3 ];
  17960. if ( points.length > 0 ) {
  17961. laste = points[ points.length - 1 ];
  17962. cpx0 = laste.x;
  17963. cpy0 = laste.y;
  17964. } else {
  17965. laste = this.actions[ i - 1 ].args;
  17966. cpx0 = laste[ laste.length - 2 ];
  17967. cpy0 = laste[ laste.length - 1 ];
  17968. }
  17969. for ( j = 1; j <= divisions; j ++ ) {
  17970. t = j / divisions;
  17971. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  17972. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  17973. points.push( new THREE.Vector2( tx, ty ) );
  17974. }
  17975. break;
  17976. case THREE.PathActions.CSPLINE_THRU:
  17977. laste = this.actions[ i - 1 ].args;
  17978. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  17979. var spts = [ last ];
  17980. var n = divisions * args[ 0 ].length;
  17981. spts = spts.concat( args[ 0 ] );
  17982. var spline = new THREE.SplineCurve( spts );
  17983. for ( j = 1; j <= n; j ++ ) {
  17984. points.push( spline.getPointAt( j / n ) );
  17985. }
  17986. break;
  17987. case THREE.PathActions.ARC:
  17988. var aX = args[ 0 ], aY = args[ 1 ],
  17989. aRadius = args[ 2 ],
  17990. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  17991. aClockwise = !! args[ 5 ];
  17992. var deltaAngle = aEndAngle - aStartAngle;
  17993. var angle;
  17994. var tdivisions = divisions * 2;
  17995. for ( j = 1; j <= tdivisions; j ++ ) {
  17996. t = j / tdivisions;
  17997. if ( ! aClockwise ) {
  17998. t = 1 - t;
  17999. }
  18000. angle = aStartAngle + t * deltaAngle;
  18001. tx = aX + aRadius * Math.cos( angle );
  18002. ty = aY + aRadius * Math.sin( angle );
  18003. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  18004. points.push( new THREE.Vector2( tx, ty ) );
  18005. }
  18006. //console.log(points);
  18007. break;
  18008. case THREE.PathActions.ELLIPSE:
  18009. var aX = args[ 0 ], aY = args[ 1 ],
  18010. xRadius = args[ 2 ],
  18011. yRadius = args[ 3 ],
  18012. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  18013. aClockwise = !! args[ 6 ],
  18014. aRotation = args[ 7 ];
  18015. var deltaAngle = aEndAngle - aStartAngle;
  18016. var angle;
  18017. var tdivisions = divisions * 2;
  18018. var cos, sin;
  18019. if ( aRotation !== 0 ) {
  18020. cos = Math.cos( aRotation );
  18021. sin = Math.sin( aRotation );
  18022. }
  18023. for ( j = 1; j <= tdivisions; j ++ ) {
  18024. t = j / tdivisions;
  18025. if ( ! aClockwise ) {
  18026. t = 1 - t;
  18027. }
  18028. angle = aStartAngle + t * deltaAngle;
  18029. tx = aX + xRadius * Math.cos( angle );
  18030. ty = aY + yRadius * Math.sin( angle );
  18031. if ( aRotation !== 0 ) {
  18032. var x = tx, y = ty;
  18033. // Rotate the point about the center of the ellipse.
  18034. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  18035. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  18036. }
  18037. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  18038. points.push( new THREE.Vector2( tx, ty ) );
  18039. }
  18040. //console.log(points);
  18041. break;
  18042. } // end switch
  18043. }
  18044. // Normalize to remove the closing point by default.
  18045. var lastPoint = points[ points.length - 1 ];
  18046. var EPSILON = 0.0000000001;
  18047. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < EPSILON &&
  18048. Math.abs( lastPoint.y - points[ 0 ].y ) < EPSILON )
  18049. points.splice( points.length - 1, 1 );
  18050. if ( closedPath ) {
  18051. points.push( points[ 0 ] );
  18052. }
  18053. return points;
  18054. };
  18055. //
  18056. // Breaks path into shapes
  18057. //
  18058. // Assumptions (if parameter isCCW==true the opposite holds):
  18059. // - solid shapes are defined clockwise (CW)
  18060. // - holes are defined counterclockwise (CCW)
  18061. //
  18062. // If parameter noHoles==true:
  18063. // - all subPaths are regarded as solid shapes
  18064. // - definition order CW/CCW has no relevance
  18065. //
  18066. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  18067. function extractSubpaths( inActions ) {
  18068. var i, il, item, action, args;
  18069. var subPaths = [], lastPath = new THREE.Path();
  18070. for ( i = 0, il = inActions.length; i < il; i ++ ) {
  18071. item = inActions[ i ];
  18072. args = item.args;
  18073. action = item.action;
  18074. if ( action === THREE.PathActions.MOVE_TO ) {
  18075. if ( lastPath.actions.length !== 0 ) {
  18076. subPaths.push( lastPath );
  18077. lastPath = new THREE.Path();
  18078. }
  18079. }
  18080. lastPath[ action ].apply( lastPath, args );
  18081. }
  18082. if ( lastPath.actions.length !== 0 ) {
  18083. subPaths.push( lastPath );
  18084. }
  18085. // console.log(subPaths);
  18086. return subPaths;
  18087. }
  18088. function toShapesNoHoles( inSubpaths ) {
  18089. var shapes = [];
  18090. for ( var i = 0, il = inSubpaths.length; i < il; i ++ ) {
  18091. var tmpPath = inSubpaths[ i ];
  18092. var tmpShape = new THREE.Shape();
  18093. tmpShape.actions = tmpPath.actions;
  18094. tmpShape.curves = tmpPath.curves;
  18095. shapes.push( tmpShape );
  18096. }
  18097. //console.log("shape", shapes);
  18098. return shapes;
  18099. }
  18100. function isPointInsidePolygon( inPt, inPolygon ) {
  18101. var EPSILON = 0.0000000001;
  18102. var polyLen = inPolygon.length;
  18103. // inPt on polygon contour => immediate success or
  18104. // toggling of inside/outside at every single! intersection point of an edge
  18105. // with the horizontal line through inPt, left of inPt
  18106. // not counting lowerY endpoints of edges and whole edges on that line
  18107. var inside = false;
  18108. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  18109. var edgeLowPt = inPolygon[ p ];
  18110. var edgeHighPt = inPolygon[ q ];
  18111. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  18112. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  18113. if ( Math.abs( edgeDy ) > EPSILON ) {
  18114. // not parallel
  18115. if ( edgeDy < 0 ) {
  18116. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  18117. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  18118. }
  18119. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  18120. if ( inPt.y === edgeLowPt.y ) {
  18121. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  18122. // continue; // no intersection or edgeLowPt => doesn't count !!!
  18123. } else {
  18124. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  18125. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  18126. if ( perpEdge < 0 ) continue;
  18127. inside = ! inside; // true intersection left of inPt
  18128. }
  18129. } else {
  18130. // parallel or collinear
  18131. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  18132. // edge lies on the same horizontal line as inPt
  18133. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  18134. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  18135. // continue;
  18136. }
  18137. }
  18138. return inside;
  18139. }
  18140. var subPaths = extractSubpaths( this.actions );
  18141. if ( subPaths.length === 0 ) return [];
  18142. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  18143. var solid, tmpPath, tmpShape, shapes = [];
  18144. if ( subPaths.length === 1 ) {
  18145. tmpPath = subPaths[ 0 ];
  18146. tmpShape = new THREE.Shape();
  18147. tmpShape.actions = tmpPath.actions;
  18148. tmpShape.curves = tmpPath.curves;
  18149. shapes.push( tmpShape );
  18150. return shapes;
  18151. }
  18152. var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  18153. holesFirst = isCCW ? ! holesFirst : holesFirst;
  18154. // console.log("Holes first", holesFirst);
  18155. var betterShapeHoles = [];
  18156. var newShapes = [];
  18157. var newShapeHoles = [];
  18158. var mainIdx = 0;
  18159. var tmpPoints;
  18160. newShapes[ mainIdx ] = undefined;
  18161. newShapeHoles[ mainIdx ] = [];
  18162. var i, il;
  18163. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  18164. tmpPath = subPaths[ i ];
  18165. tmpPoints = tmpPath.getPoints();
  18166. solid = THREE.Shape.Utils.isClockWise( tmpPoints );
  18167. solid = isCCW ? ! solid : solid;
  18168. if ( solid ) {
  18169. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  18170. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  18171. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  18172. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  18173. if ( holesFirst ) mainIdx ++;
  18174. newShapeHoles[ mainIdx ] = [];
  18175. //console.log('cw', i);
  18176. } else {
  18177. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  18178. //console.log('ccw', i);
  18179. }
  18180. }
  18181. // only Holes? -> probably all Shapes with wrong orientation
  18182. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  18183. if ( newShapes.length > 1 ) {
  18184. var ambiguous = false;
  18185. var toChange = [];
  18186. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18187. betterShapeHoles[ sIdx ] = [];
  18188. }
  18189. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18190. var sho = newShapeHoles[ sIdx ];
  18191. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  18192. var ho = sho[ hIdx ];
  18193. var hole_unassigned = true;
  18194. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  18195. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  18196. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  18197. if ( hole_unassigned ) {
  18198. hole_unassigned = false;
  18199. betterShapeHoles[ s2Idx ].push( ho );
  18200. } else {
  18201. ambiguous = true;
  18202. }
  18203. }
  18204. }
  18205. if ( hole_unassigned ) {
  18206. betterShapeHoles[ sIdx ].push( ho );
  18207. }
  18208. }
  18209. }
  18210. // console.log("ambiguous: ", ambiguous);
  18211. if ( toChange.length > 0 ) {
  18212. // console.log("to change: ", toChange);
  18213. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  18214. }
  18215. }
  18216. var tmpHoles, j, jl;
  18217. for ( i = 0, il = newShapes.length; i < il; i ++ ) {
  18218. tmpShape = newShapes[ i ].s;
  18219. shapes.push( tmpShape );
  18220. tmpHoles = newShapeHoles[ i ];
  18221. for ( j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  18222. tmpShape.holes.push( tmpHoles[ j ].h );
  18223. }
  18224. }
  18225. //console.log("shape", shapes);
  18226. return shapes;
  18227. };
  18228. // File:src/extras/core/Shape.js
  18229. /**
  18230. * @author zz85 / http://www.lab4games.net/zz85/blog
  18231. * Defines a 2d shape plane using paths.
  18232. **/
  18233. // STEP 1 Create a path.
  18234. // STEP 2 Turn path into shape.
  18235. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  18236. // STEP 3a - Extract points from each shape, turn to vertices
  18237. // STEP 3b - Triangulate each shape, add faces.
  18238. THREE.Shape = function () {
  18239. THREE.Path.apply( this, arguments );
  18240. this.holes = [];
  18241. };
  18242. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  18243. THREE.Shape.prototype.constructor = THREE.Shape;
  18244. // Convenience method to return ExtrudeGeometry
  18245. THREE.Shape.prototype.extrude = function ( options ) {
  18246. var extruded = new THREE.ExtrudeGeometry( this, options );
  18247. return extruded;
  18248. };
  18249. // Convenience method to return ShapeGeometry
  18250. THREE.Shape.prototype.makeGeometry = function ( options ) {
  18251. var geometry = new THREE.ShapeGeometry( this, options );
  18252. return geometry;
  18253. };
  18254. // Get points of holes
  18255. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  18256. var i, il = this.holes.length, holesPts = [];
  18257. for ( i = 0; i < il; i ++ ) {
  18258. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  18259. }
  18260. return holesPts;
  18261. };
  18262. // Get points of holes (spaced by regular distance)
  18263. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  18264. var i, il = this.holes.length, holesPts = [];
  18265. for ( i = 0; i < il; i ++ ) {
  18266. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  18267. }
  18268. return holesPts;
  18269. };
  18270. // Get points of shape and holes (keypoints based on segments parameter)
  18271. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  18272. return {
  18273. shape: this.getTransformedPoints( divisions ),
  18274. holes: this.getPointsHoles( divisions )
  18275. };
  18276. };
  18277. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  18278. if ( this.useSpacedPoints ) {
  18279. return this.extractAllSpacedPoints( divisions );
  18280. }
  18281. return this.extractAllPoints( divisions );
  18282. };
  18283. //
  18284. // THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  18285. //
  18286. // return {
  18287. //
  18288. // shape: this.transform( bend, divisions ),
  18289. // holes: this.getPointsHoles( divisions, bend )
  18290. //
  18291. // };
  18292. //
  18293. // };
  18294. // Get points of shape and holes (spaced by regular distance)
  18295. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  18296. return {
  18297. shape: this.getTransformedSpacedPoints( divisions ),
  18298. holes: this.getSpacedPointsHoles( divisions )
  18299. };
  18300. };
  18301. /**************************************************************
  18302. * Utils
  18303. **************************************************************/
  18304. THREE.Shape.Utils = {
  18305. triangulateShape: function ( contour, holes ) {
  18306. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  18307. // inOtherPt needs to be collinear to the inSegment
  18308. if ( inSegPt1.x !== inSegPt2.x ) {
  18309. if ( inSegPt1.x < inSegPt2.x ) {
  18310. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  18311. } else {
  18312. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  18313. }
  18314. } else {
  18315. if ( inSegPt1.y < inSegPt2.y ) {
  18316. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  18317. } else {
  18318. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  18319. }
  18320. }
  18321. }
  18322. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  18323. var EPSILON = 0.0000000001;
  18324. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  18325. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  18326. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  18327. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  18328. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  18329. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  18330. if ( Math.abs( limit ) > EPSILON ) {
  18331. // not parallel
  18332. var perpSeg2;
  18333. if ( limit > 0 ) {
  18334. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  18335. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  18336. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  18337. } else {
  18338. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  18339. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  18340. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  18341. }
  18342. // i.e. to reduce rounding errors
  18343. // intersection at endpoint of segment#1?
  18344. if ( perpSeg2 === 0 ) {
  18345. if ( ( inExcludeAdjacentSegs ) &&
  18346. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  18347. return [ inSeg1Pt1 ];
  18348. }
  18349. if ( perpSeg2 === limit ) {
  18350. if ( ( inExcludeAdjacentSegs ) &&
  18351. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  18352. return [ inSeg1Pt2 ];
  18353. }
  18354. // intersection at endpoint of segment#2?
  18355. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  18356. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  18357. // return real intersection point
  18358. var factorSeg1 = perpSeg2 / limit;
  18359. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  18360. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  18361. } else {
  18362. // parallel or collinear
  18363. if ( ( perpSeg1 !== 0 ) ||
  18364. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  18365. // they are collinear or degenerate
  18366. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  18367. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  18368. // both segments are points
  18369. if ( seg1Pt && seg2Pt ) {
  18370. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  18371. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  18372. return [ inSeg1Pt1 ]; // they are the same point
  18373. }
  18374. // segment#1 is a single point
  18375. if ( seg1Pt ) {
  18376. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  18377. return [ inSeg1Pt1 ];
  18378. }
  18379. // segment#2 is a single point
  18380. if ( seg2Pt ) {
  18381. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  18382. return [ inSeg2Pt1 ];
  18383. }
  18384. // they are collinear segments, which might overlap
  18385. var seg1min, seg1max, seg1minVal, seg1maxVal;
  18386. var seg2min, seg2max, seg2minVal, seg2maxVal;
  18387. if ( seg1dx !== 0 ) {
  18388. // the segments are NOT on a vertical line
  18389. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  18390. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  18391. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  18392. } else {
  18393. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  18394. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  18395. }
  18396. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  18397. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  18398. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  18399. } else {
  18400. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  18401. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  18402. }
  18403. } else {
  18404. // the segments are on a vertical line
  18405. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  18406. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  18407. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  18408. } else {
  18409. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  18410. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  18411. }
  18412. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  18413. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  18414. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  18415. } else {
  18416. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  18417. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  18418. }
  18419. }
  18420. if ( seg1minVal <= seg2minVal ) {
  18421. if ( seg1maxVal < seg2minVal ) return [];
  18422. if ( seg1maxVal === seg2minVal ) {
  18423. if ( inExcludeAdjacentSegs ) return [];
  18424. return [ seg2min ];
  18425. }
  18426. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  18427. return [ seg2min, seg2max ];
  18428. } else {
  18429. if ( seg1minVal > seg2maxVal ) return [];
  18430. if ( seg1minVal === seg2maxVal ) {
  18431. if ( inExcludeAdjacentSegs ) return [];
  18432. return [ seg1min ];
  18433. }
  18434. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  18435. return [ seg1min, seg2max ];
  18436. }
  18437. }
  18438. }
  18439. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  18440. // The order of legs is important
  18441. var EPSILON = 0.0000000001;
  18442. // translation of all points, so that Vertex is at (0,0)
  18443. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  18444. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  18445. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  18446. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  18447. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  18448. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  18449. if ( Math.abs( from2toAngle ) > EPSILON ) {
  18450. // angle != 180 deg.
  18451. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  18452. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  18453. if ( from2toAngle > 0 ) {
  18454. // main angle < 180 deg.
  18455. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  18456. } else {
  18457. // main angle > 180 deg.
  18458. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  18459. }
  18460. } else {
  18461. // angle == 180 deg.
  18462. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  18463. return ( from2otherAngle > 0 );
  18464. }
  18465. }
  18466. function removeHoles( contour, holes ) {
  18467. var shape = contour.concat(); // work on this shape
  18468. var hole;
  18469. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  18470. // Check if hole point lies within angle around shape point
  18471. var lastShapeIdx = shape.length - 1;
  18472. var prevShapeIdx = inShapeIdx - 1;
  18473. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  18474. var nextShapeIdx = inShapeIdx + 1;
  18475. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  18476. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  18477. if ( ! insideAngle ) {
  18478. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  18479. return false;
  18480. }
  18481. // Check if shape point lies within angle around hole point
  18482. var lastHoleIdx = hole.length - 1;
  18483. var prevHoleIdx = inHoleIdx - 1;
  18484. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  18485. var nextHoleIdx = inHoleIdx + 1;
  18486. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  18487. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  18488. if ( ! insideAngle ) {
  18489. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  18490. return false;
  18491. }
  18492. return true;
  18493. }
  18494. function intersectsShapeEdge( inShapePt, inHolePt ) {
  18495. // checks for intersections with shape edges
  18496. var sIdx, nextIdx, intersection;
  18497. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  18498. nextIdx = sIdx + 1; nextIdx %= shape.length;
  18499. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  18500. if ( intersection.length > 0 ) return true;
  18501. }
  18502. return false;
  18503. }
  18504. var indepHoles = [];
  18505. function intersectsHoleEdge( inShapePt, inHolePt ) {
  18506. // checks for intersections with hole edges
  18507. var ihIdx, chkHole,
  18508. hIdx, nextIdx, intersection;
  18509. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  18510. chkHole = holes[ indepHoles[ ihIdx ]];
  18511. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  18512. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  18513. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  18514. if ( intersection.length > 0 ) return true;
  18515. }
  18516. }
  18517. return false;
  18518. }
  18519. var holeIndex, shapeIndex,
  18520. shapePt, holePt,
  18521. holeIdx, cutKey, failedCuts = [],
  18522. tmpShape1, tmpShape2,
  18523. tmpHole1, tmpHole2;
  18524. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  18525. indepHoles.push( h );
  18526. }
  18527. var minShapeIndex = 0;
  18528. var counter = indepHoles.length * 2;
  18529. while ( indepHoles.length > 0 ) {
  18530. counter --;
  18531. if ( counter < 0 ) {
  18532. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  18533. break;
  18534. }
  18535. // search for shape-vertex and hole-vertex,
  18536. // which can be connected without intersections
  18537. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  18538. shapePt = shape[ shapeIndex ];
  18539. holeIndex = - 1;
  18540. // search for hole which can be reached without intersections
  18541. for ( var h = 0; h < indepHoles.length; h ++ ) {
  18542. holeIdx = indepHoles[ h ];
  18543. // prevent multiple checks
  18544. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  18545. if ( failedCuts[ cutKey ] !== undefined ) continue;
  18546. hole = holes[ holeIdx ];
  18547. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  18548. holePt = hole[ h2 ];
  18549. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  18550. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  18551. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  18552. holeIndex = h2;
  18553. indepHoles.splice( h, 1 );
  18554. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  18555. tmpShape2 = shape.slice( shapeIndex );
  18556. tmpHole1 = hole.slice( holeIndex );
  18557. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  18558. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  18559. minShapeIndex = shapeIndex;
  18560. // Debug only, to show the selected cuts
  18561. // glob_CutLines.push( [ shapePt, holePt ] );
  18562. break;
  18563. }
  18564. if ( holeIndex >= 0 ) break; // hole-vertex found
  18565. failedCuts[ cutKey ] = true; // remember failure
  18566. }
  18567. if ( holeIndex >= 0 ) break; // hole-vertex found
  18568. }
  18569. }
  18570. return shape; /* shape with no holes */
  18571. }
  18572. var i, il, f, face,
  18573. key, index,
  18574. allPointsMap = {};
  18575. // 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.
  18576. var allpoints = contour.concat();
  18577. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  18578. Array.prototype.push.apply( allpoints, holes[ h ] );
  18579. }
  18580. //console.log( "allpoints",allpoints, allpoints.length );
  18581. // prepare all points map
  18582. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  18583. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  18584. if ( allPointsMap[ key ] !== undefined ) {
  18585. console.warn( "THREE.Shape: Duplicate point", key );
  18586. }
  18587. allPointsMap[ key ] = i;
  18588. }
  18589. // remove holes by cutting paths to holes and adding them to the shape
  18590. var shapeWithoutHoles = removeHoles( contour, holes );
  18591. var triangles = THREE.FontUtils.Triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  18592. //console.log( "triangles",triangles, triangles.length );
  18593. // check all face vertices against all points map
  18594. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  18595. face = triangles[ i ];
  18596. for ( f = 0; f < 3; f ++ ) {
  18597. key = face[ f ].x + ":" + face[ f ].y;
  18598. index = allPointsMap[ key ];
  18599. if ( index !== undefined ) {
  18600. face[ f ] = index;
  18601. }
  18602. }
  18603. }
  18604. return triangles.concat();
  18605. },
  18606. isClockWise: function ( pts ) {
  18607. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  18608. },
  18609. // Bezier Curves formulas obtained from
  18610. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  18611. // Quad Bezier Functions
  18612. b2p0: function ( t, p ) {
  18613. var k = 1 - t;
  18614. return k * k * p;
  18615. },
  18616. b2p1: function ( t, p ) {
  18617. return 2 * ( 1 - t ) * t * p;
  18618. },
  18619. b2p2: function ( t, p ) {
  18620. return t * t * p;
  18621. },
  18622. b2: function ( t, p0, p1, p2 ) {
  18623. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  18624. },
  18625. // Cubic Bezier Functions
  18626. b3p0: function ( t, p ) {
  18627. var k = 1 - t;
  18628. return k * k * k * p;
  18629. },
  18630. b3p1: function ( t, p ) {
  18631. var k = 1 - t;
  18632. return 3 * k * k * t * p;
  18633. },
  18634. b3p2: function ( t, p ) {
  18635. var k = 1 - t;
  18636. return 3 * k * t * t * p;
  18637. },
  18638. b3p3: function ( t, p ) {
  18639. return t * t * t * p;
  18640. },
  18641. b3: function ( t, p0, p1, p2, p3 ) {
  18642. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  18643. }
  18644. };
  18645. // File:src/extras/curves/LineCurve.js
  18646. /**************************************************************
  18647. * Line
  18648. **************************************************************/
  18649. THREE.LineCurve = function ( v1, v2 ) {
  18650. this.v1 = v1;
  18651. this.v2 = v2;
  18652. };
  18653. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  18654. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  18655. THREE.LineCurve.prototype.getPoint = function ( t ) {
  18656. var point = this.v2.clone().sub( this.v1 );
  18657. point.multiplyScalar( t ).add( this.v1 );
  18658. return point;
  18659. };
  18660. // Line curve is linear, so we can overwrite default getPointAt
  18661. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  18662. return this.getPoint( u );
  18663. };
  18664. THREE.LineCurve.prototype.getTangent = function( t ) {
  18665. var tangent = this.v2.clone().sub( this.v1 );
  18666. return tangent.normalize();
  18667. };
  18668. // File:src/extras/curves/QuadraticBezierCurve.js
  18669. /**************************************************************
  18670. * Quadratic Bezier curve
  18671. **************************************************************/
  18672. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  18673. this.v0 = v0;
  18674. this.v1 = v1;
  18675. this.v2 = v2;
  18676. };
  18677. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  18678. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  18679. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  18680. var vector = new THREE.Vector2();
  18681. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  18682. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  18683. return vector;
  18684. };
  18685. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  18686. var vector = new THREE.Vector2();
  18687. vector.x = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  18688. vector.y = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  18689. // returns unit vector
  18690. return vector.normalize();
  18691. };
  18692. // File:src/extras/curves/CubicBezierCurve.js
  18693. /**************************************************************
  18694. * Cubic Bezier curve
  18695. **************************************************************/
  18696. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  18697. this.v0 = v0;
  18698. this.v1 = v1;
  18699. this.v2 = v2;
  18700. this.v3 = v3;
  18701. };
  18702. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  18703. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  18704. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  18705. var tx, ty;
  18706. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18707. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18708. return new THREE.Vector2( tx, ty );
  18709. };
  18710. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  18711. var tx, ty;
  18712. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18713. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18714. var tangent = new THREE.Vector2( tx, ty );
  18715. tangent.normalize();
  18716. return tangent;
  18717. };
  18718. // File:src/extras/curves/SplineCurve.js
  18719. /**************************************************************
  18720. * Spline curve
  18721. **************************************************************/
  18722. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  18723. this.points = ( points == undefined ) ? [] : points;
  18724. };
  18725. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  18726. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  18727. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  18728. var points = this.points;
  18729. var point = ( points.length - 1 ) * t;
  18730. var intPoint = Math.floor( point );
  18731. var weight = point - intPoint;
  18732. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  18733. var point1 = points[ intPoint ];
  18734. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18735. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18736. var vector = new THREE.Vector2();
  18737. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  18738. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  18739. return vector;
  18740. };
  18741. // File:src/extras/curves/EllipseCurve.js
  18742. /**************************************************************
  18743. * Ellipse curve
  18744. **************************************************************/
  18745. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18746. this.aX = aX;
  18747. this.aY = aY;
  18748. this.xRadius = xRadius;
  18749. this.yRadius = yRadius;
  18750. this.aStartAngle = aStartAngle;
  18751. this.aEndAngle = aEndAngle;
  18752. this.aClockwise = aClockwise;
  18753. this.aRotation = aRotation || 0;
  18754. };
  18755. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  18756. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  18757. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  18758. var deltaAngle = this.aEndAngle - this.aStartAngle;
  18759. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  18760. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  18761. var angle;
  18762. if ( this.aClockwise === true ) {
  18763. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  18764. } else {
  18765. angle = this.aStartAngle + t * deltaAngle;
  18766. }
  18767. var x = this.aX + this.xRadius * Math.cos( angle );
  18768. var y = this.aY + this.yRadius * Math.sin( angle );
  18769. if ( this.aRotation !== 0 ) {
  18770. var cos = Math.cos( this.aRotation );
  18771. var sin = Math.sin( this.aRotation );
  18772. var tx = x, ty = y;
  18773. // Rotate the point about the center of the ellipse.
  18774. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  18775. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  18776. }
  18777. return new THREE.Vector2( x, y );
  18778. };
  18779. // File:src/extras/curves/ArcCurve.js
  18780. /**************************************************************
  18781. * Arc curve
  18782. **************************************************************/
  18783. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  18784. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  18785. };
  18786. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  18787. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  18788. // File:src/extras/curves/LineCurve3.js
  18789. /**************************************************************
  18790. * Line3D
  18791. **************************************************************/
  18792. THREE.LineCurve3 = THREE.Curve.create(
  18793. function ( v1, v2 ) {
  18794. this.v1 = v1;
  18795. this.v2 = v2;
  18796. },
  18797. function ( t ) {
  18798. var vector = new THREE.Vector3();
  18799. vector.subVectors( this.v2, this.v1 ); // diff
  18800. vector.multiplyScalar( t );
  18801. vector.add( this.v1 );
  18802. return vector;
  18803. }
  18804. );
  18805. // File:src/extras/curves/QuadraticBezierCurve3.js
  18806. /**************************************************************
  18807. * Quadratic Bezier 3D curve
  18808. **************************************************************/
  18809. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  18810. function ( v0, v1, v2 ) {
  18811. this.v0 = v0;
  18812. this.v1 = v1;
  18813. this.v2 = v2;
  18814. },
  18815. function ( t ) {
  18816. var vector = new THREE.Vector3();
  18817. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  18818. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  18819. vector.z = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  18820. return vector;
  18821. }
  18822. );
  18823. // File:src/extras/curves/CubicBezierCurve3.js
  18824. /**************************************************************
  18825. * Cubic Bezier 3D curve
  18826. **************************************************************/
  18827. THREE.CubicBezierCurve3 = THREE.Curve.create(
  18828. function ( v0, v1, v2, v3 ) {
  18829. this.v0 = v0;
  18830. this.v1 = v1;
  18831. this.v2 = v2;
  18832. this.v3 = v3;
  18833. },
  18834. function ( t ) {
  18835. var vector = new THREE.Vector3();
  18836. vector.x = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18837. vector.y = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18838. vector.z = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  18839. return vector;
  18840. }
  18841. );
  18842. // File:src/extras/curves/SplineCurve3.js
  18843. /**************************************************************
  18844. * Spline 3D curve
  18845. **************************************************************/
  18846. THREE.SplineCurve3 = THREE.Curve.create(
  18847. function ( points /* array of Vector3 */ ) {
  18848. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  18849. this.points = ( points == undefined ) ? [] : points;
  18850. },
  18851. function ( t ) {
  18852. var points = this.points;
  18853. var point = ( points.length - 1 ) * t;
  18854. var intPoint = Math.floor( point );
  18855. var weight = point - intPoint;
  18856. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  18857. var point1 = points[ intPoint ];
  18858. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18859. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18860. var vector = new THREE.Vector3();
  18861. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  18862. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  18863. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  18864. return vector;
  18865. }
  18866. );
  18867. // File:src/extras/curves/CatmullRomCurve3.js
  18868. /**
  18869. * @author zz85 https://github.com/zz85
  18870. *
  18871. * Centripetal CatmullRom Curve - which is useful for avoiding
  18872. * cusps and self-intersections in non-uniform catmull rom curves.
  18873. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  18874. *
  18875. * curve.type accepts centripetal(default), chordal and catmullrom
  18876. * curve.tension is used for catmullrom which defaults to 0.5
  18877. */
  18878. THREE.CatmullRomCurve3 = ( function() {
  18879. var
  18880. tmp = new THREE.Vector3(),
  18881. px = new CubicPoly(),
  18882. py = new CubicPoly(),
  18883. pz = new CubicPoly();
  18884. /*
  18885. Based on an optimized c++ solution in
  18886. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  18887. - http://ideone.com/NoEbVM
  18888. This CubicPoly class could be used for reusing some variables and calculations,
  18889. but for three.js curve use, it could be possible inlined and flatten into a single function call
  18890. which can be placed in CurveUtils.
  18891. */
  18892. function CubicPoly() {
  18893. }
  18894. /*
  18895. * Compute coefficients for a cubic polynomial
  18896. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  18897. * such that
  18898. * p(0) = x0, p(1) = x1
  18899. * and
  18900. * p'(0) = t0, p'(1) = t1.
  18901. */
  18902. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  18903. this.c0 = x0;
  18904. this.c1 = t0;
  18905. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  18906. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  18907. };
  18908. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  18909. // compute tangents when parameterized in [t1,t2]
  18910. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  18911. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  18912. // rescale tangents for parametrization in [0,1]
  18913. t1 *= dt1;
  18914. t2 *= dt1;
  18915. // initCubicPoly
  18916. this.init( x1, x2, t1, t2 );
  18917. };
  18918. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  18919. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  18920. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  18921. };
  18922. CubicPoly.prototype.calc = function( t ) {
  18923. var t2 = t * t;
  18924. var t3 = t2 * t;
  18925. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  18926. };
  18927. // Subclass Three.js curve
  18928. return THREE.Curve.create(
  18929. function ( p /* array of Vector3 */ ) {
  18930. this.points = p || [];
  18931. },
  18932. function ( t ) {
  18933. var points = this.points,
  18934. point, intPoint, weight, l;
  18935. l = points.length;
  18936. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  18937. point = ( l - 1 ) * t;
  18938. intPoint = Math.floor( point );
  18939. weight = point - intPoint;
  18940. if ( weight === 0 && intPoint === l - 1 ) {
  18941. intPoint = l - 2;
  18942. weight = 1;
  18943. }
  18944. var p0, p1, p2, p3;
  18945. if ( intPoint === 0 ) {
  18946. // extrapolate first point
  18947. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  18948. p0 = tmp;
  18949. } else {
  18950. p0 = points[ intPoint - 1 ];
  18951. }
  18952. p1 = points[ intPoint ];
  18953. p2 = points[ intPoint + 1 ];
  18954. if ( intPoint + 2 < l ) {
  18955. p3 = points[ intPoint + 2 ]
  18956. } else {
  18957. // extrapolate last point
  18958. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  18959. p3 = tmp;
  18960. }
  18961. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  18962. // init Centripetal / Chordal Catmull-Rom
  18963. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  18964. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  18965. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  18966. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  18967. // safety check for repeated points
  18968. if ( dt1 < 1e-4 ) dt1 = 1.0;
  18969. if ( dt0 < 1e-4 ) dt0 = dt1;
  18970. if ( dt2 < 1e-4 ) dt2 = dt1;
  18971. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  18972. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  18973. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  18974. } else if ( this.type === 'catmullrom' ) {
  18975. var tension = this.tension !== undefined ? this.tension : 0.5;
  18976. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  18977. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  18978. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  18979. }
  18980. var v = new THREE.Vector3(
  18981. px.calc( weight ),
  18982. py.calc( weight ),
  18983. pz.calc( weight )
  18984. );
  18985. return v;
  18986. }
  18987. );
  18988. } )();
  18989. // File:src/extras/curves/ClosedSplineCurve3.js
  18990. /**************************************************************
  18991. * Closed Spline 3D curve
  18992. **************************************************************/
  18993. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  18994. function ( points /* array of Vector3 */ ) {
  18995. this.points = ( points == undefined ) ? [] : points;
  18996. },
  18997. function ( t ) {
  18998. var points = this.points;
  18999. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  19000. var intPoint = Math.floor( point );
  19001. var weight = point - intPoint;
  19002. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  19003. var point0 = points[ ( intPoint - 1 ) % points.length ];
  19004. var point1 = points[ ( intPoint ) % points.length ];
  19005. var point2 = points[ ( intPoint + 1 ) % points.length ];
  19006. var point3 = points[ ( intPoint + 2 ) % points.length ];
  19007. var vector = new THREE.Vector3();
  19008. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  19009. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  19010. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  19011. return vector;
  19012. }
  19013. );
  19014. // File:src/extras/geometries/BoxGeometry.js
  19015. /**
  19016. * @author mrdoob / http://mrdoob.com/
  19017. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  19018. */
  19019. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  19020. THREE.Geometry.call( this );
  19021. this.type = 'BoxGeometry';
  19022. this.parameters = {
  19023. width: width,
  19024. height: height,
  19025. depth: depth,
  19026. widthSegments: widthSegments,
  19027. heightSegments: heightSegments,
  19028. depthSegments: depthSegments
  19029. };
  19030. this.widthSegments = widthSegments || 1;
  19031. this.heightSegments = heightSegments || 1;
  19032. this.depthSegments = depthSegments || 1;
  19033. var scope = this;
  19034. var width_half = width / 2;
  19035. var height_half = height / 2;
  19036. var depth_half = depth / 2;
  19037. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  19038. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  19039. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  19040. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  19041. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  19042. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  19043. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  19044. var w, ix, iy,
  19045. gridX = scope.widthSegments,
  19046. gridY = scope.heightSegments,
  19047. width_half = width / 2,
  19048. height_half = height / 2,
  19049. offset = scope.vertices.length;
  19050. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  19051. w = 'z';
  19052. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  19053. w = 'y';
  19054. gridY = scope.depthSegments;
  19055. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  19056. w = 'x';
  19057. gridX = scope.depthSegments;
  19058. }
  19059. var gridX1 = gridX + 1,
  19060. gridY1 = gridY + 1,
  19061. segment_width = width / gridX,
  19062. segment_height = height / gridY,
  19063. normal = new THREE.Vector3();
  19064. normal[ w ] = depth > 0 ? 1 : - 1;
  19065. for ( iy = 0; iy < gridY1; iy ++ ) {
  19066. for ( ix = 0; ix < gridX1; ix ++ ) {
  19067. var vector = new THREE.Vector3();
  19068. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  19069. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  19070. vector[ w ] = depth;
  19071. scope.vertices.push( vector );
  19072. }
  19073. }
  19074. for ( iy = 0; iy < gridY; iy ++ ) {
  19075. for ( ix = 0; ix < gridX; ix ++ ) {
  19076. var a = ix + gridX1 * iy;
  19077. var b = ix + gridX1 * ( iy + 1 );
  19078. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  19079. var d = ( ix + 1 ) + gridX1 * iy;
  19080. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  19081. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  19082. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  19083. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  19084. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  19085. face.normal.copy( normal );
  19086. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  19087. face.materialIndex = materialIndex;
  19088. scope.faces.push( face );
  19089. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19090. face = new THREE.Face3( b + offset, c + offset, d + offset );
  19091. face.normal.copy( normal );
  19092. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  19093. face.materialIndex = materialIndex;
  19094. scope.faces.push( face );
  19095. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19096. }
  19097. }
  19098. }
  19099. this.mergeVertices();
  19100. };
  19101. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19102. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  19103. THREE.BoxGeometry.prototype.clone = function () {
  19104. var geometry = new THREE.BoxGeometry(
  19105. this.parameters.width,
  19106. this.parameters.height,
  19107. this.parameters.depth,
  19108. this.parameters.widthSegments,
  19109. this.parameters.heightSegments,
  19110. this.parameters.depthSegments
  19111. );
  19112. return geometry;
  19113. };
  19114. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  19115. // File:src/extras/geometries/CircleGeometry.js
  19116. /**
  19117. * @author hughes
  19118. */
  19119. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  19120. THREE.Geometry.call( this );
  19121. this.type = 'CircleGeometry';
  19122. this.parameters = {
  19123. radius: radius,
  19124. segments: segments,
  19125. thetaStart: thetaStart,
  19126. thetaLength: thetaLength
  19127. };
  19128. radius = radius || 50;
  19129. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19130. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19131. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19132. var i, uvs = [],
  19133. center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
  19134. this.vertices.push( center );
  19135. uvs.push( centerUV );
  19136. for ( i = 0; i <= segments; i ++ ) {
  19137. var vertex = new THREE.Vector3();
  19138. var segment = thetaStart + i / segments * thetaLength;
  19139. vertex.x = radius * Math.cos( segment );
  19140. vertex.y = radius * Math.sin( segment );
  19141. this.vertices.push( vertex );
  19142. uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, ( vertex.y / radius + 1 ) / 2 ) );
  19143. }
  19144. var n = new THREE.Vector3( 0, 0, 1 );
  19145. for ( i = 1; i <= segments; i ++ ) {
  19146. this.faces.push( new THREE.Face3( i, i + 1, 0, [ n.clone(), n.clone(), n.clone() ] ) );
  19147. this.faceVertexUvs[ 0 ].push( [ uvs[ i ].clone(), uvs[ i + 1 ].clone(), centerUV.clone() ] );
  19148. }
  19149. this.computeFaceNormals();
  19150. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19151. };
  19152. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19153. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  19154. THREE.CircleGeometry.prototype.clone = function () {
  19155. var geometry = new THREE.CircleGeometry(
  19156. this.parameters.radius,
  19157. this.parameters.segments,
  19158. this.parameters.thetaStart,
  19159. this.parameters.thetaLength
  19160. );
  19161. return geometry;
  19162. };
  19163. // File:src/extras/geometries/CircleBufferGeometry.js
  19164. /**
  19165. * @author benaadams / https://twitter.com/ben_a_adams
  19166. */
  19167. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  19168. THREE.BufferGeometry.call( this );
  19169. this.type = 'CircleBufferGeometry';
  19170. this.parameters = {
  19171. radius: radius,
  19172. segments: segments,
  19173. thetaStart: thetaStart,
  19174. thetaLength: thetaLength
  19175. };
  19176. radius = radius || 50;
  19177. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19178. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19179. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19180. var vertices = segments + 2;
  19181. var positions = new Float32Array( vertices * 3 );
  19182. var normals = new Float32Array( vertices * 3 );
  19183. var uvs = new Float32Array( vertices * 2 );
  19184. // center data is already zero, but need to set a few extras
  19185. normals[ 3 ] = 1.0;
  19186. uvs[ 0 ] = 0.5;
  19187. uvs[ 1 ] = 0.5;
  19188. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  19189. var segment = thetaStart + s / segments * thetaLength;
  19190. positions[ i ] = radius * Math.cos( segment );
  19191. positions[ i + 1 ] = radius * Math.sin( segment );
  19192. normals[ i + 2 ] = 1; // normal z
  19193. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  19194. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  19195. }
  19196. var indices = [];
  19197. for ( var i = 1; i <= segments; i ++ ) {
  19198. indices.push( i );
  19199. indices.push( i + 1 );
  19200. indices.push( 0 );
  19201. }
  19202. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  19203. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  19204. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  19205. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  19206. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19207. };
  19208. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19209. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  19210. THREE.CircleBufferGeometry.prototype.clone = function () {
  19211. var geometry = new THREE.CircleBufferGeometry(
  19212. this.parameters.radius,
  19213. this.parameters.segments,
  19214. this.parameters.thetaStart,
  19215. this.parameters.thetaLength
  19216. );
  19217. geometry.copy( this );
  19218. return geometry;
  19219. };
  19220. // File:src/extras/geometries/CylinderGeometry.js
  19221. /**
  19222. * @author mrdoob / http://mrdoob.com/
  19223. */
  19224. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19225. THREE.Geometry.call( this );
  19226. this.type = 'CylinderGeometry';
  19227. this.parameters = {
  19228. radiusTop: radiusTop,
  19229. radiusBottom: radiusBottom,
  19230. height: height,
  19231. radialSegments: radialSegments,
  19232. heightSegments: heightSegments,
  19233. openEnded: openEnded,
  19234. thetaStart: thetaStart,
  19235. thetaLength: thetaLength
  19236. };
  19237. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  19238. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  19239. height = height !== undefined ? height : 100;
  19240. radialSegments = radialSegments || 8;
  19241. heightSegments = heightSegments || 1;
  19242. openEnded = openEnded !== undefined ? openEnded : false;
  19243. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19244. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  19245. var heightHalf = height / 2;
  19246. var x, y, vertices = [], uvs = [];
  19247. for ( y = 0; y <= heightSegments; y ++ ) {
  19248. var verticesRow = [];
  19249. var uvsRow = [];
  19250. var v = y / heightSegments;
  19251. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  19252. for ( x = 0; x <= radialSegments; x ++ ) {
  19253. var u = x / radialSegments;
  19254. var vertex = new THREE.Vector3();
  19255. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  19256. vertex.y = - v * height + heightHalf;
  19257. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  19258. this.vertices.push( vertex );
  19259. verticesRow.push( this.vertices.length - 1 );
  19260. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  19261. }
  19262. vertices.push( verticesRow );
  19263. uvs.push( uvsRow );
  19264. }
  19265. var tanTheta = ( radiusBottom - radiusTop ) / height;
  19266. var na, nb;
  19267. for ( x = 0; x < radialSegments; x ++ ) {
  19268. if ( radiusTop !== 0 ) {
  19269. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  19270. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  19271. } else {
  19272. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  19273. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  19274. }
  19275. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  19276. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  19277. for ( y = 0; y < heightSegments; y ++ ) {
  19278. var v1 = vertices[ y ][ x ];
  19279. var v2 = vertices[ y + 1 ][ x ];
  19280. var v3 = vertices[ y + 1 ][ x + 1 ];
  19281. var v4 = vertices[ y ][ x + 1 ];
  19282. var n1 = na.clone();
  19283. var n2 = na.clone();
  19284. var n3 = nb.clone();
  19285. var n4 = nb.clone();
  19286. var uv1 = uvs[ y ][ x ].clone();
  19287. var uv2 = uvs[ y + 1 ][ x ].clone();
  19288. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  19289. var uv4 = uvs[ y ][ x + 1 ].clone();
  19290. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  19291. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  19292. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  19293. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  19294. }
  19295. }
  19296. // top cap
  19297. if ( openEnded === false && radiusTop > 0 ) {
  19298. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  19299. for ( x = 0; x < radialSegments; x ++ ) {
  19300. var v1 = vertices[ 0 ][ x ];
  19301. var v2 = vertices[ 0 ][ x + 1 ];
  19302. var v3 = this.vertices.length - 1;
  19303. var n1 = new THREE.Vector3( 0, 1, 0 );
  19304. var n2 = new THREE.Vector3( 0, 1, 0 );
  19305. var n3 = new THREE.Vector3( 0, 1, 0 );
  19306. var uv1 = uvs[ 0 ][ x ].clone();
  19307. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  19308. var uv3 = new THREE.Vector2( uv2.x, 0 );
  19309. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 1 ) );
  19310. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19311. }
  19312. }
  19313. // bottom cap
  19314. if ( openEnded === false && radiusBottom > 0 ) {
  19315. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  19316. for ( x = 0; x < radialSegments; x ++ ) {
  19317. var v1 = vertices[ heightSegments ][ x + 1 ];
  19318. var v2 = vertices[ heightSegments ][ x ];
  19319. var v3 = this.vertices.length - 1;
  19320. var n1 = new THREE.Vector3( 0, - 1, 0 );
  19321. var n2 = new THREE.Vector3( 0, - 1, 0 );
  19322. var n3 = new THREE.Vector3( 0, - 1, 0 );
  19323. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  19324. var uv2 = uvs[ heightSegments ][ x ].clone();
  19325. var uv3 = new THREE.Vector2( uv2.x, 1 );
  19326. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 2 ) );
  19327. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19328. }
  19329. }
  19330. this.computeFaceNormals();
  19331. };
  19332. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19333. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  19334. THREE.CylinderGeometry.prototype.clone = function () {
  19335. var geometry = new THREE.CylinderGeometry(
  19336. this.parameters.radiusTop,
  19337. this.parameters.radiusBottom,
  19338. this.parameters.height,
  19339. this.parameters.radialSegments,
  19340. this.parameters.heightSegments,
  19341. this.parameters.openEnded,
  19342. this.parameters.thetaStart,
  19343. this.parameters.thetaLength
  19344. );
  19345. return geometry;
  19346. };
  19347. // File:src/extras/geometries/EdgesGeometry.js
  19348. /**
  19349. * @author WestLangley / http://github.com/WestLangley
  19350. */
  19351. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  19352. THREE.BufferGeometry.call( this );
  19353. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  19354. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  19355. var edge = [ 0, 0 ], hash = {};
  19356. var sortFunction = function ( a, b ) {
  19357. return a - b;
  19358. };
  19359. var keys = [ 'a', 'b', 'c' ];
  19360. var geometry2;
  19361. if ( geometry instanceof THREE.BufferGeometry ) {
  19362. geometry2 = new THREE.Geometry();
  19363. geometry2.fromBufferGeometry( geometry );
  19364. } else {
  19365. geometry2 = geometry.clone();
  19366. }
  19367. geometry2.mergeVertices();
  19368. geometry2.computeFaceNormals();
  19369. var vertices = geometry2.vertices;
  19370. var faces = geometry2.faces;
  19371. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19372. var face = faces[ i ];
  19373. for ( var j = 0; j < 3; j ++ ) {
  19374. edge[ 0 ] = face[ keys[ j ] ];
  19375. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  19376. edge.sort( sortFunction );
  19377. var key = edge.toString();
  19378. if ( hash[ key ] === undefined ) {
  19379. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  19380. } else {
  19381. hash[ key ].face2 = i;
  19382. }
  19383. }
  19384. }
  19385. var coords = [];
  19386. for ( var key in hash ) {
  19387. var h = hash[ key ];
  19388. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  19389. var vertex = vertices[ h.vert1 ];
  19390. coords.push( vertex.x );
  19391. coords.push( vertex.y );
  19392. coords.push( vertex.z );
  19393. vertex = vertices[ h.vert2 ];
  19394. coords.push( vertex.x );
  19395. coords.push( vertex.y );
  19396. coords.push( vertex.z );
  19397. }
  19398. }
  19399. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  19400. };
  19401. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19402. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  19403. // File:src/extras/geometries/ExtrudeGeometry.js
  19404. /**
  19405. * @author zz85 / http://www.lab4games.net/zz85/blog
  19406. *
  19407. * Creates extruded geometry from a path shape.
  19408. *
  19409. * parameters = {
  19410. *
  19411. * curveSegments: <int>, // number of points on the curves
  19412. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  19413. * amount: <int>, // Depth to extrude the shape
  19414. *
  19415. * bevelEnabled: <bool>, // turn on bevel
  19416. * bevelThickness: <float>, // how deep into the original shape bevel goes
  19417. * bevelSize: <float>, // how far from shape outline is bevel
  19418. * bevelSegments: <int>, // number of bevel layers
  19419. *
  19420. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  19421. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  19422. *
  19423. * uvGenerator: <Object> // object that provides UV generator functions
  19424. *
  19425. * }
  19426. **/
  19427. THREE.ExtrudeGeometry = function ( shapes, options ) {
  19428. if ( typeof( shapes ) === "undefined" ) {
  19429. shapes = [];
  19430. return;
  19431. }
  19432. THREE.Geometry.call( this );
  19433. this.type = 'ExtrudeGeometry';
  19434. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  19435. this.addShapeList( shapes, options );
  19436. this.computeFaceNormals();
  19437. // can't really use automatic vertex normals
  19438. // as then front and back sides get smoothed too
  19439. // should do separate smoothing just for sides
  19440. //this.computeVertexNormals();
  19441. //console.log( "took", ( Date.now() - startTime ) );
  19442. };
  19443. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19444. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  19445. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19446. var sl = shapes.length;
  19447. for ( var s = 0; s < sl; s ++ ) {
  19448. var shape = shapes[ s ];
  19449. this.addShape( shape, options );
  19450. }
  19451. };
  19452. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  19453. var amount = options.amount !== undefined ? options.amount : 100;
  19454. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  19455. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  19456. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  19457. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  19458. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19459. var steps = options.steps !== undefined ? options.steps : 1;
  19460. var extrudePath = options.extrudePath;
  19461. var extrudePts, extrudeByPath = false;
  19462. // Use default WorldUVGenerator if no UV generators are specified.
  19463. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  19464. var splineTube, binormal, normal, position2;
  19465. if ( extrudePath ) {
  19466. extrudePts = extrudePath.getSpacedPoints( steps );
  19467. extrudeByPath = true;
  19468. bevelEnabled = false; // bevels not supported for path extrusion
  19469. // SETUP TNB variables
  19470. // Reuse TNB from TubeGeomtry for now.
  19471. // TODO1 - have a .isClosed in spline?
  19472. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  19473. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  19474. binormal = new THREE.Vector3();
  19475. normal = new THREE.Vector3();
  19476. position2 = new THREE.Vector3();
  19477. }
  19478. // Safeguards if bevels are not enabled
  19479. if ( ! bevelEnabled ) {
  19480. bevelSegments = 0;
  19481. bevelThickness = 0;
  19482. bevelSize = 0;
  19483. }
  19484. // Variables initialization
  19485. var ahole, h, hl; // looping of holes
  19486. var scope = this;
  19487. var shapesOffset = this.vertices.length;
  19488. var shapePoints = shape.extractPoints( curveSegments );
  19489. var vertices = shapePoints.shape;
  19490. var holes = shapePoints.holes;
  19491. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19492. if ( reverse ) {
  19493. vertices = vertices.reverse();
  19494. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  19495. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19496. ahole = holes[ h ];
  19497. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  19498. holes[ h ] = ahole.reverse();
  19499. }
  19500. }
  19501. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  19502. }
  19503. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  19504. /* Vertices */
  19505. var contour = vertices; // vertices has all points but contour has only points of circumference
  19506. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19507. ahole = holes[ h ];
  19508. vertices = vertices.concat( ahole );
  19509. }
  19510. function scalePt2 ( pt, vec, size ) {
  19511. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  19512. return vec.clone().multiplyScalar( size ).add( pt );
  19513. }
  19514. var b, bs, t, z,
  19515. vert, vlen = vertices.length,
  19516. face, flen = faces.length;
  19517. // Find directions for point movement
  19518. function getBevelVec( inPt, inPrev, inNext ) {
  19519. var EPSILON = 0.0000000001;
  19520. // computes for inPt the corresponding point inPt' on a new contour
  19521. // shifted by 1 unit (length of normalized vector) to the left
  19522. // if we walk along contour clockwise, this new contour is outside the old one
  19523. //
  19524. // inPt' is the intersection of the two lines parallel to the two
  19525. // adjacent edges of inPt at a distance of 1 unit on the left side.
  19526. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  19527. // good reading for geometry algorithms (here: line-line intersection)
  19528. // http://geomalgorithms.com/a05-_intersect-1.html
  19529. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  19530. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  19531. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  19532. // check for collinear edges
  19533. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19534. if ( Math.abs( collinear0 ) > EPSILON ) {
  19535. // not collinear
  19536. // length of vectors for normalizing
  19537. var v_prev_len = Math.sqrt( v_prev_lensq );
  19538. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  19539. // shift adjacent points by unit vectors to the left
  19540. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  19541. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  19542. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  19543. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  19544. // scaling factor for v_prev to intersection point
  19545. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  19546. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  19547. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19548. // vector from inPt to intersection point
  19549. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  19550. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  19551. // Don't normalize!, otherwise sharp corners become ugly
  19552. // but prevent crazy spikes
  19553. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  19554. if ( v_trans_lensq <= 2 ) {
  19555. return new THREE.Vector2( v_trans_x, v_trans_y );
  19556. } else {
  19557. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  19558. }
  19559. } else {
  19560. // handle special case of collinear edges
  19561. var direction_eq = false; // assumes: opposite
  19562. if ( v_prev_x > EPSILON ) {
  19563. if ( v_next_x > EPSILON ) {
  19564. direction_eq = true;
  19565. }
  19566. } else {
  19567. if ( v_prev_x < - EPSILON ) {
  19568. if ( v_next_x < - EPSILON ) {
  19569. direction_eq = true;
  19570. }
  19571. } else {
  19572. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  19573. direction_eq = true;
  19574. }
  19575. }
  19576. }
  19577. if ( direction_eq ) {
  19578. // console.log("Warning: lines are a straight sequence");
  19579. v_trans_x = - v_prev_y;
  19580. v_trans_y = v_prev_x;
  19581. shrink_by = Math.sqrt( v_prev_lensq );
  19582. } else {
  19583. // console.log("Warning: lines are a straight spike");
  19584. v_trans_x = v_prev_x;
  19585. v_trans_y = v_prev_y;
  19586. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  19587. }
  19588. }
  19589. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  19590. }
  19591. var contourMovements = [];
  19592. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19593. if ( j === il ) j = 0;
  19594. if ( k === il ) k = 0;
  19595. // (j)---(i)---(k)
  19596. // console.log('i,j,k', i, j , k)
  19597. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  19598. }
  19599. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  19600. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19601. ahole = holes[ h ];
  19602. oneHoleMovements = [];
  19603. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19604. if ( j === il ) j = 0;
  19605. if ( k === il ) k = 0;
  19606. // (j)---(i)---(k)
  19607. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  19608. }
  19609. holesMovements.push( oneHoleMovements );
  19610. verticesMovements = verticesMovements.concat( oneHoleMovements );
  19611. }
  19612. // Loop bevelSegments, 1 for the front, 1 for the back
  19613. for ( b = 0; b < bevelSegments; b ++ ) {
  19614. //for ( b = bevelSegments; b > 0; b -- ) {
  19615. t = b / bevelSegments;
  19616. z = bevelThickness * ( 1 - t );
  19617. //z = bevelThickness * t;
  19618. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  19619. //bs = bevelSize * t; // linear
  19620. // contract shape
  19621. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19622. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19623. v( vert.x, vert.y, - z );
  19624. }
  19625. // expand holes
  19626. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19627. ahole = holes[ h ];
  19628. oneHoleMovements = holesMovements[ h ];
  19629. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19630. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19631. v( vert.x, vert.y, - z );
  19632. }
  19633. }
  19634. }
  19635. bs = bevelSize;
  19636. // Back facing vertices
  19637. for ( i = 0; i < vlen; i ++ ) {
  19638. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19639. if ( ! extrudeByPath ) {
  19640. v( vert.x, vert.y, 0 );
  19641. } else {
  19642. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  19643. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  19644. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  19645. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  19646. v( position2.x, position2.y, position2.z );
  19647. }
  19648. }
  19649. // Add stepped vertices...
  19650. // Including front facing vertices
  19651. var s;
  19652. for ( s = 1; s <= steps; s ++ ) {
  19653. for ( i = 0; i < vlen; i ++ ) {
  19654. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19655. if ( ! extrudeByPath ) {
  19656. v( vert.x, vert.y, amount / steps * s );
  19657. } else {
  19658. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  19659. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  19660. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  19661. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  19662. v( position2.x, position2.y, position2.z );
  19663. }
  19664. }
  19665. }
  19666. // Add bevel segments planes
  19667. //for ( b = 1; b <= bevelSegments; b ++ ) {
  19668. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  19669. t = b / bevelSegments;
  19670. z = bevelThickness * ( 1 - t );
  19671. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  19672. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  19673. // contract shape
  19674. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19675. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19676. v( vert.x, vert.y, amount + z );
  19677. }
  19678. // expand holes
  19679. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19680. ahole = holes[ h ];
  19681. oneHoleMovements = holesMovements[ h ];
  19682. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19683. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19684. if ( ! extrudeByPath ) {
  19685. v( vert.x, vert.y, amount + z );
  19686. } else {
  19687. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  19688. }
  19689. }
  19690. }
  19691. }
  19692. /* Faces */
  19693. // Top and bottom faces
  19694. buildLidFaces();
  19695. // Sides faces
  19696. buildSideFaces();
  19697. ///// Internal functions
  19698. function buildLidFaces() {
  19699. if ( bevelEnabled ) {
  19700. var layer = 0; // steps + 1
  19701. var offset = vlen * layer;
  19702. // Bottom faces
  19703. for ( i = 0; i < flen; i ++ ) {
  19704. face = faces[ i ];
  19705. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  19706. }
  19707. layer = steps + bevelSegments * 2;
  19708. offset = vlen * layer;
  19709. // Top faces
  19710. for ( i = 0; i < flen; i ++ ) {
  19711. face = faces[ i ];
  19712. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  19713. }
  19714. } else {
  19715. // Bottom faces
  19716. for ( i = 0; i < flen; i ++ ) {
  19717. face = faces[ i ];
  19718. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  19719. }
  19720. // Top faces
  19721. for ( i = 0; i < flen; i ++ ) {
  19722. face = faces[ i ];
  19723. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  19724. }
  19725. }
  19726. }
  19727. // Create faces for the z-sides of the shape
  19728. function buildSideFaces() {
  19729. var layeroffset = 0;
  19730. sidewalls( contour, layeroffset );
  19731. layeroffset += contour.length;
  19732. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19733. ahole = holes[ h ];
  19734. sidewalls( ahole, layeroffset );
  19735. //, true
  19736. layeroffset += ahole.length;
  19737. }
  19738. }
  19739. function sidewalls( contour, layeroffset ) {
  19740. var j, k;
  19741. i = contour.length;
  19742. while ( -- i >= 0 ) {
  19743. j = i;
  19744. k = i - 1;
  19745. if ( k < 0 ) k = contour.length - 1;
  19746. //console.log('b', i,j, i-1, k,vertices.length);
  19747. var s = 0, sl = steps + bevelSegments * 2;
  19748. for ( s = 0; s < sl; s ++ ) {
  19749. var slen1 = vlen * s;
  19750. var slen2 = vlen * ( s + 1 );
  19751. var a = layeroffset + j + slen1,
  19752. b = layeroffset + k + slen1,
  19753. c = layeroffset + k + slen2,
  19754. d = layeroffset + j + slen2;
  19755. f4( a, b, c, d, contour, s, sl, j, k );
  19756. }
  19757. }
  19758. }
  19759. function v( x, y, z ) {
  19760. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  19761. }
  19762. function f3( a, b, c ) {
  19763. a += shapesOffset;
  19764. b += shapesOffset;
  19765. c += shapesOffset;
  19766. scope.faces.push( new THREE.Face3( a, b, c ) );
  19767. var uvs = uvgen.generateTopUV( scope, a, b, c );
  19768. scope.faceVertexUvs[ 0 ].push( uvs );
  19769. }
  19770. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  19771. a += shapesOffset;
  19772. b += shapesOffset;
  19773. c += shapesOffset;
  19774. d += shapesOffset;
  19775. scope.faces.push( new THREE.Face3( a, b, d ) );
  19776. scope.faces.push( new THREE.Face3( b, c, d ) );
  19777. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  19778. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  19779. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  19780. }
  19781. };
  19782. THREE.ExtrudeGeometry.WorldUVGenerator = {
  19783. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  19784. var vertices = geometry.vertices;
  19785. var a = vertices[ indexA ];
  19786. var b = vertices[ indexB ];
  19787. var c = vertices[ indexC ];
  19788. return [
  19789. new THREE.Vector2( a.x, a.y ),
  19790. new THREE.Vector2( b.x, b.y ),
  19791. new THREE.Vector2( c.x, c.y )
  19792. ];
  19793. },
  19794. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  19795. var vertices = geometry.vertices;
  19796. var a = vertices[ indexA ];
  19797. var b = vertices[ indexB ];
  19798. var c = vertices[ indexC ];
  19799. var d = vertices[ indexD ];
  19800. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  19801. return [
  19802. new THREE.Vector2( a.x, 1 - a.z ),
  19803. new THREE.Vector2( b.x, 1 - b.z ),
  19804. new THREE.Vector2( c.x, 1 - c.z ),
  19805. new THREE.Vector2( d.x, 1 - d.z )
  19806. ];
  19807. } else {
  19808. return [
  19809. new THREE.Vector2( a.y, 1 - a.z ),
  19810. new THREE.Vector2( b.y, 1 - b.z ),
  19811. new THREE.Vector2( c.y, 1 - c.z ),
  19812. new THREE.Vector2( d.y, 1 - d.z )
  19813. ];
  19814. }
  19815. }
  19816. };
  19817. // File:src/extras/geometries/ShapeGeometry.js
  19818. /**
  19819. * @author jonobr1 / http://jonobr1.com
  19820. *
  19821. * Creates a one-sided polygonal geometry from a path shape. Similar to
  19822. * ExtrudeGeometry.
  19823. *
  19824. * parameters = {
  19825. *
  19826. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  19827. *
  19828. * material: <int> // material index for front and back faces
  19829. * uvGenerator: <Object> // object that provides UV generator functions
  19830. *
  19831. * }
  19832. **/
  19833. THREE.ShapeGeometry = function ( shapes, options ) {
  19834. THREE.Geometry.call( this );
  19835. this.type = 'ShapeGeometry';
  19836. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  19837. this.addShapeList( shapes, options );
  19838. this.computeFaceNormals();
  19839. };
  19840. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19841. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  19842. /**
  19843. * Add an array of shapes to THREE.ShapeGeometry.
  19844. */
  19845. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19846. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19847. this.addShape( shapes[ i ], options );
  19848. }
  19849. return this;
  19850. };
  19851. /**
  19852. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  19853. */
  19854. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  19855. if ( options === undefined ) options = {};
  19856. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19857. var material = options.material;
  19858. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  19859. //
  19860. var i, l, hole;
  19861. var shapesOffset = this.vertices.length;
  19862. var shapePoints = shape.extractPoints( curveSegments );
  19863. var vertices = shapePoints.shape;
  19864. var holes = shapePoints.holes;
  19865. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19866. if ( reverse ) {
  19867. vertices = vertices.reverse();
  19868. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  19869. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19870. hole = holes[ i ];
  19871. if ( THREE.Shape.Utils.isClockWise( hole ) ) {
  19872. holes[ i ] = hole.reverse();
  19873. }
  19874. }
  19875. reverse = false;
  19876. }
  19877. var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
  19878. // Vertices
  19879. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19880. hole = holes[ i ];
  19881. vertices = vertices.concat( hole );
  19882. }
  19883. //
  19884. var vert, vlen = vertices.length;
  19885. var face, flen = faces.length;
  19886. for ( i = 0; i < vlen; i ++ ) {
  19887. vert = vertices[ i ];
  19888. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  19889. }
  19890. for ( i = 0; i < flen; i ++ ) {
  19891. face = faces[ i ];
  19892. var a = face[ 0 ] + shapesOffset;
  19893. var b = face[ 1 ] + shapesOffset;
  19894. var c = face[ 2 ] + shapesOffset;
  19895. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  19896. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  19897. }
  19898. };
  19899. // File:src/extras/geometries/LatheGeometry.js
  19900. /**
  19901. * @author astrodud / http://astrodud.isgreat.org/
  19902. * @author zz85 / https://github.com/zz85
  19903. * @author bhouston / http://clara.io
  19904. */
  19905. // points - to create a closed torus, one must use a set of points
  19906. // like so: [ a, b, c, d, a ], see first is the same as last.
  19907. // segments - the number of circumference segments to create
  19908. // phiStart - the starting radian
  19909. // phiLength - the radian (0 to 2*PI) range of the lathed section
  19910. // 2*pi is a closed lathe, less than 2PI is a portion.
  19911. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  19912. THREE.Geometry.call( this );
  19913. this.type = 'LatheGeometry';
  19914. this.parameters = {
  19915. points: points,
  19916. segments: segments,
  19917. phiStart: phiStart,
  19918. phiLength: phiLength
  19919. };
  19920. segments = segments || 12;
  19921. phiStart = phiStart || 0;
  19922. phiLength = phiLength || 2 * Math.PI;
  19923. var inversePointLength = 1.0 / ( points.length - 1 );
  19924. var inverseSegments = 1.0 / segments;
  19925. for ( var i = 0, il = segments; i <= il; i ++ ) {
  19926. var phi = phiStart + i * inverseSegments * phiLength;
  19927. var c = Math.cos( phi ),
  19928. s = Math.sin( phi );
  19929. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  19930. var pt = points[ j ];
  19931. var vertex = new THREE.Vector3();
  19932. vertex.x = c * pt.x - s * pt.y;
  19933. vertex.y = s * pt.x + c * pt.y;
  19934. vertex.z = pt.z;
  19935. this.vertices.push( vertex );
  19936. }
  19937. }
  19938. var np = points.length;
  19939. for ( var i = 0, il = segments; i < il; i ++ ) {
  19940. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  19941. var base = j + np * i;
  19942. var a = base;
  19943. var b = base + np;
  19944. var c = base + 1 + np;
  19945. var d = base + 1;
  19946. var u0 = i * inverseSegments;
  19947. var v0 = j * inversePointLength;
  19948. var u1 = u0 + inverseSegments;
  19949. var v1 = v0 + inversePointLength;
  19950. this.faces.push( new THREE.Face3( a, b, d ) );
  19951. this.faceVertexUvs[ 0 ].push( [
  19952. new THREE.Vector2( u0, v0 ),
  19953. new THREE.Vector2( u1, v0 ),
  19954. new THREE.Vector2( u0, v1 )
  19955. ] );
  19956. this.faces.push( new THREE.Face3( b, c, d ) );
  19957. this.faceVertexUvs[ 0 ].push( [
  19958. new THREE.Vector2( u1, v0 ),
  19959. new THREE.Vector2( u1, v1 ),
  19960. new THREE.Vector2( u0, v1 )
  19961. ] );
  19962. }
  19963. }
  19964. this.mergeVertices();
  19965. this.computeFaceNormals();
  19966. this.computeVertexNormals();
  19967. };
  19968. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19969. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  19970. // File:src/extras/geometries/PlaneGeometry.js
  19971. /**
  19972. * @author mrdoob / http://mrdoob.com/
  19973. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19974. */
  19975. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  19976. THREE.Geometry.call( this );
  19977. this.type = 'PlaneGeometry';
  19978. this.parameters = {
  19979. width: width,
  19980. height: height,
  19981. widthSegments: widthSegments,
  19982. heightSegments: heightSegments
  19983. };
  19984. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  19985. };
  19986. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19987. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  19988. THREE.PlaneGeometry.prototype.clone = function () {
  19989. var geometry = new THREE.PlaneGeometry(
  19990. this.parameters.width,
  19991. this.parameters.height,
  19992. this.parameters.widthSegments,
  19993. this.parameters.heightSegments
  19994. );
  19995. return geometry;
  19996. };
  19997. // File:src/extras/geometries/PlaneBufferGeometry.js
  19998. /**
  19999. * @author mrdoob / http://mrdoob.com/
  20000. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  20001. */
  20002. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  20003. THREE.BufferGeometry.call( this );
  20004. this.type = 'PlaneBufferGeometry';
  20005. this.parameters = {
  20006. width: width,
  20007. height: height,
  20008. widthSegments: widthSegments,
  20009. heightSegments: heightSegments
  20010. };
  20011. var width_half = width / 2;
  20012. var height_half = height / 2;
  20013. var gridX = Math.floor( widthSegments ) || 1;
  20014. var gridY = Math.floor( heightSegments ) || 1;
  20015. var gridX1 = gridX + 1;
  20016. var gridY1 = gridY + 1;
  20017. var segment_width = width / gridX;
  20018. var segment_height = height / gridY;
  20019. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  20020. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  20021. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  20022. var offset = 0;
  20023. var offset2 = 0;
  20024. for ( var iy = 0; iy < gridY1; iy ++ ) {
  20025. var y = iy * segment_height - height_half;
  20026. for ( var ix = 0; ix < gridX1; ix ++ ) {
  20027. var x = ix * segment_width - width_half;
  20028. vertices[ offset ] = x;
  20029. vertices[ offset + 1 ] = - y;
  20030. normals[ offset + 2 ] = 1;
  20031. uvs[ offset2 ] = ix / gridX;
  20032. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  20033. offset += 3;
  20034. offset2 += 2;
  20035. }
  20036. }
  20037. offset = 0;
  20038. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  20039. for ( var iy = 0; iy < gridY; iy ++ ) {
  20040. for ( var ix = 0; ix < gridX; ix ++ ) {
  20041. var a = ix + gridX1 * iy;
  20042. var b = ix + gridX1 * ( iy + 1 );
  20043. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  20044. var d = ( ix + 1 ) + gridX1 * iy;
  20045. indices[ offset ] = a;
  20046. indices[ offset + 1 ] = b;
  20047. indices[ offset + 2 ] = d;
  20048. indices[ offset + 3 ] = b;
  20049. indices[ offset + 4 ] = c;
  20050. indices[ offset + 5 ] = d;
  20051. offset += 6;
  20052. }
  20053. }
  20054. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  20055. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  20056. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  20057. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  20058. };
  20059. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20060. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  20061. THREE.PlaneBufferGeometry.prototype.clone = function () {
  20062. var geometry = new THREE.PlaneBufferGeometry(
  20063. this.parameters.width,
  20064. this.parameters.height,
  20065. this.parameters.widthSegments,
  20066. this.parameters.heightSegments
  20067. );
  20068. geometry.copy( this );
  20069. return geometry;
  20070. };
  20071. // File:src/extras/geometries/RingGeometry.js
  20072. /**
  20073. * @author Kaleb Murphy
  20074. */
  20075. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  20076. THREE.Geometry.call( this );
  20077. this.type = 'RingGeometry';
  20078. this.parameters = {
  20079. innerRadius: innerRadius,
  20080. outerRadius: outerRadius,
  20081. thetaSegments: thetaSegments,
  20082. phiSegments: phiSegments,
  20083. thetaStart: thetaStart,
  20084. thetaLength: thetaLength
  20085. };
  20086. innerRadius = innerRadius || 0;
  20087. outerRadius = outerRadius || 50;
  20088. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20089. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  20090. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  20091. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  20092. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  20093. for ( i = 0; i < phiSegments + 1; i ++ ) {
  20094. // concentric circles inside ring
  20095. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  20096. // number of segments per circle
  20097. var vertex = new THREE.Vector3();
  20098. var segment = thetaStart + o / thetaSegments * thetaLength;
  20099. vertex.x = radius * Math.cos( segment );
  20100. vertex.y = radius * Math.sin( segment );
  20101. this.vertices.push( vertex );
  20102. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  20103. }
  20104. radius += radiusStep;
  20105. }
  20106. var n = new THREE.Vector3( 0, 0, 1 );
  20107. for ( i = 0; i < phiSegments; i ++ ) {
  20108. // concentric circles inside ring
  20109. var thetaSegment = i * ( thetaSegments + 1 );
  20110. for ( o = 0; o < thetaSegments ; o ++ ) {
  20111. // number of segments per circle
  20112. var segment = o + thetaSegment;
  20113. var v1 = segment;
  20114. var v2 = segment + thetaSegments + 1;
  20115. var v3 = segment + thetaSegments + 2;
  20116. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  20117. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  20118. v1 = segment;
  20119. v2 = segment + thetaSegments + 2;
  20120. v3 = segment + 1;
  20121. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  20122. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  20123. }
  20124. }
  20125. this.computeFaceNormals();
  20126. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20127. };
  20128. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20129. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  20130. THREE.RingGeometry.prototype.clone = function () {
  20131. var geometry = new THREE.RingGeometry(
  20132. this.parameters.innerRadius,
  20133. this.parameters.outerRadius,
  20134. this.parameters.thetaSegments,
  20135. this.parameters.phiSegments,
  20136. this.parameters.thetaStart,
  20137. this.parameters.thetaLength
  20138. );
  20139. return geometry;
  20140. };
  20141. // File:src/extras/geometries/SphereGeometry.js
  20142. /**
  20143. * @author mrdoob / http://mrdoob.com/
  20144. */
  20145. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  20146. THREE.Geometry.call( this );
  20147. this.type = 'SphereGeometry';
  20148. this.parameters = {
  20149. radius: radius,
  20150. widthSegments: widthSegments,
  20151. heightSegments: heightSegments,
  20152. phiStart: phiStart,
  20153. phiLength: phiLength,
  20154. thetaStart: thetaStart,
  20155. thetaLength: thetaLength
  20156. };
  20157. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  20158. };
  20159. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20160. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  20161. THREE.SphereGeometry.prototype.clone = function () {
  20162. var geometry = new THREE.SphereGeometry(
  20163. this.parameters.radius,
  20164. this.parameters.widthSegments,
  20165. this.parameters.heightSegments,
  20166. this.parameters.phiStart,
  20167. this.parameters.phiLength,
  20168. this.parameters.thetaStart,
  20169. this.parameters.thetaLength
  20170. );
  20171. return geometry;
  20172. };
  20173. // File:src/extras/geometries/SphereBufferGeometry.js
  20174. /**
  20175. * @author benaadams / https://twitter.com/ben_a_adams
  20176. * based on THREE.SphereGeometry
  20177. */
  20178. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  20179. THREE.BufferGeometry.call( this );
  20180. this.type = 'SphereBufferGeometry';
  20181. this.parameters = {
  20182. radius: radius,
  20183. widthSegments: widthSegments,
  20184. heightSegments: heightSegments,
  20185. phiStart: phiStart,
  20186. phiLength: phiLength,
  20187. thetaStart: thetaStart,
  20188. thetaLength: thetaLength
  20189. };
  20190. radius = radius || 50;
  20191. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  20192. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  20193. phiStart = phiStart !== undefined ? phiStart : 0;
  20194. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  20195. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20196. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  20197. var thetaEnd = thetaStart + thetaLength;
  20198. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  20199. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  20200. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  20201. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  20202. var index = 0, vertices = [], normal = new THREE.Vector3();
  20203. for ( var y = 0; y <= heightSegments; y ++ ) {
  20204. var verticesRow = [];
  20205. var v = y / heightSegments;
  20206. for ( var x = 0; x <= widthSegments; x ++ ) {
  20207. var u = x / widthSegments;
  20208. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  20209. var py = radius * Math.cos( thetaStart + v * thetaLength );
  20210. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  20211. normal.set( px, py, pz ).normalize();
  20212. positions.setXYZ( index, px, py, pz );
  20213. normals.setXYZ( index, normal.x, normal.y, normal.z );
  20214. uvs.setXY( index, u, 1 - v );
  20215. verticesRow.push( index );
  20216. index ++;
  20217. }
  20218. vertices.push( verticesRow );
  20219. }
  20220. var indices = [];
  20221. for ( var y = 0; y < heightSegments; y ++ ) {
  20222. for ( var x = 0; x < widthSegments; x ++ ) {
  20223. var v1 = vertices[ y ][ x + 1 ];
  20224. var v2 = vertices[ y ][ x ];
  20225. var v3 = vertices[ y + 1 ][ x ];
  20226. var v4 = vertices[ y + 1 ][ x + 1 ];
  20227. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  20228. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  20229. }
  20230. }
  20231. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  20232. this.addAttribute( 'position', positions );
  20233. this.addAttribute( 'normal', normals );
  20234. this.addAttribute( 'uv', uvs );
  20235. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20236. };
  20237. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20238. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  20239. THREE.SphereBufferGeometry.prototype.clone = function () {
  20240. var geometry = new THREE.SphereBufferGeometry(
  20241. this.parameters.radius,
  20242. this.parameters.widthSegments,
  20243. this.parameters.heightSegments,
  20244. this.parameters.phiStart,
  20245. this.parameters.phiLength,
  20246. this.parameters.thetaStart,
  20247. this.parameters.thetaLength
  20248. );
  20249. geometry.copy( this );
  20250. return geometry;
  20251. };
  20252. // File:src/extras/geometries/TextGeometry.js
  20253. /**
  20254. * @author zz85 / http://www.lab4games.net/zz85/blog
  20255. * @author alteredq / http://alteredqualia.com/
  20256. *
  20257. * For creating 3D text geometry in three.js
  20258. *
  20259. * Text = 3D Text
  20260. *
  20261. * parameters = {
  20262. * size: <float>, // size of the text
  20263. * height: <float>, // thickness to extrude text
  20264. * curveSegments: <int>, // number of points on the curves
  20265. *
  20266. * font: <string>, // font name
  20267. * weight: <string>, // font weight (normal, bold)
  20268. * style: <string>, // font style (normal, italics)
  20269. *
  20270. * bevelEnabled: <bool>, // turn on bevel
  20271. * bevelThickness: <float>, // how deep into text bevel goes
  20272. * bevelSize: <float>, // how far from text outline is bevel
  20273. * }
  20274. *
  20275. */
  20276. /* Usage Examples
  20277. // TextGeometry wrapper
  20278. var text3d = new TextGeometry( text, options );
  20279. // Complete manner
  20280. var textShapes = THREE.FontUtils.generateShapes( text, options );
  20281. var text3d = new ExtrudeGeometry( textShapes, options );
  20282. */
  20283. THREE.TextGeometry = function ( text, parameters ) {
  20284. parameters = parameters || {};
  20285. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  20286. // translate parameters to ExtrudeGeometry API
  20287. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  20288. // defaults
  20289. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  20290. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  20291. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  20292. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  20293. this.type = 'TextGeometry';
  20294. };
  20295. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  20296. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  20297. // File:src/extras/geometries/TorusGeometry.js
  20298. /**
  20299. * @author oosmoxiecode
  20300. * @author mrdoob / http://mrdoob.com/
  20301. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  20302. */
  20303. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  20304. THREE.Geometry.call( this );
  20305. this.type = 'TorusGeometry';
  20306. this.parameters = {
  20307. radius: radius,
  20308. tube: tube,
  20309. radialSegments: radialSegments,
  20310. tubularSegments: tubularSegments,
  20311. arc: arc
  20312. };
  20313. radius = radius || 100;
  20314. tube = tube || 40;
  20315. radialSegments = radialSegments || 8;
  20316. tubularSegments = tubularSegments || 6;
  20317. arc = arc || Math.PI * 2;
  20318. var center = new THREE.Vector3(), uvs = [], normals = [];
  20319. for ( var j = 0; j <= radialSegments; j ++ ) {
  20320. for ( var i = 0; i <= tubularSegments; i ++ ) {
  20321. var u = i / tubularSegments * arc;
  20322. var v = j / radialSegments * Math.PI * 2;
  20323. center.x = radius * Math.cos( u );
  20324. center.y = radius * Math.sin( u );
  20325. var vertex = new THREE.Vector3();
  20326. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  20327. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  20328. vertex.z = tube * Math.sin( v );
  20329. this.vertices.push( vertex );
  20330. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  20331. normals.push( vertex.clone().sub( center ).normalize() );
  20332. }
  20333. }
  20334. for ( var j = 1; j <= radialSegments; j ++ ) {
  20335. for ( var i = 1; i <= tubularSegments; i ++ ) {
  20336. var a = ( tubularSegments + 1 ) * j + i - 1;
  20337. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  20338. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  20339. var d = ( tubularSegments + 1 ) * j + i;
  20340. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  20341. this.faces.push( face );
  20342. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  20343. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  20344. this.faces.push( face );
  20345. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  20346. }
  20347. }
  20348. this.computeFaceNormals();
  20349. };
  20350. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20351. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  20352. THREE.TorusGeometry.prototype.clone = function () {
  20353. var geometry = new THREE.TorusGeometry(
  20354. this.parameters.radius,
  20355. this.parameters.tube,
  20356. this.parameters.radialSegments,
  20357. this.parameters.tubularSegments,
  20358. this.parameters.arc
  20359. );
  20360. return geometry;
  20361. };
  20362. // File:src/extras/geometries/TorusKnotGeometry.js
  20363. /**
  20364. * @author oosmoxiecode
  20365. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  20366. */
  20367. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  20368. THREE.Geometry.call( this );
  20369. this.type = 'TorusKnotGeometry';
  20370. this.parameters = {
  20371. radius: radius,
  20372. tube: tube,
  20373. radialSegments: radialSegments,
  20374. tubularSegments: tubularSegments,
  20375. p: p,
  20376. q: q,
  20377. heightScale: heightScale
  20378. };
  20379. radius = radius || 100;
  20380. tube = tube || 40;
  20381. radialSegments = radialSegments || 64;
  20382. tubularSegments = tubularSegments || 8;
  20383. p = p || 2;
  20384. q = q || 3;
  20385. heightScale = heightScale || 1;
  20386. var grid = new Array( radialSegments );
  20387. var tang = new THREE.Vector3();
  20388. var n = new THREE.Vector3();
  20389. var bitan = new THREE.Vector3();
  20390. for ( var i = 0; i < radialSegments; ++ i ) {
  20391. grid[ i ] = new Array( tubularSegments );
  20392. var u = i / radialSegments * 2 * p * Math.PI;
  20393. var p1 = getPos( u, q, p, radius, heightScale );
  20394. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  20395. tang.subVectors( p2, p1 );
  20396. n.addVectors( p2, p1 );
  20397. bitan.crossVectors( tang, n );
  20398. n.crossVectors( bitan, tang );
  20399. bitan.normalize();
  20400. n.normalize();
  20401. for ( var j = 0; j < tubularSegments; ++ j ) {
  20402. var v = j / tubularSegments * 2 * Math.PI;
  20403. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  20404. var cy = tube * Math.sin( v );
  20405. var pos = new THREE.Vector3();
  20406. pos.x = p1.x + cx * n.x + cy * bitan.x;
  20407. pos.y = p1.y + cx * n.y + cy * bitan.y;
  20408. pos.z = p1.z + cx * n.z + cy * bitan.z;
  20409. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  20410. }
  20411. }
  20412. for ( var i = 0; i < radialSegments; ++ i ) {
  20413. for ( var j = 0; j < tubularSegments; ++ j ) {
  20414. var ip = ( i + 1 ) % radialSegments;
  20415. var jp = ( j + 1 ) % tubularSegments;
  20416. var a = grid[ i ][ j ];
  20417. var b = grid[ ip ][ j ];
  20418. var c = grid[ ip ][ jp ];
  20419. var d = grid[ i ][ jp ];
  20420. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  20421. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  20422. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  20423. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  20424. this.faces.push( new THREE.Face3( a, b, d ) );
  20425. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20426. this.faces.push( new THREE.Face3( b, c, d ) );
  20427. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  20428. }
  20429. }
  20430. this.computeFaceNormals();
  20431. this.computeVertexNormals();
  20432. function getPos( u, in_q, in_p, radius, heightScale ) {
  20433. var cu = Math.cos( u );
  20434. var su = Math.sin( u );
  20435. var quOverP = in_q / in_p * u;
  20436. var cs = Math.cos( quOverP );
  20437. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  20438. var ty = radius * ( 2 + cs ) * su * 0.5;
  20439. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  20440. return new THREE.Vector3( tx, ty, tz );
  20441. }
  20442. };
  20443. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20444. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  20445. THREE.TorusKnotGeometry.prototype.clone = function () {
  20446. var geometry = new THREE.TorusKnotGeometry(
  20447. this.parameters.radius,
  20448. this.parameters.tube,
  20449. this.parameters.radialSegments,
  20450. this.parameters.tubularSegments,
  20451. this.parameters.p,
  20452. this.parameters.q,
  20453. this.parameters.heightScale
  20454. );
  20455. return geometry;
  20456. };
  20457. // File:src/extras/geometries/TubeGeometry.js
  20458. /**
  20459. * @author WestLangley / https://github.com/WestLangley
  20460. * @author zz85 / https://github.com/zz85
  20461. * @author miningold / https://github.com/miningold
  20462. * @author jonobr1 / https://github.com/jonobr1
  20463. *
  20464. * Modified from the TorusKnotGeometry by @oosmoxiecode
  20465. *
  20466. * Creates a tube which extrudes along a 3d spline
  20467. *
  20468. * Uses parallel transport frames as described in
  20469. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  20470. */
  20471. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  20472. THREE.Geometry.call( this );
  20473. this.type = 'TubeGeometry';
  20474. this.parameters = {
  20475. path: path,
  20476. segments: segments,
  20477. radius: radius,
  20478. radialSegments: radialSegments,
  20479. closed: closed
  20480. };
  20481. segments = segments || 64;
  20482. radius = radius || 1;
  20483. radialSegments = radialSegments || 8;
  20484. closed = closed || false;
  20485. taper = taper || THREE.TubeGeometry.NoTaper;
  20486. var grid = [];
  20487. var scope = this,
  20488. tangent,
  20489. normal,
  20490. binormal,
  20491. numpoints = segments + 1,
  20492. u, v, r,
  20493. cx, cy,
  20494. pos, pos2 = new THREE.Vector3(),
  20495. i, j,
  20496. ip, jp,
  20497. a, b, c, d,
  20498. uva, uvb, uvc, uvd;
  20499. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  20500. tangents = frames.tangents,
  20501. normals = frames.normals,
  20502. binormals = frames.binormals;
  20503. // proxy internals
  20504. this.tangents = tangents;
  20505. this.normals = normals;
  20506. this.binormals = binormals;
  20507. function vert( x, y, z ) {
  20508. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  20509. }
  20510. // construct the grid
  20511. for ( i = 0; i < numpoints; i ++ ) {
  20512. grid[ i ] = [];
  20513. u = i / ( numpoints - 1 );
  20514. pos = path.getPointAt( u );
  20515. tangent = tangents[ i ];
  20516. normal = normals[ i ];
  20517. binormal = binormals[ i ];
  20518. r = radius * taper( u );
  20519. for ( j = 0; j < radialSegments; j ++ ) {
  20520. v = j / radialSegments * 2 * Math.PI;
  20521. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  20522. cy = r * Math.sin( v );
  20523. pos2.copy( pos );
  20524. pos2.x += cx * normal.x + cy * binormal.x;
  20525. pos2.y += cx * normal.y + cy * binormal.y;
  20526. pos2.z += cx * normal.z + cy * binormal.z;
  20527. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  20528. }
  20529. }
  20530. // construct the mesh
  20531. for ( i = 0; i < segments; i ++ ) {
  20532. for ( j = 0; j < radialSegments; j ++ ) {
  20533. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  20534. jp = ( j + 1 ) % radialSegments;
  20535. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  20536. b = grid[ ip ][ j ];
  20537. c = grid[ ip ][ jp ];
  20538. d = grid[ i ][ jp ];
  20539. uva = new THREE.Vector2( i / segments, j / radialSegments );
  20540. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  20541. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  20542. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  20543. this.faces.push( new THREE.Face3( a, b, d ) );
  20544. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20545. this.faces.push( new THREE.Face3( b, c, d ) );
  20546. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  20547. }
  20548. }
  20549. this.computeFaceNormals();
  20550. this.computeVertexNormals();
  20551. };
  20552. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20553. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  20554. THREE.TubeGeometry.NoTaper = function ( u ) {
  20555. return 1;
  20556. };
  20557. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  20558. return Math.sin( Math.PI * u );
  20559. };
  20560. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  20561. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  20562. var normal = new THREE.Vector3(),
  20563. tangents = [],
  20564. normals = [],
  20565. binormals = [],
  20566. vec = new THREE.Vector3(),
  20567. mat = new THREE.Matrix4(),
  20568. numpoints = segments + 1,
  20569. theta,
  20570. epsilon = 0.0001,
  20571. smallest,
  20572. tx, ty, tz,
  20573. i, u;
  20574. // expose internals
  20575. this.tangents = tangents;
  20576. this.normals = normals;
  20577. this.binormals = binormals;
  20578. // compute the tangent vectors for each segment on the path
  20579. for ( i = 0; i < numpoints; i ++ ) {
  20580. u = i / ( numpoints - 1 );
  20581. tangents[ i ] = path.getTangentAt( u );
  20582. tangents[ i ].normalize();
  20583. }
  20584. initialNormal3();
  20585. /*
  20586. function initialNormal1(lastBinormal) {
  20587. // fixed start binormal. Has dangers of 0 vectors
  20588. normals[ 0 ] = new THREE.Vector3();
  20589. binormals[ 0 ] = new THREE.Vector3();
  20590. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  20591. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  20592. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20593. }
  20594. function initialNormal2() {
  20595. // This uses the Frenet-Serret formula for deriving binormal
  20596. var t2 = path.getTangentAt( epsilon );
  20597. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  20598. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  20599. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  20600. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20601. }
  20602. */
  20603. function initialNormal3() {
  20604. // select an initial normal vector perpendicular to the first tangent vector,
  20605. // and in the direction of the smallest tangent xyz component
  20606. normals[ 0 ] = new THREE.Vector3();
  20607. binormals[ 0 ] = new THREE.Vector3();
  20608. smallest = Number.MAX_VALUE;
  20609. tx = Math.abs( tangents[ 0 ].x );
  20610. ty = Math.abs( tangents[ 0 ].y );
  20611. tz = Math.abs( tangents[ 0 ].z );
  20612. if ( tx <= smallest ) {
  20613. smallest = tx;
  20614. normal.set( 1, 0, 0 );
  20615. }
  20616. if ( ty <= smallest ) {
  20617. smallest = ty;
  20618. normal.set( 0, 1, 0 );
  20619. }
  20620. if ( tz <= smallest ) {
  20621. normal.set( 0, 0, 1 );
  20622. }
  20623. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20624. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20625. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20626. }
  20627. // compute the slowly-varying normal and binormal vectors for each segment on the path
  20628. for ( i = 1; i < numpoints; i ++ ) {
  20629. normals[ i ] = normals[ i - 1 ].clone();
  20630. binormals[ i ] = binormals[ i - 1 ].clone();
  20631. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20632. if ( vec.length() > epsilon ) {
  20633. vec.normalize();
  20634. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20635. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20636. }
  20637. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20638. }
  20639. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20640. if ( closed ) {
  20641. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  20642. theta /= ( numpoints - 1 );
  20643. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  20644. theta = - theta;
  20645. }
  20646. for ( i = 1; i < numpoints; i ++ ) {
  20647. // twist a little...
  20648. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  20649. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20650. }
  20651. }
  20652. };
  20653. // File:src/extras/geometries/PolyhedronGeometry.js
  20654. /**
  20655. * @author clockworkgeek / https://github.com/clockworkgeek
  20656. * @author timothypratley / https://github.com/timothypratley
  20657. * @author WestLangley / http://github.com/WestLangley
  20658. */
  20659. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  20660. THREE.Geometry.call( this );
  20661. this.type = 'PolyhedronGeometry';
  20662. this.parameters = {
  20663. vertices: vertices,
  20664. indices: indices,
  20665. radius: radius,
  20666. detail: detail
  20667. };
  20668. radius = radius || 1;
  20669. detail = detail || 0;
  20670. var that = this;
  20671. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  20672. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  20673. }
  20674. var p = this.vertices;
  20675. var faces = [];
  20676. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  20677. var v1 = p[ indices[ i ] ];
  20678. var v2 = p[ indices[ i + 1 ] ];
  20679. var v3 = p[ indices[ i + 2 ] ];
  20680. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  20681. }
  20682. var centroid = new THREE.Vector3();
  20683. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20684. subdivide( faces[ i ], detail );
  20685. }
  20686. // Handle case when face straddles the seam
  20687. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  20688. var uvs = this.faceVertexUvs[ 0 ][ i ];
  20689. var x0 = uvs[ 0 ].x;
  20690. var x1 = uvs[ 1 ].x;
  20691. var x2 = uvs[ 2 ].x;
  20692. var max = Math.max( x0, Math.max( x1, x2 ) );
  20693. var min = Math.min( x0, Math.min( x1, x2 ) );
  20694. if ( max > 0.9 && min < 0.1 ) {
  20695. // 0.9 is somewhat arbitrary
  20696. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  20697. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  20698. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  20699. }
  20700. }
  20701. // Apply radius
  20702. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  20703. this.vertices[ i ].multiplyScalar( radius );
  20704. }
  20705. // Merge vertices
  20706. this.mergeVertices();
  20707. this.computeFaceNormals();
  20708. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20709. // Project vector onto sphere's surface
  20710. function prepare( vector ) {
  20711. var vertex = vector.normalize().clone();
  20712. vertex.index = that.vertices.push( vertex ) - 1;
  20713. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  20714. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  20715. var v = inclination( vector ) / Math.PI + 0.5;
  20716. vertex.uv = new THREE.Vector2( u, 1 - v );
  20717. return vertex;
  20718. }
  20719. // Approximate a curved face with recursively sub-divided triangles.
  20720. function make( v1, v2, v3, materialIndex ) {
  20721. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  20722. that.faces.push( face );
  20723. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  20724. var azi = azimuth( centroid );
  20725. that.faceVertexUvs[ 0 ].push( [
  20726. correctUV( v1.uv, v1, azi ),
  20727. correctUV( v2.uv, v2, azi ),
  20728. correctUV( v3.uv, v3, azi )
  20729. ] );
  20730. }
  20731. // Analytically subdivide a face to the required detail level.
  20732. function subdivide( face, detail ) {
  20733. var cols = Math.pow( 2, detail );
  20734. var a = prepare( that.vertices[ face.a ] );
  20735. var b = prepare( that.vertices[ face.b ] );
  20736. var c = prepare( that.vertices[ face.c ] );
  20737. var v = [];
  20738. var materialIndex = face.materialIndex;
  20739. // Construct all of the vertices for this subdivision.
  20740. for ( var i = 0 ; i <= cols; i ++ ) {
  20741. v[ i ] = [];
  20742. var aj = prepare( a.clone().lerp( c, i / cols ) );
  20743. var bj = prepare( b.clone().lerp( c, i / cols ) );
  20744. var rows = cols - i;
  20745. for ( var j = 0; j <= rows; j ++ ) {
  20746. if ( j === 0 && i === cols ) {
  20747. v[ i ][ j ] = aj;
  20748. } else {
  20749. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  20750. }
  20751. }
  20752. }
  20753. // Construct all of the faces.
  20754. for ( var i = 0; i < cols ; i ++ ) {
  20755. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  20756. var k = Math.floor( j / 2 );
  20757. if ( j % 2 === 0 ) {
  20758. make(
  20759. v[ i ][ k + 1 ],
  20760. v[ i + 1 ][ k ],
  20761. v[ i ][ k ],
  20762. materialIndex
  20763. );
  20764. } else {
  20765. make(
  20766. v[ i ][ k + 1 ],
  20767. v[ i + 1 ][ k + 1 ],
  20768. v[ i + 1 ][ k ],
  20769. materialIndex
  20770. );
  20771. }
  20772. }
  20773. }
  20774. }
  20775. // Angle around the Y axis, counter-clockwise when looking from above.
  20776. function azimuth( vector ) {
  20777. return Math.atan2( vector.z, - vector.x );
  20778. }
  20779. // Angle above the XZ plane.
  20780. function inclination( vector ) {
  20781. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  20782. }
  20783. // Texture fixing helper. Spheres have some odd behaviours.
  20784. function correctUV( uv, vector, azimuth ) {
  20785. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  20786. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  20787. return uv.clone();
  20788. }
  20789. };
  20790. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20791. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  20792. THREE.PolyhedronGeometry.prototype.clone = function () {
  20793. var geometry = new THREE.PolyhedronGeometry(
  20794. this.parameters.vertices,
  20795. this.parameters.indices,
  20796. this.parameters.radius,
  20797. this.parameters.detail
  20798. );
  20799. return geometry.copy( this );
  20800. };
  20801. THREE.PolyhedronGeometry.prototype.copy = function ( source ) {
  20802. THREE.Geometry.prototype.copy.call( this, source );
  20803. return this;
  20804. };
  20805. // File:src/extras/geometries/DodecahedronGeometry.js
  20806. /**
  20807. * @author Abe Pazos / https://hamoid.com
  20808. */
  20809. THREE.DodecahedronGeometry = function ( radius, detail ) {
  20810. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20811. var r = 1 / t;
  20812. var vertices = [
  20813. // (±1, ±1, ±1)
  20814. - 1, - 1, - 1, - 1, - 1, 1,
  20815. - 1, 1, - 1, - 1, 1, 1,
  20816. 1, - 1, - 1, 1, - 1, 1,
  20817. 1, 1, - 1, 1, 1, 1,
  20818. // (0, ±1/φ, ±φ)
  20819. 0, - r, - t, 0, - r, t,
  20820. 0, r, - t, 0, r, t,
  20821. // (±1/φ, ±φ, 0)
  20822. - r, - t, 0, - r, t, 0,
  20823. r, - t, 0, r, t, 0,
  20824. // (±φ, 0, ±1/φ)
  20825. - t, 0, - r, t, 0, - r,
  20826. - t, 0, r, t, 0, r
  20827. ];
  20828. var indices = [
  20829. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  20830. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  20831. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  20832. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  20833. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  20834. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  20835. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  20836. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  20837. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  20838. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  20839. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  20840. 1, 12, 14, 1, 14, 5, 1, 5, 9
  20841. ];
  20842. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20843. this.type = 'DodecahedronGeometry';
  20844. this.parameters = {
  20845. radius: radius,
  20846. detail: detail
  20847. };
  20848. };
  20849. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20850. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  20851. THREE.DodecahedronGeometry.prototype.clone = function () {
  20852. var geometry = new THREE.DodecahedronGeometry(
  20853. this.parameters.radius,
  20854. this.parameters.detail
  20855. );
  20856. geometry.copy( this );
  20857. return geometry;
  20858. };
  20859. // File:src/extras/geometries/IcosahedronGeometry.js
  20860. /**
  20861. * @author timothypratley / https://github.com/timothypratley
  20862. */
  20863. THREE.IcosahedronGeometry = function ( radius, detail ) {
  20864. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20865. var vertices = [
  20866. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  20867. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  20868. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  20869. ];
  20870. var indices = [
  20871. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  20872. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  20873. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  20874. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  20875. ];
  20876. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20877. this.type = 'IcosahedronGeometry';
  20878. this.parameters = {
  20879. radius: radius,
  20880. detail: detail
  20881. };
  20882. };
  20883. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20884. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  20885. THREE.IcosahedronGeometry.prototype.clone = function () {
  20886. var geometry = new THREE.IcosahedronGeometry(
  20887. this.parameters.radius,
  20888. this.parameters.detail
  20889. );
  20890. geometry.copy( this );
  20891. return geometry;
  20892. };
  20893. // File:src/extras/geometries/OctahedronGeometry.js
  20894. /**
  20895. * @author timothypratley / https://github.com/timothypratley
  20896. */
  20897. THREE.OctahedronGeometry = function ( radius, detail ) {
  20898. var vertices = [
  20899. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  20900. ];
  20901. var indices = [
  20902. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  20903. ];
  20904. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20905. this.type = 'OctahedronGeometry';
  20906. this.parameters = {
  20907. radius: radius,
  20908. detail: detail
  20909. };
  20910. };
  20911. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20912. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  20913. THREE.OctahedronGeometry.prototype.clone = function () {
  20914. var geometry = new THREE.OctahedronGeometry(
  20915. this.parameters.radius,
  20916. this.parameters.detail
  20917. );
  20918. geometry.copy( this );
  20919. return geometry;
  20920. };
  20921. // File:src/extras/geometries/TetrahedronGeometry.js
  20922. /**
  20923. * @author timothypratley / https://github.com/timothypratley
  20924. */
  20925. THREE.TetrahedronGeometry = function ( radius, detail ) {
  20926. var vertices = [
  20927. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20928. ];
  20929. var indices = [
  20930. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20931. ];
  20932. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20933. this.type = 'TetrahedronGeometry';
  20934. this.parameters = {
  20935. radius: radius,
  20936. detail: detail
  20937. };
  20938. };
  20939. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20940. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  20941. THREE.TetrahedronGeometry.prototype.clone = function () {
  20942. var geometry = new THREE.TetrahedronGeometry(
  20943. this.parameters.radius,
  20944. this.parameters.detail
  20945. );
  20946. geometry.copy( this );
  20947. return geometry;
  20948. };
  20949. // File:src/extras/geometries/ParametricGeometry.js
  20950. /**
  20951. * @author zz85 / https://github.com/zz85
  20952. * Parametric Surfaces Geometry
  20953. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  20954. *
  20955. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  20956. *
  20957. */
  20958. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  20959. THREE.Geometry.call( this );
  20960. this.type = 'ParametricGeometry';
  20961. this.parameters = {
  20962. func: func,
  20963. slices: slices,
  20964. stacks: stacks
  20965. };
  20966. var verts = this.vertices;
  20967. var faces = this.faces;
  20968. var uvs = this.faceVertexUvs[ 0 ];
  20969. var i, j, p;
  20970. var u, v;
  20971. var sliceCount = slices + 1;
  20972. for ( i = 0; i <= stacks; i ++ ) {
  20973. v = i / stacks;
  20974. for ( j = 0; j <= slices; j ++ ) {
  20975. u = j / slices;
  20976. p = func( u, v );
  20977. verts.push( p );
  20978. }
  20979. }
  20980. var a, b, c, d;
  20981. var uva, uvb, uvc, uvd;
  20982. for ( i = 0; i < stacks; i ++ ) {
  20983. for ( j = 0; j < slices; j ++ ) {
  20984. a = i * sliceCount + j;
  20985. b = i * sliceCount + j + 1;
  20986. c = ( i + 1 ) * sliceCount + j + 1;
  20987. d = ( i + 1 ) * sliceCount + j;
  20988. uva = new THREE.Vector2( j / slices, i / stacks );
  20989. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  20990. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  20991. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  20992. faces.push( new THREE.Face3( a, b, d ) );
  20993. uvs.push( [ uva, uvb, uvd ] );
  20994. faces.push( new THREE.Face3( b, c, d ) );
  20995. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  20996. }
  20997. }
  20998. // console.log(this);
  20999. // magic bullet
  21000. // var diff = this.mergeVertices();
  21001. // console.log('removed ', diff, ' vertices by merging');
  21002. this.computeFaceNormals();
  21003. this.computeVertexNormals();
  21004. };
  21005. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21006. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  21007. // File:src/extras/geometries/WireframeGeometry.js
  21008. /**
  21009. * @author mrdoob / http://mrdoob.com/
  21010. */
  21011. THREE.WireframeGeometry = function ( geometry ) {
  21012. THREE.BufferGeometry.call( this );
  21013. var edge = [ 0, 0 ], hash = {};
  21014. var sortFunction = function ( a, b ) {
  21015. return a - b;
  21016. };
  21017. var keys = [ 'a', 'b', 'c' ];
  21018. if ( geometry instanceof THREE.Geometry ) {
  21019. var vertices = geometry.vertices;
  21020. var faces = geometry.faces;
  21021. var numEdges = 0;
  21022. // allocate maximal size
  21023. var edges = new Uint32Array( 6 * faces.length );
  21024. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21025. var face = faces[ i ];
  21026. for ( var j = 0; j < 3; j ++ ) {
  21027. edge[ 0 ] = face[ keys[ j ] ];
  21028. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21029. edge.sort( sortFunction );
  21030. var key = edge.toString();
  21031. if ( hash[ key ] === undefined ) {
  21032. edges[ 2 * numEdges ] = edge[ 0 ];
  21033. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  21034. hash[ key ] = true;
  21035. numEdges ++;
  21036. }
  21037. }
  21038. }
  21039. var coords = new Float32Array( numEdges * 2 * 3 );
  21040. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  21041. for ( var j = 0; j < 2; j ++ ) {
  21042. var vertex = vertices[ edges [ 2 * i + j ] ];
  21043. var index = 6 * i + 3 * j;
  21044. coords[ index + 0 ] = vertex.x;
  21045. coords[ index + 1 ] = vertex.y;
  21046. coords[ index + 2 ] = vertex.z;
  21047. }
  21048. }
  21049. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21050. } else if ( geometry instanceof THREE.BufferGeometry ) {
  21051. if ( geometry.index !== null ) {
  21052. // Indexed BufferGeometry
  21053. var indices = geometry.index.array;
  21054. var vertices = geometry.attributes.position;
  21055. var drawcalls = geometry.drawcalls;
  21056. var numEdges = 0;
  21057. if ( drawcalls.length === 0 ) {
  21058. geometry.addGroup( 0, indices.length );
  21059. }
  21060. // allocate maximal size
  21061. var edges = new Uint32Array( 2 * indices.length );
  21062. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  21063. var drawcall = drawcalls[ o ];
  21064. var start = drawcall.start;
  21065. var count = drawcall.count;
  21066. for ( var i = start, il = start + count; i < il; i += 3 ) {
  21067. for ( var j = 0; j < 3; j ++ ) {
  21068. edge[ 0 ] = indices[ i + j ];
  21069. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  21070. edge.sort( sortFunction );
  21071. var key = edge.toString();
  21072. if ( hash[ key ] === undefined ) {
  21073. edges[ 2 * numEdges ] = edge[ 0 ];
  21074. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  21075. hash[ key ] = true;
  21076. numEdges ++;
  21077. }
  21078. }
  21079. }
  21080. }
  21081. var coords = new Float32Array( numEdges * 2 * 3 );
  21082. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  21083. for ( var j = 0; j < 2; j ++ ) {
  21084. var index = 6 * i + 3 * j;
  21085. var index2 = edges[ 2 * i + j ];
  21086. coords[ index + 0 ] = vertices.getX( index2 );
  21087. coords[ index + 1 ] = vertices.getY( index2 );
  21088. coords[ index + 2 ] = vertices.getZ( index2 );
  21089. }
  21090. }
  21091. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21092. } else {
  21093. // non-indexed BufferGeometry
  21094. var vertices = geometry.attributes.position.array;
  21095. var numEdges = vertices.length / 3;
  21096. var numTris = numEdges / 3;
  21097. var coords = new Float32Array( numEdges * 2 * 3 );
  21098. for ( var i = 0, l = numTris; i < l; i ++ ) {
  21099. for ( var j = 0; j < 3; j ++ ) {
  21100. var index = 18 * i + 6 * j;
  21101. var index1 = 9 * i + 3 * j;
  21102. coords[ index + 0 ] = vertices[ index1 ];
  21103. coords[ index + 1 ] = vertices[ index1 + 1 ];
  21104. coords[ index + 2 ] = vertices[ index1 + 2 ];
  21105. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  21106. coords[ index + 3 ] = vertices[ index2 ];
  21107. coords[ index + 4 ] = vertices[ index2 + 1 ];
  21108. coords[ index + 5 ] = vertices[ index2 + 2 ];
  21109. }
  21110. }
  21111. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21112. }
  21113. }
  21114. };
  21115. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21116. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  21117. // File:src/extras/helpers/AxisHelper.js
  21118. /**
  21119. * @author sroucheray / http://sroucheray.org/
  21120. * @author mrdoob / http://mrdoob.com/
  21121. */
  21122. THREE.AxisHelper = function ( size ) {
  21123. size = size || 1;
  21124. var vertices = new Float32Array( [
  21125. 0, 0, 0, size, 0, 0,
  21126. 0, 0, 0, 0, size, 0,
  21127. 0, 0, 0, 0, 0, size
  21128. ] );
  21129. var colors = new Float32Array( [
  21130. 1, 0, 0, 1, 0.6, 0,
  21131. 0, 1, 0, 0.6, 1, 0,
  21132. 0, 0, 1, 0, 0.6, 1
  21133. ] );
  21134. var geometry = new THREE.BufferGeometry();
  21135. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21136. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  21137. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  21138. THREE.LineSegments.call( this, geometry, material );
  21139. };
  21140. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21141. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  21142. // File:src/extras/helpers/ArrowHelper.js
  21143. /**
  21144. * @author WestLangley / http://github.com/WestLangley
  21145. * @author zz85 / http://github.com/zz85
  21146. * @author bhouston / http://clara.io
  21147. *
  21148. * Creates an arrow for visualizing directions
  21149. *
  21150. * Parameters:
  21151. * dir - Vector3
  21152. * origin - Vector3
  21153. * length - Number
  21154. * color - color in hex value
  21155. * headLength - Number
  21156. * headWidth - Number
  21157. */
  21158. THREE.ArrowHelper = ( function () {
  21159. var lineGeometry = new THREE.Geometry();
  21160. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  21161. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  21162. coneGeometry.translate( 0, - 0.5, 0 );
  21163. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  21164. // dir is assumed to be normalized
  21165. THREE.Object3D.call( this );
  21166. if ( color === undefined ) color = 0xffff00;
  21167. if ( length === undefined ) length = 1;
  21168. if ( headLength === undefined ) headLength = 0.2 * length;
  21169. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  21170. this.position.copy( origin );
  21171. if ( headLength < length ) {
  21172. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  21173. this.line.matrixAutoUpdate = false;
  21174. this.add( this.line );
  21175. }
  21176. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  21177. this.cone.matrixAutoUpdate = false;
  21178. this.add( this.cone );
  21179. this.setDirection( dir );
  21180. this.setLength( length, headLength, headWidth );
  21181. }
  21182. }() );
  21183. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  21184. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  21185. THREE.ArrowHelper.prototype.setDirection = ( function () {
  21186. var axis = new THREE.Vector3();
  21187. var radians;
  21188. return function setDirection( dir ) {
  21189. // dir is assumed to be normalized
  21190. if ( dir.y > 0.99999 ) {
  21191. this.quaternion.set( 0, 0, 0, 1 );
  21192. } else if ( dir.y < - 0.99999 ) {
  21193. this.quaternion.set( 1, 0, 0, 0 );
  21194. } else {
  21195. axis.set( dir.z, 0, - dir.x ).normalize();
  21196. radians = Math.acos( dir.y );
  21197. this.quaternion.setFromAxisAngle( axis, radians );
  21198. }
  21199. };
  21200. }() );
  21201. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  21202. if ( headLength === undefined ) headLength = 0.2 * length;
  21203. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  21204. if ( headLength < length ){
  21205. this.line.scale.set( 1, length - headLength, 1 );
  21206. this.line.updateMatrix();
  21207. }
  21208. this.cone.scale.set( headWidth, headLength, headWidth );
  21209. this.cone.position.y = length;
  21210. this.cone.updateMatrix();
  21211. };
  21212. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  21213. if ( this.line !== undefined ) this.line.material.color.set( color );
  21214. this.cone.material.color.set( color );
  21215. };
  21216. // File:src/extras/helpers/BoxHelper.js
  21217. /**
  21218. * @author mrdoob / http://mrdoob.com/
  21219. */
  21220. THREE.BoxHelper = function ( object ) {
  21221. var indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
  21222. var positions = new Float32Array( 8 * 3 );
  21223. var geometry = new THREE.BufferGeometry();
  21224. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21225. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21226. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  21227. if ( object !== undefined ) {
  21228. this.update( object );
  21229. }
  21230. };
  21231. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21232. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  21233. THREE.BoxHelper.prototype.update = ( function () {
  21234. var box = new THREE.Box3();
  21235. return function ( object ) {
  21236. box.setFromObject( object );
  21237. if ( box.empty() ) return;
  21238. var min = box.min;
  21239. var max = box.max;
  21240. /*
  21241. 5____4
  21242. 1/___0/|
  21243. | 6__|_7
  21244. 2/___3/
  21245. 0: max.x, max.y, max.z
  21246. 1: min.x, max.y, max.z
  21247. 2: min.x, min.y, max.z
  21248. 3: max.x, min.y, max.z
  21249. 4: max.x, max.y, min.z
  21250. 5: min.x, max.y, min.z
  21251. 6: min.x, min.y, min.z
  21252. 7: max.x, min.y, min.z
  21253. */
  21254. var position = this.geometry.attributes.position;
  21255. var array = position.array;
  21256. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  21257. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  21258. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  21259. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  21260. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  21261. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  21262. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  21263. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  21264. position.needsUpdate = true;
  21265. this.geometry.computeBoundingSphere();
  21266. }
  21267. } )();
  21268. // File:src/extras/helpers/BoundingBoxHelper.js
  21269. /**
  21270. * @author WestLangley / http://github.com/WestLangley
  21271. */
  21272. // a helper to show the world-axis-aligned bounding box for an object
  21273. THREE.BoundingBoxHelper = function ( object, hex ) {
  21274. var color = ( hex !== undefined ) ? hex : 0x888888;
  21275. this.object = object;
  21276. this.box = new THREE.Box3();
  21277. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  21278. };
  21279. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  21280. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  21281. THREE.BoundingBoxHelper.prototype.update = function () {
  21282. this.box.setFromObject( this.object );
  21283. this.box.size( this.scale );
  21284. this.box.center( this.position );
  21285. };
  21286. // File:src/extras/helpers/CameraHelper.js
  21287. /**
  21288. * @author alteredq / http://alteredqualia.com/
  21289. *
  21290. * - shows frustum, line of sight and up of the camera
  21291. * - suitable for fast updates
  21292. * - based on frustum visualization in lightgl.js shadowmap example
  21293. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  21294. */
  21295. THREE.CameraHelper = function ( camera ) {
  21296. var geometry = new THREE.Geometry();
  21297. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  21298. var pointMap = {};
  21299. // colors
  21300. var hexFrustum = 0xffaa00;
  21301. var hexCone = 0xff0000;
  21302. var hexUp = 0x00aaff;
  21303. var hexTarget = 0xffffff;
  21304. var hexCross = 0x333333;
  21305. // near
  21306. addLine( "n1", "n2", hexFrustum );
  21307. addLine( "n2", "n4", hexFrustum );
  21308. addLine( "n4", "n3", hexFrustum );
  21309. addLine( "n3", "n1", hexFrustum );
  21310. // far
  21311. addLine( "f1", "f2", hexFrustum );
  21312. addLine( "f2", "f4", hexFrustum );
  21313. addLine( "f4", "f3", hexFrustum );
  21314. addLine( "f3", "f1", hexFrustum );
  21315. // sides
  21316. addLine( "n1", "f1", hexFrustum );
  21317. addLine( "n2", "f2", hexFrustum );
  21318. addLine( "n3", "f3", hexFrustum );
  21319. addLine( "n4", "f4", hexFrustum );
  21320. // cone
  21321. addLine( "p", "n1", hexCone );
  21322. addLine( "p", "n2", hexCone );
  21323. addLine( "p", "n3", hexCone );
  21324. addLine( "p", "n4", hexCone );
  21325. // up
  21326. addLine( "u1", "u2", hexUp );
  21327. addLine( "u2", "u3", hexUp );
  21328. addLine( "u3", "u1", hexUp );
  21329. // target
  21330. addLine( "c", "t", hexTarget );
  21331. addLine( "p", "c", hexCross );
  21332. // cross
  21333. addLine( "cn1", "cn2", hexCross );
  21334. addLine( "cn3", "cn4", hexCross );
  21335. addLine( "cf1", "cf2", hexCross );
  21336. addLine( "cf3", "cf4", hexCross );
  21337. function addLine( a, b, hex ) {
  21338. addPoint( a, hex );
  21339. addPoint( b, hex );
  21340. }
  21341. function addPoint( id, hex ) {
  21342. geometry.vertices.push( new THREE.Vector3() );
  21343. geometry.colors.push( new THREE.Color( hex ) );
  21344. if ( pointMap[ id ] === undefined ) {
  21345. pointMap[ id ] = [];
  21346. }
  21347. pointMap[ id ].push( geometry.vertices.length - 1 );
  21348. }
  21349. THREE.LineSegments.call( this, geometry, material );
  21350. this.camera = camera;
  21351. this.matrix = camera.matrixWorld;
  21352. this.matrixAutoUpdate = false;
  21353. this.pointMap = pointMap;
  21354. this.update();
  21355. };
  21356. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21357. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  21358. THREE.CameraHelper.prototype.update = function () {
  21359. var geometry, pointMap;
  21360. var vector = new THREE.Vector3();
  21361. var camera = new THREE.Camera();
  21362. var setPoint = function ( point, x, y, z ) {
  21363. vector.set( x, y, z ).unproject( camera );
  21364. var points = pointMap[ point ];
  21365. if ( points !== undefined ) {
  21366. for ( var i = 0, il = points.length; i < il; i ++ ) {
  21367. geometry.vertices[ points[ i ] ].copy( vector );
  21368. }
  21369. }
  21370. };
  21371. return function () {
  21372. geometry = this.geometry;
  21373. pointMap = this.pointMap;
  21374. var w = 1, h = 1;
  21375. // we need just camera projection matrix
  21376. // world matrix must be identity
  21377. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  21378. // center / target
  21379. setPoint( "c", 0, 0, - 1 );
  21380. setPoint( "t", 0, 0, 1 );
  21381. // near
  21382. setPoint( "n1", - w, - h, - 1 );
  21383. setPoint( "n2", w, - h, - 1 );
  21384. setPoint( "n3", - w, h, - 1 );
  21385. setPoint( "n4", w, h, - 1 );
  21386. // far
  21387. setPoint( "f1", - w, - h, 1 );
  21388. setPoint( "f2", w, - h, 1 );
  21389. setPoint( "f3", - w, h, 1 );
  21390. setPoint( "f4", w, h, 1 );
  21391. // up
  21392. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  21393. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  21394. setPoint( "u3", 0, h * 2, - 1 );
  21395. // cross
  21396. setPoint( "cf1", - w, 0, 1 );
  21397. setPoint( "cf2", w, 0, 1 );
  21398. setPoint( "cf3", 0, - h, 1 );
  21399. setPoint( "cf4", 0, h, 1 );
  21400. setPoint( "cn1", - w, 0, - 1 );
  21401. setPoint( "cn2", w, 0, - 1 );
  21402. setPoint( "cn3", 0, - h, - 1 );
  21403. setPoint( "cn4", 0, h, - 1 );
  21404. geometry.verticesNeedUpdate = true;
  21405. };
  21406. }();
  21407. // File:src/extras/helpers/DirectionalLightHelper.js
  21408. /**
  21409. * @author alteredq / http://alteredqualia.com/
  21410. * @author mrdoob / http://mrdoob.com/
  21411. * @author WestLangley / http://github.com/WestLangley
  21412. */
  21413. THREE.DirectionalLightHelper = function ( light, size ) {
  21414. THREE.Object3D.call( this );
  21415. this.light = light;
  21416. this.light.updateMatrixWorld();
  21417. this.matrix = light.matrixWorld;
  21418. this.matrixAutoUpdate = false;
  21419. size = size || 1;
  21420. var geometry = new THREE.Geometry();
  21421. geometry.vertices.push(
  21422. new THREE.Vector3( - size, size, 0 ),
  21423. new THREE.Vector3( size, size, 0 ),
  21424. new THREE.Vector3( size, - size, 0 ),
  21425. new THREE.Vector3( - size, - size, 0 ),
  21426. new THREE.Vector3( - size, size, 0 )
  21427. );
  21428. var material = new THREE.LineBasicMaterial( { fog: false } );
  21429. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21430. this.lightPlane = new THREE.Line( geometry, material );
  21431. this.add( this.lightPlane );
  21432. geometry = new THREE.Geometry();
  21433. geometry.vertices.push(
  21434. new THREE.Vector3(),
  21435. new THREE.Vector3()
  21436. );
  21437. material = new THREE.LineBasicMaterial( { fog: false } );
  21438. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21439. this.targetLine = new THREE.Line( geometry, material );
  21440. this.add( this.targetLine );
  21441. this.update();
  21442. };
  21443. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21444. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  21445. THREE.DirectionalLightHelper.prototype.dispose = function () {
  21446. this.lightPlane.geometry.dispose();
  21447. this.lightPlane.material.dispose();
  21448. this.targetLine.geometry.dispose();
  21449. this.targetLine.material.dispose();
  21450. };
  21451. THREE.DirectionalLightHelper.prototype.update = function () {
  21452. var v1 = new THREE.Vector3();
  21453. var v2 = new THREE.Vector3();
  21454. var v3 = new THREE.Vector3();
  21455. return function () {
  21456. v1.setFromMatrixPosition( this.light.matrixWorld );
  21457. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  21458. v3.subVectors( v2, v1 );
  21459. this.lightPlane.lookAt( v3 );
  21460. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21461. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  21462. this.targetLine.geometry.verticesNeedUpdate = true;
  21463. this.targetLine.material.color.copy( this.lightPlane.material.color );
  21464. };
  21465. }();
  21466. // File:src/extras/helpers/EdgesHelper.js
  21467. /**
  21468. * @author WestLangley / http://github.com/WestLangley
  21469. * @param object THREE.Mesh whose geometry will be used
  21470. * @param hex line color
  21471. * @param thresholdAngle the minimum angle (in degrees),
  21472. * between the face normals of adjacent faces,
  21473. * that is required to render an edge. A value of 10 means
  21474. * an edge is only rendered if the angle is at least 10 degrees.
  21475. */
  21476. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  21477. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21478. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  21479. this.matrix = object.matrixWorld;
  21480. this.matrixAutoUpdate = false;
  21481. };
  21482. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21483. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  21484. // File:src/extras/helpers/FaceNormalsHelper.js
  21485. /**
  21486. * @author mrdoob / http://mrdoob.com/
  21487. * @author WestLangley / http://github.com/WestLangley
  21488. */
  21489. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  21490. // FaceNormalsHelper only supports THREE.Geometry
  21491. this.object = object;
  21492. this.size = ( size !== undefined ) ? size : 1;
  21493. var color = ( hex !== undefined ) ? hex : 0xffff00;
  21494. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21495. //
  21496. var nNormals = 0;
  21497. var objGeometry = this.object.geometry;
  21498. if ( objGeometry instanceof THREE.Geometry ) {
  21499. nNormals = objGeometry.faces.length;
  21500. } else {
  21501. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  21502. }
  21503. //
  21504. var geometry = new THREE.BufferGeometry();
  21505. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21506. geometry.addAttribute( 'position', positions );
  21507. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21508. //
  21509. this.matrixAutoUpdate = false;
  21510. this.update();
  21511. };
  21512. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21513. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  21514. THREE.FaceNormalsHelper.prototype.update = ( function () {
  21515. var v1 = new THREE.Vector3();
  21516. var v2 = new THREE.Vector3();
  21517. var normalMatrix = new THREE.Matrix3();
  21518. return function update() {
  21519. this.object.updateMatrixWorld( true );
  21520. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21521. var matrixWorld = this.object.matrixWorld;
  21522. var position = this.geometry.attributes.position;
  21523. //
  21524. var objGeometry = this.object.geometry;
  21525. var vertices = objGeometry.vertices;
  21526. var faces = objGeometry.faces;
  21527. var idx = 0;
  21528. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21529. var face = faces[ i ];
  21530. var normal = face.normal;
  21531. v1.copy( vertices[ face.a ] )
  21532. .add( vertices[ face.b ] )
  21533. .add( vertices[ face.c ] )
  21534. .divideScalar( 3 )
  21535. .applyMatrix4( matrixWorld );
  21536. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21537. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21538. idx = idx + 1;
  21539. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21540. idx = idx + 1;
  21541. }
  21542. position.needsUpdate = true;
  21543. return this;
  21544. }
  21545. }() );
  21546. // File:src/extras/helpers/GridHelper.js
  21547. /**
  21548. * @author mrdoob / http://mrdoob.com/
  21549. */
  21550. THREE.GridHelper = function ( size, step ) {
  21551. var geometry = new THREE.Geometry();
  21552. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  21553. this.color1 = new THREE.Color( 0x444444 );
  21554. this.color2 = new THREE.Color( 0x888888 );
  21555. for ( var i = - size; i <= size; i += step ) {
  21556. geometry.vertices.push(
  21557. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  21558. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  21559. );
  21560. var color = i === 0 ? this.color1 : this.color2;
  21561. geometry.colors.push( color, color, color, color );
  21562. }
  21563. THREE.LineSegments.call( this, geometry, material );
  21564. };
  21565. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21566. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  21567. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  21568. this.color1.set( colorCenterLine );
  21569. this.color2.set( colorGrid );
  21570. this.geometry.colorsNeedUpdate = true;
  21571. };
  21572. // File:src/extras/helpers/HemisphereLightHelper.js
  21573. /**
  21574. * @author alteredq / http://alteredqualia.com/
  21575. * @author mrdoob / http://mrdoob.com/
  21576. */
  21577. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  21578. THREE.Object3D.call( this );
  21579. this.light = light;
  21580. this.light.updateMatrixWorld();
  21581. this.matrix = light.matrixWorld;
  21582. this.matrixAutoUpdate = false;
  21583. this.colors = [ new THREE.Color(), new THREE.Color() ];
  21584. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21585. geometry.rotateX( - Math.PI / 2 );
  21586. for ( var i = 0, il = 8; i < il; i ++ ) {
  21587. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  21588. }
  21589. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  21590. this.lightSphere = new THREE.Mesh( geometry, material );
  21591. this.add( this.lightSphere );
  21592. this.update();
  21593. };
  21594. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21595. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  21596. THREE.HemisphereLightHelper.prototype.dispose = function () {
  21597. this.lightSphere.geometry.dispose();
  21598. this.lightSphere.material.dispose();
  21599. };
  21600. THREE.HemisphereLightHelper.prototype.update = function () {
  21601. var vector = new THREE.Vector3();
  21602. return function () {
  21603. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  21604. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  21605. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  21606. this.lightSphere.geometry.colorsNeedUpdate = true;
  21607. }
  21608. }();
  21609. // File:src/extras/helpers/PointLightHelper.js
  21610. /**
  21611. * @author alteredq / http://alteredqualia.com/
  21612. * @author mrdoob / http://mrdoob.com/
  21613. */
  21614. THREE.PointLightHelper = function ( light, sphereSize ) {
  21615. this.light = light;
  21616. this.light.updateMatrixWorld();
  21617. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21618. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21619. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21620. THREE.Mesh.call( this, geometry, material );
  21621. this.matrix = this.light.matrixWorld;
  21622. this.matrixAutoUpdate = false;
  21623. /*
  21624. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  21625. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  21626. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  21627. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  21628. var d = light.distance;
  21629. if ( d === 0.0 ) {
  21630. this.lightDistance.visible = false;
  21631. } else {
  21632. this.lightDistance.scale.set( d, d, d );
  21633. }
  21634. this.add( this.lightDistance );
  21635. */
  21636. };
  21637. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  21638. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  21639. THREE.PointLightHelper.prototype.dispose = function () {
  21640. this.geometry.dispose();
  21641. this.material.dispose();
  21642. };
  21643. THREE.PointLightHelper.prototype.update = function () {
  21644. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21645. /*
  21646. var d = this.light.distance;
  21647. if ( d === 0.0 ) {
  21648. this.lightDistance.visible = false;
  21649. } else {
  21650. this.lightDistance.visible = true;
  21651. this.lightDistance.scale.set( d, d, d );
  21652. }
  21653. */
  21654. };
  21655. // File:src/extras/helpers/SkeletonHelper.js
  21656. /**
  21657. * @author Sean Griffin / http://twitter.com/sgrif
  21658. * @author Michael Guerrero / http://realitymeltdown.com
  21659. * @author mrdoob / http://mrdoob.com/
  21660. * @author ikerr / http://verold.com
  21661. */
  21662. THREE.SkeletonHelper = function ( object ) {
  21663. this.bones = this.getBoneList( object );
  21664. var geometry = new THREE.Geometry();
  21665. for ( var i = 0; i < this.bones.length; i ++ ) {
  21666. var bone = this.bones[ i ];
  21667. if ( bone.parent instanceof THREE.Bone ) {
  21668. geometry.vertices.push( new THREE.Vector3() );
  21669. geometry.vertices.push( new THREE.Vector3() );
  21670. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  21671. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  21672. }
  21673. }
  21674. geometry.dynamic = true;
  21675. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  21676. THREE.LineSegments.call( this, geometry, material );
  21677. this.root = object;
  21678. this.matrix = object.matrixWorld;
  21679. this.matrixAutoUpdate = false;
  21680. this.update();
  21681. };
  21682. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21683. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  21684. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  21685. var boneList = [];
  21686. if ( object instanceof THREE.Bone ) {
  21687. boneList.push( object );
  21688. }
  21689. for ( var i = 0; i < object.children.length; i ++ ) {
  21690. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  21691. }
  21692. return boneList;
  21693. };
  21694. THREE.SkeletonHelper.prototype.update = function () {
  21695. var geometry = this.geometry;
  21696. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  21697. var boneMatrix = new THREE.Matrix4();
  21698. var j = 0;
  21699. for ( var i = 0; i < this.bones.length; i ++ ) {
  21700. var bone = this.bones[ i ];
  21701. if ( bone.parent instanceof THREE.Bone ) {
  21702. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  21703. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  21704. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  21705. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  21706. j += 2;
  21707. }
  21708. }
  21709. geometry.verticesNeedUpdate = true;
  21710. geometry.computeBoundingSphere();
  21711. };
  21712. // File:src/extras/helpers/SpotLightHelper.js
  21713. /**
  21714. * @author alteredq / http://alteredqualia.com/
  21715. * @author mrdoob / http://mrdoob.com/
  21716. * @author WestLangley / http://github.com/WestLangley
  21717. */
  21718. THREE.SpotLightHelper = function ( light ) {
  21719. THREE.Object3D.call( this );
  21720. this.light = light;
  21721. this.light.updateMatrixWorld();
  21722. this.matrix = light.matrixWorld;
  21723. this.matrixAutoUpdate = false;
  21724. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  21725. geometry.translate( 0, - 0.5, 0 );
  21726. geometry.rotateX( - Math.PI / 2 );
  21727. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21728. this.cone = new THREE.Mesh( geometry, material );
  21729. this.add( this.cone );
  21730. this.update();
  21731. };
  21732. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21733. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  21734. THREE.SpotLightHelper.prototype.dispose = function () {
  21735. this.cone.geometry.dispose();
  21736. this.cone.material.dispose();
  21737. };
  21738. THREE.SpotLightHelper.prototype.update = function () {
  21739. var vector = new THREE.Vector3();
  21740. var vector2 = new THREE.Vector3();
  21741. return function () {
  21742. var coneLength = this.light.distance ? this.light.distance : 10000;
  21743. var coneWidth = coneLength * Math.tan( this.light.angle );
  21744. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  21745. vector.setFromMatrixPosition( this.light.matrixWorld );
  21746. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  21747. this.cone.lookAt( vector2.sub( vector ) );
  21748. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21749. };
  21750. }();
  21751. // File:src/extras/helpers/VertexNormalsHelper.js
  21752. /**
  21753. * @author mrdoob / http://mrdoob.com/
  21754. * @author WestLangley / http://github.com/WestLangley
  21755. */
  21756. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  21757. this.object = object;
  21758. this.size = ( size !== undefined ) ? size : 1;
  21759. var color = ( hex !== undefined ) ? hex : 0xff0000;
  21760. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21761. //
  21762. var nNormals = 0;
  21763. var objGeometry = this.object.geometry;
  21764. if ( objGeometry instanceof THREE.Geometry ) {
  21765. nNormals = objGeometry.faces.length * 3;
  21766. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21767. nNormals = objGeometry.attributes.normal.count
  21768. }
  21769. //
  21770. var geometry = new THREE.BufferGeometry();
  21771. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21772. geometry.addAttribute( 'position', positions );
  21773. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21774. //
  21775. this.matrixAutoUpdate = false;
  21776. this.update();
  21777. };
  21778. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21779. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  21780. THREE.VertexNormalsHelper.prototype.update = ( function () {
  21781. var v1 = new THREE.Vector3();
  21782. var v2 = new THREE.Vector3();
  21783. var normalMatrix = new THREE.Matrix3();
  21784. return function update() {
  21785. var keys = [ 'a', 'b', 'c' ];
  21786. this.object.updateMatrixWorld( true );
  21787. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21788. var matrixWorld = this.object.matrixWorld;
  21789. var position = this.geometry.attributes.position;
  21790. //
  21791. var objGeometry = this.object.geometry;
  21792. if ( objGeometry instanceof THREE.Geometry ) {
  21793. var vertices = objGeometry.vertices;
  21794. var faces = objGeometry.faces;
  21795. var idx = 0;
  21796. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21797. var face = faces[ i ];
  21798. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  21799. var vertex = vertices[ face[ keys[ j ] ] ];
  21800. var normal = face.vertexNormals[ j ];
  21801. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21802. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21803. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21804. idx = idx + 1;
  21805. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21806. idx = idx + 1;
  21807. }
  21808. }
  21809. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21810. var objPos = objGeometry.attributes.position;
  21811. var objNorm = objGeometry.attributes.normal;
  21812. var idx = 0;
  21813. // for simplicity, ignore index and drawcalls, and render every normal
  21814. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21815. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21816. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  21817. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21818. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21819. idx = idx + 1;
  21820. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21821. idx = idx + 1;
  21822. }
  21823. }
  21824. position.needsUpdate = true;
  21825. return this;
  21826. }
  21827. }() );
  21828. // File:src/extras/helpers/WireframeHelper.js
  21829. /**
  21830. * @author mrdoob / http://mrdoob.com/
  21831. */
  21832. THREE.WireframeHelper = function ( object, hex ) {
  21833. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21834. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  21835. this.matrix = object.matrixWorld;
  21836. this.matrixAutoUpdate = false;
  21837. };
  21838. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21839. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  21840. // File:src/extras/objects/ImmediateRenderObject.js
  21841. /**
  21842. * @author alteredq / http://alteredqualia.com/
  21843. */
  21844. THREE.ImmediateRenderObject = function ( material ) {
  21845. THREE.Object3D.call( this );
  21846. this.material = material;
  21847. this.render = function ( renderCallback ) {};
  21848. };
  21849. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  21850. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  21851. // File:src/extras/objects/MorphBlendMesh.js
  21852. /**
  21853. * @author alteredq / http://alteredqualia.com/
  21854. */
  21855. THREE.MorphBlendMesh = function( geometry, material ) {
  21856. THREE.Mesh.call( this, geometry, material );
  21857. this.animationsMap = {};
  21858. this.animationsList = [];
  21859. // prepare default animation
  21860. // (all frames played together in 1 second)
  21861. var numFrames = this.geometry.morphTargets.length;
  21862. var name = "__default";
  21863. var startFrame = 0;
  21864. var endFrame = numFrames - 1;
  21865. var fps = numFrames / 1;
  21866. this.createAnimation( name, startFrame, endFrame, fps );
  21867. this.setAnimationWeight( name, 1 );
  21868. };
  21869. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  21870. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21871. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21872. var animation = {
  21873. start: start,
  21874. end: end,
  21875. length: end - start + 1,
  21876. fps: fps,
  21877. duration: ( end - start ) / fps,
  21878. lastFrame: 0,
  21879. currentFrame: 0,
  21880. active: false,
  21881. time: 0,
  21882. direction: 1,
  21883. weight: 1,
  21884. directionBackwards: false,
  21885. mirroredLoop: false
  21886. };
  21887. this.animationsMap[ name ] = animation;
  21888. this.animationsList.push( animation );
  21889. };
  21890. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21891. var pattern = /([a-z]+)_?(\d+)/;
  21892. var firstAnimation, frameRanges = {};
  21893. var geometry = this.geometry;
  21894. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21895. var morph = geometry.morphTargets[ i ];
  21896. var chunks = morph.name.match( pattern );
  21897. if ( chunks && chunks.length > 1 ) {
  21898. var name = chunks[ 1 ];
  21899. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  21900. var range = frameRanges[ name ];
  21901. if ( i < range.start ) range.start = i;
  21902. if ( i > range.end ) range.end = i;
  21903. if ( ! firstAnimation ) firstAnimation = name;
  21904. }
  21905. }
  21906. for ( var name in frameRanges ) {
  21907. var range = frameRanges[ name ];
  21908. this.createAnimation( name, range.start, range.end, fps );
  21909. }
  21910. this.firstAnimation = firstAnimation;
  21911. };
  21912. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21913. var animation = this.animationsMap[ name ];
  21914. if ( animation ) {
  21915. animation.direction = 1;
  21916. animation.directionBackwards = false;
  21917. }
  21918. };
  21919. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21920. var animation = this.animationsMap[ name ];
  21921. if ( animation ) {
  21922. animation.direction = - 1;
  21923. animation.directionBackwards = true;
  21924. }
  21925. };
  21926. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21927. var animation = this.animationsMap[ name ];
  21928. if ( animation ) {
  21929. animation.fps = fps;
  21930. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21931. }
  21932. };
  21933. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21934. var animation = this.animationsMap[ name ];
  21935. if ( animation ) {
  21936. animation.duration = duration;
  21937. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21938. }
  21939. };
  21940. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21941. var animation = this.animationsMap[ name ];
  21942. if ( animation ) {
  21943. animation.weight = weight;
  21944. }
  21945. };
  21946. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  21947. var animation = this.animationsMap[ name ];
  21948. if ( animation ) {
  21949. animation.time = time;
  21950. }
  21951. };
  21952. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  21953. var time = 0;
  21954. var animation = this.animationsMap[ name ];
  21955. if ( animation ) {
  21956. time = animation.time;
  21957. }
  21958. return time;
  21959. };
  21960. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  21961. var duration = - 1;
  21962. var animation = this.animationsMap[ name ];
  21963. if ( animation ) {
  21964. duration = animation.duration;
  21965. }
  21966. return duration;
  21967. };
  21968. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  21969. var animation = this.animationsMap[ name ];
  21970. if ( animation ) {
  21971. animation.time = 0;
  21972. animation.active = true;
  21973. } else {
  21974. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  21975. }
  21976. };
  21977. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  21978. var animation = this.animationsMap[ name ];
  21979. if ( animation ) {
  21980. animation.active = false;
  21981. }
  21982. };
  21983. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  21984. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  21985. var animation = this.animationsList[ i ];
  21986. if ( ! animation.active ) continue;
  21987. var frameTime = animation.duration / animation.length;
  21988. animation.time += animation.direction * delta;
  21989. if ( animation.mirroredLoop ) {
  21990. if ( animation.time > animation.duration || animation.time < 0 ) {
  21991. animation.direction *= - 1;
  21992. if ( animation.time > animation.duration ) {
  21993. animation.time = animation.duration;
  21994. animation.directionBackwards = true;
  21995. }
  21996. if ( animation.time < 0 ) {
  21997. animation.time = 0;
  21998. animation.directionBackwards = false;
  21999. }
  22000. }
  22001. } else {
  22002. animation.time = animation.time % animation.duration;
  22003. if ( animation.time < 0 ) animation.time += animation.duration;
  22004. }
  22005. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  22006. var weight = animation.weight;
  22007. if ( keyframe !== animation.currentFrame ) {
  22008. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  22009. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  22010. this.morphTargetInfluences[ keyframe ] = 0;
  22011. animation.lastFrame = animation.currentFrame;
  22012. animation.currentFrame = keyframe;
  22013. }
  22014. var mix = ( animation.time % frameTime ) / frameTime;
  22015. if ( animation.directionBackwards ) mix = 1 - mix;
  22016. if ( animation.currentFrame !== animation.lastFrame ) {
  22017. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  22018. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  22019. } else {
  22020. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  22021. }
  22022. }
  22023. };
粤ICP备19079148号